Skip to content

fix: Reject variable-width columns whose value offsets are out of bounds - #562

Draft
Sealdot wants to merge 1 commit into
apache:mainfrom
Sealdot:fix-ipc-varwidth-offsets-556
Draft

Sealdot wants to merge 1 commit into
apache:mainfrom
Sealdot:fix-ipc-varwidth-offsets-556

Conversation

@Sealdot

@Sealdot Sealdot commented Dec 3, 2026

Copy link
Copy Markdown

Closes #556.

The IPC reader never compared the value offsets of a variable-width column with its data buffer, or with each other. An offset past the end of the data read the padding bytes after it, and an offset below the one before it made two values overlap: getVariableWidthBytes() calls subarray(x, y), which clamps the end and returns an empty value when y < x. Both reads gave corrupt values with no error; Arrow C++ refuses both arrays in Array::ValidateFull().

VectorLoader now checks the offsets of Utf8, LargeUtf8, Binary, and LargeBinary columns when loading a record batch. It throws when the buffer holds fewer than length + 1 offsets, when the first offset is negative, when an offset is below the one before it, or when the last offset is past the data buffer's length. A first offset above zero stays valid, since a sliced array keeps offsets into its original buffer. This applies to the stream and file readers, compressed batches, and the JSON loader, which share the same visitors. Nested List/Map offsets index child vectors rather than a data buffer and are out of scope here.

The regression tests patch one value offset inside otherwise valid streams and files written by the real writers — a last offset 8 bytes past the data buffer, an offset below its predecessor, and a negative first offset now raise an error, while empty strings (repeated offsets) and unmodified bytes still read correctly. The open PR #551 validates buffer regions against the message body and does not cover this fault: these offsets are inside their own buffer.

All 3,012 IPC tests across 19 suites passed on main (7a34e681), along with the ESNext ESM source typecheck and ESLint on both changed files. A full local Jest run was not attempted; on the same machine the suite previously reached its 640 MiB Node heap limit. Upstream CI workflows await maintainer approval and have not run.

Cognition Devin CLI agent (SWE-2 High) assisted with the implementation, tests, and verification.

Throw when the value offsets of a Utf8, LargeUtf8, Binary, or LargeBinary column are fewer than length + 1, negative, out of order, or end past the data buffer, instead of reading clamped or overlapping values.

AI assistance: Cognition Devin CLI agent (SWE-2 High).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The IPC reader accepts Utf8 value offsets past the data or out of order, and the values read with no error

1 participant