Skip to content

fix(parquet/variant): prevent metadata offset cursor overflow - #1290

Merged
zeroshade merged 1 commit into
apache:mainfrom
matanper:codex/variant-metadata-offset-overflow
Sep 8, 2026
Merged

zeroshade merged 1 commit into
apache:mainfrom
matanper:codex/variant-metadata-offset-overflow

Conversation

@matanper

@matanper matanper commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Rationale for this change

Reading valid VARIANT metadata with 126 dictionary keys and two-byte offsets panics with slice bounds out of range [255:1]. The metadata offset cursor inherits uint8 from offsetSz; both advancing the cursor and computing the slice end can wrap at byte 256. Three- and four-byte offset tables hit the same problem with even fewer keys.

This also affects current main after #1063: validating the complete offset table does not prevent the cursor arithmetic from overflowing while reading that valid table.

What changes are included in this PR?

Use an int offset width and cursor for indexing the metadata buffer. Keep the wire-format width and existing metadata validation unchanged.

Add synthetic valid-metadata tests immediately before, at, and after the failure boundary for two-, three-, and four-byte offsets, plus larger dictionaries. Check every decoded dictionary key. No external test data is required.

Are these changes tested?

  • Before the fix, go test ./parquet/variant -run TestMetadataOffsetTableCrossesByteBoundary -count=1 reproduces the panic at width_2/keys_126.
  • After the fix, go test ./parquet/variant ./arrow/extensions passes, including all 13 new boundary cases.

Are there any user-facing changes?

Valid VARIANT dictionaries spanning byte 255 decode successfully instead of panicking. There are no public API or format changes.

Fixes #1291.

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

Confirmed the bug is real and the fix is correct. I reproduced the panic on current main with this PR's test (slice bounds out of range [255:1] at width_2/keys_126), so valid VARIANT metadata does fail today. The uint8 cursor wrapping at byte 256 is the root cause, and switching to an int cursor is safe because the existing valuesStart check already validates the full offset-table extent in uint64 arithmetic before the loop, keeping every slice in bounds. All 14 boundary subtests plus ./parquet/variant and ./arrow/extensions pass locally on the fix. Thanks for the tight, well-tested patch.


This review was drafted by an AI-assisted tool and
confirmed by an Apache Arrow Go maintainer.

@zeroshade
zeroshade merged commit 27952c7 into apache:main Sep 8, 2026
33 of 34 checks passed
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.

[Parquet] VARIANT metadata reader panics when offset table crosses byte 255

2 participants