Skip to content

fix(parquet): bound row-group count by remaining input before reserving - #11419

Merged
alamb merged 4 commits into
apache:mainfrom
pmoust:fix/row-group-count-bound
Oct 7, 2026
Merged

alamb merged 4 commits into
apache:mainfrom
pmoust:fix/row-group-count-bound

Conversation

@pmoust

@pmoust pmoust commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

Decoding a Parquet footer reserves a Vec sized from the declared
row-group count before reading any row group:

let mut rg_vec = Vec::with_capacity(list_ident.size as usize);

list_ident.size comes straight off the wire and RowGroupMetaData is a
large struct, so a footer of a few bytes that declares a huge row-group
count asks for count * size_of::<RowGroupMetaData>() up front, before a
single row group is read. On a host under memory pressure that allocation
aborts the process.

PR #10979 bounded read_thrift_vec by the remaining input. The row-group
list is decoded inline in parquet_metadata_from_bytes and does not go
through that helper, so the bound did not reach it. The other footer lists
(schema elements, column chunks, sorting columns, key/values, column
orders) do go through read_thrift_vec. This is the one that did not.

What changes are included in this PR?

  • Apply the same remaining-input bound inline at the row-group list: each
    row group is at least one byte on the wire, so a declared count larger
    than the remaining input is malformed and is rejected before the
    reserve.
  • A test (row_group_count_exceeding_remaining_input_is_rejected) builds a
    valid footer prefix and declares an over-sized row_groups list, then
    asserts the decode reports the bound. Without the bound the same input
    instead fails later with Required field columns is missing, so the
    test is shown failing against the unfixed code.

Are these changes tested?

Yes. The new test passes with the bound and fails without it, as described
above.

Are there any user-facing changes?

A malformed footer that declares more row groups than its bytes can hold
now returns a Parquet error describing the bound, rather than attempting
a large allocation. This was found while hardening the Parquet
external-table reader in Ravel.

@etseidl etseidl left a comment

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.

Thanks @pmoust, this looks good. Just a few long comment nits and a suggestion.

Comment thread parquet/src/file/metadata/thrift/mod.rs Resolved
Comment thread parquet/src/file/metadata/thrift/mod.rs Resolved
Comment thread parquet/src/file/metadata/thrift/mod.rs Outdated
// count larger than the remaining input is malformed. Reject
// it before reserving, so a tiny footer cannot drive a
// multi-gigabyte allocation.
if let Some(remaining) = prot.remaining_bytes()

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.

Rather than repeating this code again, I wonder if we should add a list size validator either as a standalone function or add it to the ThriftCompactInputProtocol trait. Use that new function here and in read_thrift_vec.

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.

Done. Extracted check_list_size in parquet_thrift.rs; both read_thrift_vec and the row-group site call it now, so the bound lives in one place.

Decoding a footer reserved a Vec sized from the declared row-group count
before reading any row group:

    let mut rg_vec = Vec::with_capacity(list_ident.size as usize);

The size comes straight off the wire, and RowGroupMetaData is a large
struct, so a footer of a few bytes that declares a huge row-group count
asks for count * size_of::<RowGroupMetaData>() up front. On a host under
memory pressure that allocation aborts the process.

PR apache#10979 bounded read_thrift_vec by the remaining input. The row-group
list is decoded inline in parquet_metadata_from_bytes and does not go
through that helper, so the bound did not reach it. The other footer
lists (schema elements, column chunks, sorting columns, key/values,
column orders) do go through read_thrift_vec. This is the one that did
not.

Factor the bound into check_list_size and call it from both read_thrift_vec
and the row-group site: each row group is at least one byte on the wire, so
a declared count larger than the remaining input is malformed and is
rejected before the reserve.

A test builds a valid footer prefix and declares an over-sized
row_groups list, then asserts the decode reports the bound rather than
reserving. Without the bound the same input instead fails later with
"Required field columns is missing".

Fixes apache#11418

Signed-off-by: Panagiotis Moustafellos <[email protected]>
@pmoust
pmoust force-pushed the fix/row-group-count-bound branch from fa1b71c to 975c97e Compare October 6, 2026 23:53
@etseidl

etseidl commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

run benchmark metadata

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark starting (GKE) | trigger

Target: metadata

Sharding factor: 1 (1 workers).

Comparing fix/row-group-count-bound (975c97e) to 6b34163 (merge-base) diff

Run configuration
run benchmark metadata
shards: 1

Results will be posted when all workers finish.


File an issue against this benchmark runner

@etseidl etseidl left a comment

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.

Thanks @pmoust, this looks good. One last nit (my fault).

Comment thread parquet/src/file/metadata/thrift/mod.rs Resolved
@adriangbot

