Repository navigation
fix(parquet): bound row-group count by remaining input before reserving - #11419
Conversation
6097ca4 to
fa1b71c
Compare
| // 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() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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]>
fa1b71c to
975c97e
Compare
|
run benchmark metadata |
|
🤖 Benchmark starting (GKE) | trigger Target: metadata Sharding factor: 1 (1 workers). Comparing fix/row-group-count-bound (975c97e) to 6b34163 (merge-base) diff Run configurationrun benchmark metadata
shards: 1
Results will be posted when all workers finish. File an issue against this benchmark runner |
|
🤖 Benchmark completed (GKE) | trigger Target: metadata Comparing fix/row-group-count-bound (975c97e) to 6b34163 (merge-base) diff Run configurationrun benchmark metadata
shards: 1
DetailsPer-runner informationmetadata — shard 1/1Node: gk3-benchmark-cluster-nap-a9z1dgmm-1e7d4a80-gbbk Instance: c4a-highcpu-48 (12 vCPU / 65 GiB) uname: BENCH_COMMAND: cargo bench --features=arrow,async,test_common,experimental,object_store --bench metadataCPU Details (lscpu)Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
Co-authored-by: Ed Seidl <[email protected]>
|
Thanks @alamb! |
Which issue does this PR close?
Rationale for this change
Decoding a Parquet footer reserves a
Vecsized from the declaredrow-group count before reading any row group:
list_ident.sizecomes straight off the wire andRowGroupMetaDatais alarge struct, so a footer of a few bytes that declares a huge row-group
count asks for
count * size_of::<RowGroupMetaData>()up front, before asingle row group is read. On a host under memory pressure that allocation
aborts the process.
PR #10979 bounded
read_thrift_vecby the remaining input. The row-grouplist is decoded inline in
parquet_metadata_from_bytesand does not gothrough 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?
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.
row_group_count_exceeding_remaining_input_is_rejected) builds avalid footer prefix and declares an over-sized
row_groupslist, thenasserts the decode reports the bound. Without the bound the same input
instead fails later with
Required field columns is missing, so thetest 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 errordescribing the bound, rather than attemptinga large allocation. This was found while hardening the Parquet
external-table reader in Ravel.