Skip to content

fix(arrow-array): strip trailing bytes in values data when constructing FixedSizeBinaryArrays - #12410

Merged
Jefffrey merged 3 commits into
apache:mainfrom
aloneangel45:fix/12409-fsb-trailing-bytes
Nov 24, 2026
Merged

Jefffrey merged 3 commits into
apache:mainfrom
aloneangel45:fix/12409-fsb-trailing-bytes

Conversation

@aloneangel45

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

FixedSizeBinaryArray::try_new and FixedSizeBinaryArray::try_new_with_len allow constructing an array from a Buffer with trailing remainder bytes (tested in test_constructors for a 10-byte buffer with value_length = 3 yielding len() == 3), but stored the unsliced Buffer. As a result, FixedSizeBinaryArray::value_data() and values() exposed trailing bytes past len * value_size, causing callers such as FixedSizeBinaryBuilder::append_array to append extra non-element bytes and shift subsequent elements.

What changes are included in this PR?

  • Update FixedSizeBinaryArray::try_new_with_len in arrow-array/src/array/fixed_size_binary_array.rs to slice values to 0..len * value_size whenever values.len() > len * value_size, matching the invariant already maintained by From<ArrayData>, slice(), and new_unchecked().
  • Add unit tests covering value_data(), values(), to_data(), into_parts(), and FixedSizeBinaryBuilder::append_array when the source FixedSizeBinaryArray is constructed from a buffer containing trailing bytes.

Are these changes tested?

Yes. Added unit tests test_try_new_strips_trailing_bytes (arrow-array/src/array/fixed_size_binary_array.rs) and test_fixed_size_binary_builder_append_array_trailing_bytes (arrow-array/src/builder/fixed_size_binary_builder.rs) covering construction with trailing buffer bytes and appending into FixedSizeBinaryBuilder, and ran arrow-array and arrow-select tests alongside rustfmt and clippy.

Are there any significant user-facing changes?

No. FixedSizeBinaryArray::value_data(), values(), to_data(), and into_parts() now expose only the len * value_size bytes belonging to the array rather than trailing buffer padding bytes.

AI usage disclosure

An LLM coding assistant helped inspect callers, draft the fix and unit tests, and run local cargo verification, with all changes reviewed and verified before submission.

@boring-cyborg boring-cyborg Bot added the arrow-core Core crates related to representing arrow data label Nov 23, 2026

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

));
}

let required_len = len * value_size;

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.

super super nit: replace this with a checked mul

lets avoid the 1 line follow up pr 😅

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Replaced len * value_size with len.checked_mul(value_size) in FixedSizeBinaryArray::try_new_with_len (arrow-array/src/array/fixed_size_binary_array.rs) in the latest commit.

Re-verified with cargo fmt -p arrow-array -- --check, cargo clippy -p arrow-array --lib --tests -- -D warnings, and cargo test -p arrow-array --lib (765 passed, 0 failed, 1 ignored).

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.

is this error case strictly necessary? arent we bounded by the above check

if value_size != 0 && values.len() / value_size != len {

in that we cant overflow this multiplication if we've reached this point?


side note: it is not necessary to restate youve run the test suite, the CI would speak for itself

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch — when value_size != 0, the values.len() / value_size != len check above guarantees len * value_size <= values.len() <= usize::MAX, and when value_size == 0, the product is always 0. Removed the unreachable error branch in a56c2f6 (using checked_mul(value_size).expect(...) to match From<ArrayData>).

@Jefffrey

Copy link
Copy Markdown
Contributor
image

is there a human behind this account?

@Jefffrey Jefffrey added the Prolific Author author opened PRs or issues in more than 20 repositories in the last 30 days label Nov 23, 2026
@aloneangel45

Copy link
Copy Markdown
Contributor Author

Yes, there is a human owner behind this account — I use AI coding agents as part of my workflow to find, implement, and test bug fixes across open-source repos, and I verify the changes and test suites locally (arrow-array, arrow-select, and the enabled fork CI workflow on this branch).

Fully understand if arrow-rs prefers human-authored-only submissions or wants additional scrutiny on the fix in arrow-array/src/array/fixed_size_binary_array.rs; happy to address any technical review feedback on #12410 or close it if you'd rather not take it.

@Jefffrey Jefffrey 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.

it would be a good idea to document this new behaviour in appropriate places


Yes, there is a human owner behind this account — I use AI coding agents as part of my workflow to find, implement, and test bug fixes across open-source repos, and I verify the changes and test suites locally (arrow-array, arrow-select, and the enabled fork CI workflow on this branch).

Fully understand if arrow-rs prefers human-authored-only submissions or wants additional scrutiny on the fix in arrow-array/src/array/fixed_size_binary_array.rs; happy to address any technical review feedback on #12410 or close it if you'd rather not take it.

we are fine with AI usage; however we are under pressure from increasing bot accounts which submit PRs to a wide range of repos, giving zero confidence the author has given proper care and consideration to each and every one, which pushes all of the burden onto us maintainers. im fine with proceeding with this PR, but i expect good faith effort from an actual human being

@aloneangel45

Copy link
Copy Markdown
Contributor Author

Updated in a56c2f6: documented the trailing-byte truncation on FixedSizeBinaryArray::new, try_new, and try_new_with_len, and removed the unreachable overflow ArrowError branch in try_new_with_len.

@Jefffrey Jefffrey changed the title fix(arrow-array): strip trailing bytes in FixedSizeBinaryArray::try_new_with_len fix(arrow-array): strip trailing bytes in values data when constructing FixedSizeBinaryArrays Nov 24, 2026
@Jefffrey Jefffrey added the bug Squash those bugs label Nov 24, 2026
@ToniAdreal

This comment was marked as spam.

@Jefffrey
Jefffrey added this pull request to the merge queue Nov 24, 2026
Merged via the queue into apache:main with commit 6ec6d46 Nov 24, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arrow-core Core crates related to representing arrow data bug Squash those bugs Prolific Author author opened PRs or issues in more than 20 repositories in the last 30 days

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FixedSizeBinary::value_data can return trailing bytes

4 participants