Skip to content

fix(parquet): return byte array overflow and map decoding errors - #11791

Merged
Rich-T-kid merged 2 commits into
apache:mainfrom
hhhizzz:pr/byte-array-overflow-safety
Oct 30, 2026
Merged

Rich-T-kid merged 2 commits into
apache:mainfrom
hhhizzz:pr/byte-array-overflow-safety

Conversation

@hhhizzz

@hhhizzz hhhizzz commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

First part(1/4) of the solution. Whole solution can be found here: #11478 (comment)

This addresses panic handling only. Reading oversized Utf8/Binary batches successfully and bounding Mask decoding memory are separate changes.

Rationale for this change

Reading DELTA_LENGTH_BYTE_ARRAY data can panic when the cumulative payload exceeds the output offset range. Map decoding can also panic when an underlying reader returns an error.

These failures should return explicit errors through the normal reader error path.

What changes are included in this PR?

  • Use checked arithmetic when validating delta-length page lengths.
  • Check cumulative output offsets before reserving or copying payloads. On overflow, return an error without modifying the output or advancing the decoder.
  • Preserve the existing bulk-copy path for valid input.
  • Propagate Map child-reader errors instead of unwrapping them.

Are these changes tested?

Yes. Added regression tests cover:

  • Offset boundaries, integer overflow, and values that fit 64-bit offsets but exceed 32-bit offsets.
  • Appending decoded values, empty strings, skipping, and end of input.
  • Propagation of errors from malformed Map data.
  • A real large-buffer overflow, verifying that the output and decoder state remain unchanged and subsequent reads still work. This memory-intensive test is ignored by default and was run explicitly.

Both panic regressions fail against the original implementation and pass with these changes. Workspace tests and the additional Parquet async/experimental tests also pass.

Are there any significant user-facing changes?

No additional changes beyond the error handling described above. There are no public API changes.

AI assistance: OpenAI Codex assisted with implementation and regression tests.

@github-actions github-actions Bot added the parquet parquet crate label Oct 22, 2026
Check cumulative delta-length byte-array offsets before reserving or
copying payloads, and propagate Map child-reader errors instead of
panicking. Use checked arithmetic when validating page lengths.

Add offset-boundary, decoder-state, and malformed-map regressions. The
large-buffer regression is opt-in and also checks that an overflow leaves
the output and decoder cursors unchanged.

Relates to apache#7973 and apache#11478.

Implemented with assistance from OpenAI Codex.
}

#[test]
#[ignore = "allocates about 2 GiB; run --ignored --test-threads=1"]

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.

not sure its worth keeping this test in that case 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I’d like to keep it as a manual regression for the real decoder’s overflow handling and state preservation, which the small arithmetic tests don’t cover, while avoiding a ~2 GiB allocation in routine CI; I’ve added a comment explaining this.

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.

in what cases would we ever remember to run this, given our overall test suite is already quite large

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

My intended use case is to run this myself while developing and validating the follow-up fixes in this series, rather than expect maintainers to remember to run it. Once capacity-safe decoding and batch splitting are in place, I plan to replace this interim panic-to-error check with end-to-end tests that verify successful reads of more than 2 GiB of logical payload across valid output batches. Ideally, that coverage would run automatically in a suitable CI job.

@Rich-T-kid

Copy link
Copy Markdown
Contributor

thanks @hhhizzz @Jefffrey

@Rich-T-kid
Rich-T-kid added this pull request to the merge queue Oct 30, 2026
Merged via the queue into apache:main with commit 44f6371 Oct 30, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Squash those bugs parquet parquet crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants