Skip to content

fix(parquet): bound page decompression allocations - #52

Merged
lorenzhs merged 2 commits into
release-24.0.0from
lorenz/fb-4526-bounded-page-decompression
Oct 5, 2026
Merged

lorenzhs merged 2 commits into
release-24.0.0from
lorenz/fb-4526-bounded-page-decompression

Conversation

@lorenzhs

@lorenzhs lorenzhs commented Oct 5, 2026 •

Copy link
Copy Markdown
Collaborator

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, SerializedPageReader routes through DecompressLargePage, which grows the output buffer incrementally (capped at the header’s declared length) for streaming codecs (GZIP/ZSTD) and a new DecompressSnappyToBuffer helper 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).

DecompressIfNeeded is 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 stub DecompressSnappyToBuffer is 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.

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
lorenzhs requested a review from a team October 5, 2026 13:25
@lorenzhs
lorenzhs marked this pull request as ready for review October 5, 2026 13:25
@lorenzhs
lorenzhs merged commit ace40fa into release-24.0.0 Oct 5, 2026
10 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.

2 participants