Skip to content

GH-51222: [C++] Avoid overflow in binary_slice output sizing - #52451

Open
Dricmoy wants to merge 1 commit into
apache:mainfrom
Dricmoy:gh-51222-binary-slice-overflow
Open

Dricmoy wants to merge 1 commit into
apache:mainfrom
Dricmoy:gh-51222-binary-slice-overflow

Conversation

@Dricmoy

@Dricmoy Dricmoy commented Oct 8, 2026 •

Copy link
Copy Markdown

Rationale for this change

binary_slice uses INT64_MAX as its default stop. The output-size estimate used that value directly, which could overflow for multiple input values and cause valid calls such as binary_slice(values, 1) to fail with ArrowInvalid: Negative buffer resize.

Closes #51222.

What changes are included in this PR?

Clamp the stop value to the available input byte range before calculating the maximum output size, matching the existing utf8_slice_codeunits implementation. Add regression coverage for both binary and large-binary arrays.

Are these changes tested?

Yes.

  • Focused *SliceBytes* C++ tests: 10 passed.
  • Full arrow-compute-scalar-type-test: 348 passed, with one pre-existing disabled test.
  • C++ formatting and cpplint checks passed.
  • git diff --check passed.

Are there any user-facing changes?

Yes. Calling binary_slice with its default stop on sufficiently long input now returns the expected slice instead of raising ArrowInvalid: Negative buffer resize.

Was AI used for this PR?

In accordance to the AI generation guidelines, please disclose below whether and how AI was used in this PR.

OpenAI Codex assisted with investigation, implementation, test selection, validation, and drafting this description. I reviewed the change, understand it, and take responsibility for the contribution.

PR code and description written by:

  • Human
  • AI

Reviewed before submission by:

  • Human
  • AI
  • Not reviewed

@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown

⚠️ GitHub issue #51222 has no components, please add labels for components.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[C++] binary_slice with its default stop raises "Negative buffer resize"

1 participant