difftreelog
fix unchecked conversion of array index
in: master
2 files changed
crates/jrsonnet-evaluator/src/error.rsdiffbeforeafterboth114 InComprehensionCanOnlyIterateOverArray,114 InComprehensionCanOnlyIterateOverArray,115115116 #[error("array out of bounds: {0} is not within [0,{1})")]116 #[error("array out of bounds: {0} is not within [0,{1})")]117 ArrayBoundsError(usize, usize),117 ArrayBoundsError(isize, usize),118 #[error("string out of bounds: {0} is not within [0,{1})")]118 #[error("string out of bounds: {0} is not within [0,{1})")]119 StringBoundsError(usize, usize),119 StringBoundsError(usize, usize),120120crates/jrsonnet-evaluator/src/evaluate/mod.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/evaluate/mod.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate/mod.rs
@@ -18,8 +18,8 @@
function::{CallLocation, FuncDesc, FuncVal},
typed::Typed,
val::{CachedUnbound, IndexableVal, StrValue, Thunk, ThunkValue},
- Context, GcHashMap, ObjValue, ObjValueBuilder, ObjectAssertion, Pending, Result, ResultExt,
- State, Unbound, Val, Error,
+ Context, Error, GcHashMap, ObjValue, ObjValueBuilder, ObjectAssertion, Pending, Result,
+ ResultExt, State, Unbound, Val,
};
pub mod destructure;
pub mod operator;
@@ -518,8 +518,11 @@
if n.fract() > f64::EPSILON {
bail!(FractionalIndex)
}
+ if n < 0.0 {
+ bail!(ArrayBoundsError(n as isize, v.len()));
+ }
v.get(n as usize)?
- .ok_or_else(|| ArrayBoundsError(n as usize, v.len()))?
+ .ok_or_else(|| ArrayBoundsError(n as isize, v.len()))?
}
(Val::Arr(_), Val::Str(n)) => {
bail!(AttemptedIndexAnArrayWithString(n.into_flat()))