Skip to content

MINOR: Reject negative first offsets in ValidateVectorDataVisitor - #1532

Merged
jbonofre merged 1 commit into
apache:mainfrom
Arawoof06:validate-negative-first-offset
Nov 30, 2026
Merged

jbonofre merged 1 commit into
apache:mainfrom
Arawoof06:validate-negative-first-offset

Conversation

@Arawoof06

Copy link
Copy Markdown
Contributor

What's Changed

ValidateVectorDataVisitor.validateOffsetBuffer scans the offset buffer from position 1 and uses offsets[0] only to seed prevValue, so the first offset is never checked for being non-negative. validateLargeOffsetBuffer has the same gap. A negative first offset leaves the remaining offsets non-decreasing and the last offset inside the data buffer, which is all ValidateVectorBufferVisitor compares, so ValueVectorUtility.validateFull accepts the vector. That covers VarCharVector/VarBinaryVector, their large variants and ListVector/LargeListVector, which take their offsets verbatim from IPC input, and validateFull is what ArrowReader.setValidateBatches(true) runs on an untrusted stream. Arrow C++ ValidateOffsets rejects a negative first offset.

A VarBinaryVector holding aaa, bbb with offsets[0] set to -8 passes validateFull today, and reading it then goes below the data buffer:

validateFull PASSED on offsets[0] = -8
get(0) threw java.lang.IndexOutOfBoundsException: index: -8, length: 11 (expected: range(0, 8))

With arrow.enable_unsafe_memory_access=true no bounds check is left, and the eight bytes planted in front of the data buffer come back as part of the value:

get(0) -> [65, 65, 65, 65, 65, 65, 65, 65, 97, 97, 97] (len 11)

Both helpers now check position 0 the way they already check the rest of the buffer. A vector whose first offset is 0 behaves as before. testValidateNegativeFirstOffset exercises the int and long helpers through VarBinaryVector, LargeVarBinaryVector, ListVector and LargeListVector, and fails on main. The vector, algorithm, compression and adapter/jdbc suites pass, and spotless and checkstyle are clean.

@github-actions

This comment has been minimized.

@lidavidm lidavidm added the bug-fix PRs that fix a big. label Nov 30, 2026
@github-actions github-actions Bot added this to the 20.1.0 milestone Nov 30, 2026

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

Thanks for the fix! Checking prevValue >= 0 at position 0 in both validateOffsetBuffer and validateLargeOffsetBuffer closes the gap while still allowing valid non-zero initial offsets (e.g. for sliced vectors) and empty vectors (valueCount == 0). The test coverage across VarBinaryVector, LargeVarBinaryVector, ListVector, and LargeListVector looks solid.

LGTM!

@jbonofre
jbonofre merged commit 1519c69 into apache:main Nov 30, 2026
22 of 25 checks passed
@Arawoof06

Copy link
Copy Markdown
Contributor Author

Appreciate the quick review and the merge.

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.

3 participants