Skip to content

[59_maintenance] fix(arrow-array): avoid returning corrupt array in GenericByteArray::into_builder - #11446

Merged
alamb merged 1 commit into
apache:59_maintenancefrom
Jefffrey:backport_11311
Oct 8, 2026
Merged

alamb merged 1 commit into
apache:59_maintenancefrom
Jefffrey:backport_11311

Conversation

@Jefffrey

@Jefffrey Jefffrey commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

…:into_builder` (apache#11311)

# Which issue does this PR close?

- N/A

# Rationale for this change

`GenericByteArray::into_builder` attempts to convert the byte array into
a builder without copying the underlying buffers, returning an error if
that cannot be done. When it was called with a sliced array whose first
offset was non-zero, it returned a corrupted array whose offsets pointed
past the underlying values array.

To fix this, refactor `into_builder` so that it avoids modifying the
values array until we are sure that `into_builder` will succeed.

Along the way, we arrange to copy the input null buffer if it can't be
reused; the null buffer is small, so it doesn't seem worth forcing the
caller to copy the rest of the array fields if the array could otherwise
be reused.

# What changes are included in this PR?

* Refactor `GenericByteArray::into_builder` and fix bug, as described
above
* Add unit tests
* Adjust `GenericByteBuilder::new_from_buffer` to truncate any bytes in
the buffer beyond the last offset


# Are these changes tested?

Yes; existing tests pass, new unit tests added.

# Are there any user-facing changes?

No.
@Jefffrey Jefffrey added the bug Squash those bugs label Oct 8, 2026
@Jefffrey Jefffrey changed the title fix(arrow-array): avoid returning corrupt array in GenericByteArray::into_builder [59_maintenance] fix(arrow-array): avoid returning corrupt array in GenericByteArray::into_builder Oct 8, 2026

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

Seems like a clean cherry-pick. LGTM FWIW, thanks @Jefffrey!

@alamb

alamb commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

🚀

@alamb
alamb merged commit 5cd40db into apache:59_maintenance Oct 8, 2026
30 of 33 checks passed
@Jefffrey
Jefffrey deleted the backport_11311 branch October 9, 2026 02:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Squash those bugs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants