Skip to content

fix(arrow-array): strip trailing bytes in FixedSizeBinaryBuilder::append_array (#12409) - #12437

Closed
ToniAdreal wants to merge 1 commit into
apache:mainfrom
ToniAdreal:followup-12410-builder-append-array
Closed

ToniAdreal wants to merge 1 commit into
apache:mainfrom
ToniAdreal:followup-12410-builder-append-array

Conversation

@ToniAdreal

Copy link
Copy Markdown

Follow-up to #12410, which fixed the construction-time leak for #12409.

#12410 strips trailing bytes in FixedSizeBinaryArray::try_new_with_len, so the checked constructors no longer expose them. One path is still open: FixedSizeBinaryArray::new_unchecked stores the buffer as-is (unless force_validate), and FixedSizeBinaryBuilder::append_array copied value_data() wholesale — the issue itself calls out this exact spot. An unchecked array carrying trailing bytes could still pollute the builder and shift every element appended afterwards.

Changes:

  • FixedSizeBinaryBuilder::append_array now copies only len * value_size bytes before extending.
  • One regression test, test_fixed_size_binary_builder_append_array_unchecked_trailing_bytes: appending an unchecked 10-byte array (value_size 3) asserts the builder holds 9 bytes and the finished array reports 9. (Named with an unchecked infix to avoid colliding with the test_fixed_size_binary_builder_append_array_trailing_bytes test added in fix(arrow-array): strip trailing bytes in values data when constructing FixedSizeBinaryArrays #12410, which covers the checked path.)

Verification:

  • Reproduction test failed before the fix (values_slice().len() was 10, expected 9) and passes after.
  • cargo test -p arrow-array --lib fixed_size_binary: 45 passed, 0 failed.
  • cargo test -p arrow-array --lib: 765 passed, 0 failed, 1 ignored, 1 filtered out. The filtered test is test_gc_huge_array, which the 6 GB dev cell OOM-kills (SIGKILL, unrelated to this change); CI should run it.
  • cargo clippy -p arrow-array: clean, no warnings.
  • cargo fmt --all -- --check: clean.

AI assistance disclosure: This PR was prepared with AI assistance (Muse). I reviewed the diff line by line, I understand the change, and I ran the tests listed above.

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

Copy link
Copy Markdown
Contributor

what problem is this fixing? it requires a consumer construct an invalid array via new_unchecked to hit to case

@ToniAdreal

Copy link
Copy Markdown
Author

You're right that after #12410 the checked paths can't produce this anymore — I re-read main and confirmed try_new/try_new_with_len truncate, From<ArrayData> slices to len * value_size, and slice() does the same. The only remaining trigger is new_unchecked without force_validate, which stores the buffer as-is and whose safety contract requires values.len() == len * value_length. So yes, reaching this case does require misusing an unsafe API.

The reason I still opened it is that #12409 — the issue this PR links to — explicitly called out append_array (lines 102–103 in the issue) as a place where trailing bytes "can be appended and corrupt the data of the builder", and asked for stripping "so we have a consistent view of only the bytes involved in the array". #12410 fixed the construction side; this closes the exact spot the issue named.

What the guard buys in practice: append_array is safe code, and today it trusts value_data().len() wholesale, so a trailing-byte array silently corrupts the builder — later elements shift, and finish() then builds via new_unchecked with a buffer that breaks the values.len() == len * value_length guarantee its own SAFETY comment asserts. The fix is a one-line slice to len * value_size plus a regression test, so the builder can't propagate the bad state even when handed such an array.

If you'd rather treat new_unchecked misuse as out of scope for safe-API hardening, I'm happy to close this — no strong attachment. Otherwise it's ready for review.

@Jefffrey

Copy link
Copy Markdown
Contributor

this reads like an LLM, im closing this.

@Jefffrey Jefffrey closed this Nov 24, 2026
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants