Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Bug fixes
* (Fuzzing) Fixed panic when assigning to a property of a constant object.
* Fixed undefined behavior (an aliasing violation detected by Miri) when a variable is passed to a function that does not take its first argument by `&mut`, e.g. `x.contains("a")` or `f(x)` for a script function. This was a regression in 1.27.0.
* `sort` and `sort_desc` no longer panic on an array of floating-point numbers that contains NaN. NaN now sorts after every other number (before them for `sort_desc`) (thanks [`@Rockyrok77`](https://github.com/Rockyrok77)).
* `pad` on an array now enforces `max_array_size` when the padding length is large enough to overflow the size calculation. Previously it could pass the check and then panic or abort the process while allocating (thanks [`@Rockyrok77`](https://github.com/Rockyrok77)).

Enhancements
------------
Expand Down
8 changes: 6 additions & 2 deletions src/packages/array_basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,12 @@ pub mod array_functions {
let (a, m, s) = crate::eval::calc_array_sizes(array);
let (ax, mx, sx) = crate::eval::calc_data_sizes(&item, true);

_ctx.engine()
.throw_on_size((a + pad + ax * pad, m + mx * pad, s + sx * pad))?;
// `pad` comes from the script, so saturate to keep the totals from wrapping
_ctx.engine().throw_on_size((
a.saturating_add(pad).saturating_add(ax.saturating_mul(pad)),
m.saturating_add(mx.saturating_mul(pad)),
s.saturating_add(sx.saturating_mul(pad)),
))?;
}

array.resize(len, item);
Expand Down
16 changes: 16 additions & 0 deletions tests/data_size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,22 @@ fn test_max_array_size() {
EvalAltResult::ErrorDataTooLarge(..)
));

// 4 * 2^62 wraps to zero in a 64-bit usize
#[cfg(not(feature = "no_object"))]
#[cfg(not(feature = "only_i32"))]
#[cfg(target_pointer_width = "64")]
assert!(matches!(
*engine
.run(
"
let x = [];
x.pad(4611686018427387904, [1, 2, 3]);
"
)
.unwrap_err(),
EvalAltResult::ErrorDataTooLarge(..)
));

assert_eq!(
engine
.eval::<INT>(
Expand Down
Loading