Trap out-of-bounds panic for BLOB's.

This commit is contained in:
Stephen Chung 2021-12-02 13:09:59 +08:00
parent 5363b0724f
commit 70f4c53854
2 changed files with 7 additions and 1 deletions

View File

@ -13,6 +13,7 @@ Bug fixes
--------- ---------
* `from_dynamic` now supports deserializing `Option`. * `from_dynamic` now supports deserializing `Option`.
* BLOB's no longer panic when accessed with an out-of-bounds index.
Enhancements Enhancements
------------ ------------

View File

@ -2052,7 +2052,12 @@ impl Engine {
index as usize index as usize
}; };
let value = (arr[arr_idx] as INT).into(); let value = arr
.get(arr_idx)
.map(|&v| (v as INT).into())
.ok_or_else(|| {
Box::new(EvalAltResult::ErrorArrayBounds(arr_len, index, idx_pos))
})?;
Ok(Target::BlobByte(target, arr_idx, value)) Ok(Target::BlobByte(target, arr_idx, value))
} }