Repository navigation
fix(parquet): bound page decompression allocations - #52
Merged
lorenzhs merged 2 commits intoOct 5, 2026
Merged
Conversation
A malformed page can claim 512 MiB from zero compressed bytes. Reject inconsistent sizes before allocating, and retain one-shot decompression for pages through 64 MiB. Larger GZIP, ZSTD and other streaming-codec outputs grow with decoded bytes. Reuse streaming state and preserve concatenated GZIP/ZSTD frames. Snappy uses a growing sink because its length prefix is also untrusted; raw and Hadoop LZ4 remain one-shot with their maximum expansion checked against the compressed input. Keep the ordinary corded path. Large corded pages borrow a contiguous payload or coalesce only their compressed bytes through the reader pool. Validate V2 level lengths while preserving all-null and uncompressed pages. PackDB's page-reader tests cover the threshold, large pages, allocation bounds, malformed streams, and plain/single-slice/split corded input.
…ines (FB-4526) Bazel defines Arrow's optional codec macros on the Arrow library alone. Parquet must not use its own feature defines to select the large-page Snappy path, or it falls through to unsupported streaming decompression. Keep the growing Snappy helper callable from Parquet and provide an unavailable-codec stub when Arrow itself is built without Snappy. Codec creation still rejects unavailable codecs before reading any page.
lorenzhs
marked this pull request as ready for review
October 5, 2026 13:25
moshap-firebolt
approved these changes
Oct 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
Parquet page decompression allocates the declared uncompressed size before validating the compressed payload. A malformed 1,448-byte file caused roughly 512 MiB of Arrow allocations before returning a size mismatch.
Summary
Keep the existing one-shot decoding path for pages up to 64 MiB. Above that threshold, grow streaming-codec and Snappy output buffers as bytes are decoded, capped at the declared length. Bound large raw/Hadoop LZ4 output by the actual compressed input size. Preserve the corded fast path, V2 level prefixes, concatenated frames, and decompressor reuse; reject inconsistent lengths, excess output, and truncated streams. Keep Snappy dispatch compatible with builds where codec feature defines are local to the Arrow target.
Test Plan
Validated through PackDB's normal and ASan CMake builds with focused PageReader tests covering valid large pages, threshold behavior, inflated sizes, truncated streams, V2 prefixes, concatenated frames, and reader reuse across plain and contiguous/split corded buffers. Replayed the Parquet regression corpus in both builds. The original reproducer now allocates 2,944 bytes through the Arrow memory pool.
Note
Medium Risk
Changes core Parquet read decompression and error handling for malicious or corrupt pages; behavior should be safer but regressions could affect large valid pages or specific codecs (Snappy, LZ4, GZIP/ZSTD).
Overview
Bounds Parquet page decompression memory so corrupt headers can’t force huge upfront allocations before the payload is validated.
Pages with declared uncompressed size ≤ 64 MiB still use the existing one-shot decode. Above that,
SerializedPageReaderroutes throughDecompressLargePage, which grows the output buffer incrementally (capped at the header’s declared length) for streaming codecs (GZIP/ZSTD) and a newDecompressSnappyToBufferhelper that writes via Snappy’s sink API with the same cap. Large LZ4 / LZ4_Hadoop pages keep one-shot decode but reject impossible expansion ratios (output_len > input_len * 255).DecompressIfNeededis tightened: stricter level/size checks, unified uncompressed handling, V2 pages always enter the same path, and corded inputs are coalesced only on the large-page branch. A stubDecompressSnappyToBufferis provided when Snappy isn’t built so Parquet can link without matching codec feature macros.Reviewed by Cursor Bugbot for commit f764f13. Bugbot is set up for automated code reviews on this repo. Configure here.