git.delta.rocks / jrsonnet / refs/commits / abd809cc16d2

difftreelog

fix unchecked conversion of array index

Yaroslav Bolyukin2023-09-22parent: #e19afeb.patch.diff
in: master

2 files changed

modifiedcrates/jrsonnet-evaluator/src/error.rsdiffbeforeafterboth
114 InComprehensionCanOnlyIterateOverArray,114 InComprehensionCanOnlyIterateOverArray,
115115
116 #[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),
120120
modifiedcrates/jrsonnet-evaluator/src/evaluate/mod.rsdiffbeforeafterboth
18 function::{CallLocation, FuncDesc, FuncVal},18 function::{CallLocation, FuncDesc, FuncVal},
19 typed::Typed,19 typed::Typed,
20 val::{CachedUnbound, IndexableVal, StrValue, Thunk, ThunkValue},20 val::{CachedUnbound, IndexableVal, StrValue, Thunk, ThunkValue},
21 Context, GcHashMap, ObjValue, ObjValueBuilder, ObjectAssertion, Pending, Result, ResultExt,21 Context, Error, GcHashMap, ObjValue, ObjValueBuilder, ObjectAssertion, Pending, Result,
22 State, Unbound, Val, Error,22 ResultExt, State, Unbound, Val,
23};23};
24pub mod destructure;24pub mod destructure;
25pub mod operator;25pub mod operator;
518 if n.fract() > f64::EPSILON {518 if n.fract() > f64::EPSILON {
519 bail!(FractionalIndex)519 bail!(FractionalIndex)
520 }520 }
521 if n < 0.0 {
522 bail!(ArrayBoundsError(n as isize, v.len()));
523 }
521 v.get(n as usize)?524 v.get(n as usize)?
522 .ok_or_else(|| ArrayBoundsError(n as usize, v.len()))?525 .ok_or_else(|| ArrayBoundsError(n as isize, v.len()))?
523 }526 }
524 (Val::Arr(_), Val::Str(n)) => {527 (Val::Arr(_), Val::Str(n)) => {
525 bail!(AttemptedIndexAnArrayWithString(n.into_flat()))528 bail!(AttemptedIndexAnArrayWithString(n.into_flat()))