Copy link
Copy Markdown

🤖 Benchmark completed (GKE) | trigger

Target: metadata

Comparing fix/row-group-count-bound (975c97e) to 6b34163 (merge-base) diff

Run configuration
run benchmark metadata
shards: 1
Details
group                                               base                                   changed
-----                                               ----                                   -------
decode metadata (wide) with schema                  1.00     25.9±0.74ms        ? ?/sec    1.00     25.8±0.69ms        ? ?/sec
decode metadata (wide) with skip PES                1.00     26.4±0.69ms        ? ?/sec    1.00     26.4±0.58ms        ? ?/sec
decode metadata (wide) with skip all stats          1.00     30.5±0.70ms        ? ?/sec    1.00     30.5±0.71ms        ? ?/sec
decode metadata (wide) with skip column stats       1.00     27.6±0.69ms        ? ?/sec    1.00     27.6±0.74ms        ? ?/sec
decode metadata (wide) with skip size stats         1.00     30.8±0.59ms        ? ?/sec    1.00     30.8±0.60ms        ? ?/sec
decode metadata (wide) with stats mask              1.00     25.4±0.51ms        ? ?/sec    1.01     25.5±0.58ms        ? ?/sec
decode metadata with schema                         1.01      4.2±0.01µs        ? ?/sec    1.00      4.1±0.01µs        ? ?/sec
decode metadata with skip PES                       1.00      7.1±0.06µs        ? ?/sec    1.00      7.1±0.07µs        ? ?/sec
decode metadata with skip column stats              1.00      6.8±0.04µs        ? ?/sec    1.00      6.8±0.08µs        ? ?/sec
decode metadata with stats mask                     1.00      6.9±0.04µs        ? ?/sec    1.00      6.9±0.03µs        ? ?/sec
decode parquet metadata                             1.01      7.2±0.05µs        ? ?/sec    1.00      7.2±0.04µs        ? ?/sec
decode parquet metadata (wide)                      1.00     27.8±0.74ms        ? ?/sec    1.00     27.9±0.75ms        ? ?/sec
decode parquet metadata no path_in_schema (wide)    1.00     27.3±0.80ms        ? ?/sec    1.00     27.2±0.78ms        ? ?/sec
decode parquet metadata w/ size stats (wide)        1.00     34.4±0.54ms        ? ?/sec    1.00     34.4±0.59ms        ? ?/sec
open(default)                                       1.00      7.8±0.05µs        ? ?/sec    1.01      7.8±0.04µs        ? ?/sec
open(page index)                                    1.00    130.5±0.07µs        ? ?/sec    1.00    130.3±0.07µs        ? ?/sec

Per-runner information
metadata — shard 1/1

Node: gk3-benchmark-cluster-nap-a9z1dgmm-1e7d4a80-gbbk

Instance: c4a-highcpu-48 (12 vCPU / 65 GiB)

uname:

Linux bench-c6030780666-3107-dx7qs 6.12.94+ #1 SMP Fri Aug 21 08:00:16 UTC 2026 aarch64 GNU/Linux

BENCH_COMMAND:

cargo bench --features=arrow,async,test_common,experimental,object_store --bench metadata
CPU Details (lscpu)
Architecture:                            aarch64
CPU op-mode(s):                          64-bit
Byte Order:                              Little Endian
CPU(s):                                  48
On-line CPU(s) list:                     0-47
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     48
Socket(s):                               -
Cluster(s):                              1
Stepping:                                r0p1
BogoMIPS:                                2000.00
Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache:                               3 MiB (48 instances)
L1i cache:                               3 MiB (48 instances)
L2 cache:                                96 MiB (48 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-47
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; CSV2, BHB
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected
Resource Usage

base (merge-base)

Metric Value
Wall time 155.0s
Peak memory 98.9 MiB
Avg memory 47.5 MiB
CPU user 149.9s
CPU sys 0.1s
Peak spill 0 B

branch

Metric Value
Wall time 155.0s
Peak memory 98.8 MiB
Avg memory 47.3 MiB
CPU user 149.1s
CPU sys 0.1s
Peak spill 0 B

File an issue against this benchmark runner

@alamb
alamb enabled auto-merge October 7, 2026 19:42
@alamb
alamb added this pull request to the merge queue Oct 7, 2026
@etseidl

etseidl commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Thanks @alamb!

Merged via the queue into apache:main with commit a2f3034 Oct 7, 2026
24 checks passed
@pmoust
pmoust deleted the fix/row-group-count-bound branch October 8, 2026 00:14
@Jefffrey Jefffrey added the bug Squash those bugs label Oct 8, 2026
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.

Unbounded Vec::with_capacity on row-group count in footer metadata decode

5 participants