You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "Sean-Kenneth-Doherty (via GitHub)" <gi...@apache.org> on 2026/05/17 06:43:40 UTC
[PR] Guard array_resize target size [datafusion]
Sean-Kenneth-Doherty opened a new pull request, #22296:
URL: https://github.com/apache/datafusion/pull/22296
## Which issue does this PR close?
- Closes #22227.
## Rationale for this change
`array_resize` can panic when a query asks for an impossibly large target size, for example `array_resize(make_array(1), 9223372036854775807, 0)`. The resize path was using the requested count to size fill arrays and mutable array buffers before rejecting values that cannot fit in the output list offsets or allocation limits.
## What changes are included in this PR?
- Validates each non-null target size before using it for resize capacity planning.
- Rejects target sizes that cannot fit the output list offset type.
- Adds a conservative value-capacity check before materializing fill arrays or `MutableArrayData` buffers.
- Adds a unit regression and an SQL logic regression for the large target-size query.
Scope note: this is limited to `array_resize` target-size validation for #22227.
## Are these changes tested?
Yes.
- `cargo test -p datafusion-functions-nested array_resize_rejects_target_count_overflow`
- `cargo test -p datafusion-sqllogictest --test sqllogictests -- array/array_resize.slt`
- `cargo test -p datafusion-functions-nested`
- `cargo fmt --check`
- `cargo clippy -p datafusion-functions-nested --all-targets -- -D warnings`
- `git diff --check`
## Are there any user-facing changes?
Yes. Oversized `array_resize` target lengths now return a DataFusion execution error instead of panicking the process.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Guard array_resize target size [datafusion]
Posted by "Sean-Kenneth-Doherty (via GitHub)" <gi...@apache.org>.
Sean-Kenneth-Doherty commented on PR #22296:
URL: https://github.com/apache/datafusion/pull/22296#issuecomment-4558973622
Addressed the cumulative `List` offset overflow gap in `f395b4eb8`.
Changes:
- validate the cumulative `output_values_len` against the concrete offset type `O` before value-capacity checks and before fill/mutable buffer allocation
- add a two-row `ListArray` regression where each row target fits `i32`, but the combined output length exceeds `i32::MAX`
Validation:
- `cargo fmt --all --check`
- `git diff --check`
- `CARGO_BUILD_JOBS=2 cargo test -p datafusion-functions-nested array_resize_rejects_cumulative_list_offset_overflow -- --nocapture`
- `CARGO_BUILD_JOBS=2 cargo test -p datafusion-functions-nested array_resize_rejects -- --nocapture` (`2 passed`)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Guard array_resize target size [datafusion]
Posted by "Sean-Kenneth-Doherty (via GitHub)" <gi...@apache.org>.
Sean-Kenneth-Doherty commented on PR #22296:
URL: https://github.com/apache/datafusion/pull/22296#issuecomment-4469641163
Fresh local validation on `4f1bbbdba`:
- `cargo test -p datafusion-functions-nested array_resize_rejects_target_count_overflow` -> passed
- `cargo test -p datafusion-sqllogictest --test sqllogictests -- array/array_resize.slt` -> passed
- `cargo test -p datafusion-functions-nested` -> 63 unit tests passed plus 2 doctests passed
- `cargo fmt --all --check` -> passed
- `cargo clippy -p datafusion-functions-nested --all-targets -- -D warnings` -> passed
- `git diff --check origin/main...HEAD` -> clean
GitHub currently only shows the labeler `Process` check, so this covers the changed `array_resize` overflow path and the touched SQLLogicTest file locally.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Guard array_resize target size [datafusion]
Posted by "kosiew (via GitHub)" <gi...@apache.org>.
kosiew commented on code in PR #22296:
URL: https://github.com/apache/datafusion/pull/22296#discussion_r3292633354
##########
datafusion/functions-nested/src/resize.rs:
##########
@@ -206,18 +206,20 @@ fn general_list_resize<O: OffsetSizeTrait + TryInto<i64>>(
if array.is_null(row_index) {
continue;
}
- let target_count = count_array.value(row_index).to_usize().ok_or_else(|| {
- internal_datafusion_err!("array_resize: failed to convert size to usize")
- })?;
+ let target_count = target_count::<O>(count_array, row_index)?;
output_values_len =
output_values_len.checked_add(target_count).ok_or_else(|| {
- internal_datafusion_err!("array_resize: output size overflow")
+ datafusion_common::DataFusionError::Execution(
+ "array_resize: target size too large".to_string(),
+ )
})?;
let current_len = (offset_window[1] - offset_window[0]).to_usize().unwrap();
if target_count > current_len {
max_extra = max_extra.max(target_count - current_len);
}
}
+ validate_value_capacity(&data_type, output_values_len)?;
Review Comment:
The pre-allocation validation still does not fully enforce the output-list offset invariant for `List` arrays.
`target_count::<i32>` validates each row independently, but `output_values_len` can still exceed `i32::MAX` when multiple non-null rows are combined. For example, two `List` rows each resized to `1_073_741_824` elements produce a cumulative value length of `2_147_483_648`, which cannot be represented by `i32` offsets.
This path can still pass `validate_value_capacity` for many value types and reach `MutableArrayData::with_capacities` or offset addition before rejection, so the current change only fixes the single-row overflow case.
Could we validate the cumulative `output_values_len` against `O` before any fill array or mutable buffer allocation? Something like `O::from_usize(output_values_len).is_some()` would work.
It would also be great to add a regression test covering the multi-row `List` overflow scenario.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Guard array_resize target size [datafusion]
Posted by "kosiew (via GitHub)" <gi...@apache.org>.
kosiew commented on PR #22296:
URL: https://github.com/apache/datafusion/pull/22296#issuecomment-4572621902
@Sean-Kenneth-Doherty
Can you resolve the conflicts?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org