Skip to content

fix(arrow-string): saturate the length in Utf8View/BinaryView substring - #12006

Merged
Rich-T-kid merged 1 commit into
apache:mainfrom
hsdfat:substring-view-length
Nov 4, 2026
Merged

Rich-T-kid merged 1 commit into
apache:mainfrom
hsdfat:substring-view-length

Conversation

@hsdfat

@hsdfat hsdfat commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

view_substring_range computed the end as new_start.saturating_add(length as i64). For length > i64::MAX the cast wraps negative, so the end lands before the start:

  • substring(&BinaryViewArray["hello"], 1, Some(u64::MAX)) panics with slice index starts at 1 but ends at 0;
  • the same call on StringViewArray returns ComputeError("The offset 9223372036854775808 is at an invalid utf-8 boundary.").

LargeUtf8 and LargeBinary return "ello" for the same input.

What changes are included in this PR?

Use the existing u64_to_i64_saturating(length) in view_substring_range, like the other arms.

Are these changes tested?

Yes. A new test checks that Utf8View matches LargeUtf8 and BinaryView matches LargeBinary for several starts (including negative and beyond the end) with lengths 2^63 and u64::MAX.

Are there any significant user-facing changes?

No.


AI disclosure: the bug was found and the patch and test drafted with AI assistance (Claude); I reviewed every line, verified the failing test before/after the fix, and ran fmt/clippy/tests for the crate.

A length above i64::MAX was cast with `as i64` and wrapped to a negative
value, so the end landed before the start. BinaryView then panicked on the
slice and Utf8View returned a bogus invalid utf-8 boundary error. Saturate
the length like the LargeUtf8/LargeBinary arms do.
@github-actions github-actions Bot added the arrow-kernels Crates that transform arrow data (e.g. compute, cast) label Oct 30, 2026
@Rich-T-kid
Rich-T-kid self-requested a review November 1, 2026 22:54

@Rich-T-kid Rich-T-kid left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @hsdfat

@Rich-T-kid
Rich-T-kid added this pull request to the merge queue Nov 4, 2026
Merged via the queue into apache:main with commit 00b27ee Nov 4, 2026
21 checks passed
@Jefffrey Jefffrey added the bug Squash those bugs label Nov 4, 2026
@hsdfat
hsdfat deleted the substring-view-length branch November 6, 2026 11:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arrow-kernels Crates that transform arrow data (e.g. compute, cast) bug Squash those bugs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants