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 04:50:41 UTC
[PR] fix: guard array_position start_from underflow [datafusion]
Sean-Kenneth-Doherty opened a new pull request, #22291:
URL: https://github.com/apache/datafusion/pull/22291
## Which issue does this PR close?
- Closes #22220.
## Rationale for this change
`array_position` converts the optional 1-indexed `start_from` argument to a 0-indexed offset by subtracting one. When `start_from` is `i64::MIN`, that subtraction can underflow and panic before DataFusion can return a normal error.
## What changes are included in this PR?
- Adds a shared checked conversion for `array_position` `start_from` values.
- Uses it in both scalar and array `start_from` paths.
- Adds regression coverage for the `i64::MIN` boundary.
## Are these changes tested?
- `cargo fmt --all`
- `TMPDIR=/home/sean/Projects/datafusion-array-position-min/target/tmp cargo test -p datafusion-functions-nested position::tests::test_array_position_start_from_min_value -- --nocapture`
- `TMPDIR=/home/sean/Projects/datafusion-array-position-min/target/tmp cargo test --profile=ci --test sqllogictests -- array/array_position.slt`
- `TMPDIR=/home/sean/Projects/datafusion-array-position-min/target/tmp cargo clippy --all-targets --all-features -- -D warnings`
- `git diff --check`
I also manually checked the issue reproducer no longer panics: `EXPLAIN SELECT array_position([1], 1, -9223372036854775808);` now returns a plan, while plain execution returns `Execution error: start_from out of bounds: -9223372036854775808`.
## Are there any user-facing changes?
Invalid `array_position` `start_from` values at the `i64::MIN` boundary now return a normal DataFusion error instead of panicking.
--
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] fix: guard array_position start_from underflow [datafusion]
Posted by "Jefffrey (via GitHub)" <gi...@apache.org>.
Jefffrey commented on code in PR #22291:
URL: https://github.com/apache/datafusion/pull/22291#discussion_r3315400427
##########
datafusion/functions-nested/src/position.rs:
##########
@@ -207,17 +207,23 @@ fn resolve_start_from(
match third_arg {
None => Ok(vec![0i64; num_rows]),
Some(ColumnarValue::Scalar(ScalarValue::Int64(Some(v)))) => {
- Ok(vec![v - 1; num_rows])
+ Ok(vec![normalize_start_from(*v)?; num_rows])
}
Some(ColumnarValue::Scalar(s)) => {
exec_err!("array_position expected Int64 for start_from, got {s}")
}
- Some(ColumnarValue::Array(a)) => {
- Ok(as_int64_array(a)?.values().iter().map(|&x| x - 1).collect())
- }
+ Some(ColumnarValue::Array(a)) => as_int64_array(a)?
+ .values()
+ .iter()
+ .map(|&x| normalize_start_from(x))
+ .collect(),
}
}
+fn normalize_start_from(start_from: i64) -> Result<i64> {
Review Comment:
we can just inline this
##########
datafusion/functions-nested/src/position.rs:
##########
@@ -592,9 +598,29 @@ fn array_positions_scalar<O: OffsetSizeTrait>(
mod tests {
use super::*;
use arrow::array::AsArray;
- use arrow::datatypes::Int32Type;
+ use arrow::array::Int64Array;
+ use arrow::datatypes::{Int32Type, Int64Type};
use datafusion_common::config::ConfigOptions;
+ #[test]
+ fn test_array_position_start_from_min_value() -> Result<()> {
Review Comment:
we can remove this test since we already have an SLT
--
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] fix: guard array_position start_from underflow [datafusion]
Posted by "Sean-Kenneth-Doherty (via GitHub)" <gi...@apache.org>.
Sean-Kenneth-Doherty commented on PR #22291:
URL: https://github.com/apache/datafusion/pull/22291#issuecomment-4469407535
Fresh validation on the PR head (`862c36ee8`):
- `TMPDIR=/home/sean/Projects/datafusion-array-position-min/target/tmp cargo test -p datafusion-functions-nested position::tests::test_array_position_start_from_min_value -- --nocapture` -> passed (`1 passed`)
- `TMPDIR=/home/sean/Projects/datafusion-array-position-min/target/tmp cargo test --profile=ci --test sqllogictests -- array/array_position.slt` -> passed (`1/1 files completed`)
- `cargo fmt --all -- --check` -> passed
- `git diff --check origin/main...HEAD` -> clean
GitHub Actions only ran the labeler for this PR, so this keeps the regression evidence visible while the branch waits for review.
--
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] fix: guard array_position start_from underflow [datafusion]
Posted by "Sean-Kenneth-Doherty (via GitHub)" <gi...@apache.org>.
Sean-Kenneth-Doherty commented on PR #22291:
URL: https://github.com/apache/datafusion/pull/22291#issuecomment-4559054471
Updated in `57df3fbb9` to use `saturating_sub(1)` for `start_from` normalization, matching the existing later bounds-validation flow.
I also changed the regression to exercise the full `array_position` path for a non-null row with `i64::MIN`, so the important behavior remains covered: no arithmetic panic, just a normal `start_from out of bounds` error.
Validation:
- `cargo fmt --all --check`
- `git diff --check`
- `CARGO_BUILD_JOBS=2 cargo test -p datafusion-functions-nested position::tests::test_array_position_start_from_min_value -- --nocapture`
- `CARGO_BUILD_JOBS=2 cargo test -p datafusion-sqllogictest --test sqllogictests -- array/array_position.slt` (`1/1 files completed`)
--
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