You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "SAY-5 (via GitHub)" <gi...@apache.org> on 2026/07/10 01:09:55 UTC

[PR] fix: avoid panic in array_position start_from near i64::MIN [datafusion]

SAY-5 opened a new pull request, #23433:
URL: https://github.com/apache/datafusion/pull/23433

   ## Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   - Closes #22220.
   
   ## Rationale for this change
   
   <!--
    Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.  
   -->
   
   `array_position` accepts an optional 1-indexed `start_from` argument. When resolving it, the code converts to a 0-indexed offset with a plain `value - 1`. For `start_from = i64::MIN` this subtraction overflows, which panics in debug/overflow-checked builds and wraps in release. The out-of-bounds error path also computed `from + 1`, which overflows the same way. An invalid `start_from` should return a normal error rather than panic.
   
   ## What changes are included in this PR?
   
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   Use `saturating_sub(1)` when converting `start_from` to a 0-indexed offset and `saturating_add(1)` when reporting it back in the out-of-bounds error. A saturated `i64::MIN` stays negative, so the existing `from >= 0` bounds check now rejects it with the usual `start_from out of bounds` error instead of overflowing.
   
   ## Are these changes tested?
   
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
   -->
   
   Yes. Added a unit test that invokes `array_position` with `start_from = i64::MIN` and asserts an error is returned. It panics on `main` and passes with this change.
   
   ## Are there any user-facing changes?
   
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   `array_position(..., i64::MIN)` now returns an error instead of panicking. No API changes.
   
   <!--
   If there are any breaking changes to public APIs, please add the `api change` label.
   -->
   


-- 
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: avoid panic in array_position start_from near i64::MIN [datafusion]

Posted by "SAY-5 (via GitHub)" <gi...@apache.org>.
SAY-5 closed pull request #23433: fix: avoid panic in array_position start_from near i64::MIN
URL: https://github.com/apache/datafusion/pull/23433


-- 
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: avoid panic in array_position start_from near i64::MIN [datafusion]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #23433:
URL: https://github.com/apache/datafusion/pull/23433#issuecomment-5825286414

   Thank you for your contribution. Unfortunately, this pull request is stale because it has been open 60 days with no activity. Please remove the stale label or comment or this will be closed in 7 days.


-- 
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: avoid panic in array_position start_from near i64::MIN [datafusion]

Posted by "SAY-5 (via GitHub)" <gi...@apache.org>.
SAY-5 commented on PR #23433:
URL: https://github.com/apache/datafusion/pull/23433#issuecomment-5837101608

   Closing, #24838 landed the checked_sub fix for this on main so this one is redundant now.


-- 
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: avoid panic in array_position start_from near i64::MIN [datafusion]

Posted by "SAY-5 (via GitHub)" <gi...@apache.org>.
SAY-5 commented on PR #23433:
URL: https://github.com/apache/datafusion/pull/23433#issuecomment-5024593059

   Reworked as suggested. `resolve_start_from` now keeps the original 1-based i64 values, and a single `zero_based_start(start_from, row_len)` helper does the `checked_sub(1)` + `usize::try_from` and validates the resulting 0-based index against the row length, returning `start_from out of bounds` instead of saturating or panicking. Both the scalar fast path and the general dispatch now go through it. The i64::MIN case is covered by the existing unit test and the array_position sqllogictests pass.


-- 
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: avoid panic in array_position start_from near i64::MIN [datafusion]

Posted by "SAY-5 (via GitHub)" <gi...@apache.org>.
SAY-5 commented on PR #23433:
URL: https://github.com/apache/datafusion/pull/23433#issuecomment-5011500301

   That makes sense, saturating_sub just avoids the panic without giving a clean error at the edges. I'll rework it to keep start_from as the original 1-based i64 and do the conversion in one shared helper:
   
   - checked_sub(1) on the original value
   - usize::try_from on the result
   - validate the 0-based index against the row length
   - build the out-of-bounds error from the untouched original value (so the message shows what the caller actually passed)
   
   Then resolve_start_from and general_position_dispatch both go through that helper instead of mapping x - 1 up front. I'll push the refactor and update the i64::MIN test to assert the error message.


-- 
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: avoid panic in array_position start_from near i64::MIN [datafusion]

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #23433:
URL: https://github.com/apache/datafusion/pull/23433#issuecomment-5025053045

   ## [Codecov](https://app.codecov.io/gh/apache/datafusion/pull/23433?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :x: Patch coverage is `92.50000%` with `3 lines` in your changes missing coverage. Please review.
   :warning: Please [upload](https://docs.codecov.com/docs/codecov-uploader) report for BASE (`main@4207291`). [Learn more](https://docs.codecov.io/docs/error-reference?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#section-missing-base-commit) about missing BASE report.
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/datafusion/pull/23433?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
   |---|---|---|
   | [datafusion/functions-nested/src/position.rs](https://app.codecov.io/gh/apache/datafusion/pull/23433?src=pr&el=tree&filepath=datafusion%2Ffunctions-nested%2Fsrc%2Fposition.rs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZGF0YWZ1c2lvbi9mdW5jdGlvbnMtbmVzdGVkL3NyYy9wb3NpdGlvbi5ycw==) | 92.50% | [0 Missing and 3 partials :warning: ](https://app.codecov.io/gh/apache/datafusion/pull/23433?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   ```diff
   @@           Coverage Diff           @@
   ##             main   #23433   +/-   ##
   =======================================
     Coverage        ?   80.70%           
   =======================================
     Files           ?     1089           
     Lines           ?   368056           
     Branches        ?   368056           
   =======================================
     Hits            ?   297049           
     Misses          ?    53306           
     Partials        ?    17701           
   ```
   </details>
   
   [:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/datafusion/pull/23433?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   - :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
   </details>


-- 
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