Skip to content

MINOR: Check buffer bounds in BaseFixedWidthVector.copyFrom - #1505

Merged
jbonofre merged 1 commit into
apache:mainfrom
Arawoof06:fixed-width-copyfrom-bounds
Nov 19, 2026
Merged

jbonofre merged 1 commit into
apache:mainfrom
Arawoof06:fixed-width-copyfrom-bounds

Conversation

@Arawoof06

Copy link
Copy Markdown
Contributor

What's Changed

BaseFixedWidthVector.copyFrom copied typeWidth bytes with a raw MemoryUtil.copyMemory, so the source range was never checked against the source data buffer. loadFieldBuffers does not compare the data buffer length with the field node length, and full validation is off by default in ArrowReader, so an IPC batch or dictionary that declares 16 Int values with a 4-byte data buffer loads without error. get(8) on that vector throws IndexOutOfBoundsException, but copyFrom/copyFromSafe (also reached through TransferPair.copyValueSafe, e.g. from DictionaryEncoder.decode and the struct/list/union copyFrom paths) copies whatever native memory follows the buffer into the target vector, with bounds checking enabled.

The copy now goes through ArrowBuf.setBytes(index, src, srcIndex, length), which always checks the source range and checks the destination when bounds checking is on, matching the variable-width copyFrom, which already uses the checked getBytes. The validity bit is set after the copy, so a rejected copy leaves the target slot null.

The new test in TestCopyFrom loads an IntVector with a short data buffer and expects IndexOutOfBoundsException from both copyFrom and copyFromSafe. Before the change, the same setup copied the 0x41414141 written just past the slice into the target. The vector and algorithm test suites pass.

@jbonofre jbonofre left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. Using ArrowBuf.setBytes checks the source buffer bounds, and setting the validity bit after the copy keeps a failed copy from marking the destination slot valid.
The regression test covers both copyFrom and copyFromSafe with a truncated source buffer.

@jbonofre jbonofre added the bug-fix PRs that fix a big. label Nov 19, 2026
@apache apache deleted a comment from github-actions Bot Nov 19, 2026
@github-actions github-actions Bot added this to the 20.0.0 milestone Nov 19, 2026
@jbonofre
jbonofre merged commit 547cd99 into apache:main Nov 19, 2026
22 of 24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug-fix PRs that fix a big.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants