Skip to content

fix(parquet): harden ColumnMetaData Thrift validation - #12514

Closed
ryanvickr wants to merge 2 commits into
apache:mainfrom
ryanvickr:fix/column-metadata-thrift-validation
Closed

ryanvickr wants to merge 2 commits into
apache:mainfrom
ryanvickr:fix/column-metadata-thrift-validation

Conversation

@ryanvickr

@ryanvickr ryanvickr commented Nov 30, 2026 •

Copy link
Copy Markdown

Which issue does this PR close?

Rationale for this change

When decoding ColumnMetaData from a Parquet footer, the Thrift decoder currently lets a few invalid inputs through:

  • The column's physical type field is read and discarded without checking it against the schema, and required-field validation never explicitly checks that type was present.
  • Signed integer fields for value counts, byte sizes, and page or Bloom filter offsets accept negative values.

Downstream code expects these values to be non-negative and consistent with the schema, so malformed footers can cause arithmetic overflow, wraparound on unsigned casts, or panics when computing byte ranges. Validating them during Thrift decoding catches corrupt footers up front without requiring breaking changes to ColumnChunkMetaData::byte_range() or ColumnChunkMetaDataBuilder::build().

What changes are included in this PR?

In parquet/src/file/metadata/thrift/mod.rs:

  • Require ColumnMetaData.type to be present and match the column descriptor's physical type.
  • Reject negative values (while still allowing 0) for num_values, total_uncompressed_size, total_compressed_size, data_page_offset, index_page_offset, dictionary_page_offset, bloom_filter_offset, and bloom_filter_length.
  • Add unit tests for missing physical type, physical type mismatch, and negative vs. zero values across all eight fields.

Are these changes tested?

Yes — unit tests are included in parquet::file::metadata::thrift::tests:

  • test_read_column_metadata_rejects_type_mismatch
  • test_read_column_metadata_missing_type_is_error
  • test_read_column_metadata_rejects_negative_fields (verifies -1 and i64::MIN / i32::MIN return errors while 0 remains accepted for all eight fields)

Are there any significant user-facing changes?

No breaking API changes. ColumnChunkMetaData::byte_range(&self) -> (u64, u64) and ColumnChunkMetaDataBuilder::build remain unchanged. Malformed Thrift metadata with missing or mismatched ColumnMetaData.type or negative counts/sizes/offsets now fails during metadata decoding with a ParquetError::General.

AI usage disclosure

AI coding assistance was used to adapt the validation logic, draft the unit tests, and draft this PR description; all changes and test results were reviewed by the author.

Validate ColumnMetaData.type (presence and physical type match against schema) and reject negative counts, sizes, and offsets during Thrift decoding.
@boring-cyborg boring-cyborg Bot added the parquet parquet crate label Nov 30, 2026
@ryanvickr

Copy link
Copy Markdown
Author

cc @etseidl @Rich-T-kid — fork CI is green. I noticed #12369 already checks negative data/dictionary page offsets and compressed size on column metadata; this PR also validates physical type presence and schema matches plus negative values across the remaining count, size, offset, and Bloom filter fields during Thrift decoding. Happy to coordinate or adjust if you'd prefer these combined or sequenced.

@etseidl

etseidl commented Nov 30, 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/column-metadata-thrift-validation (23389e1) to 5e2595e (merge-base) diff

Run configuration
run benchmark metadata
shards: 1
Trigger comment
run benchmark metadata

Results will be posted when all workers finish.


File an issue against this benchmark runner

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark completed (GKE) | trigger

Target: metadata

Comparing fix/column-metadata-thrift-validation (23389e1) to 5e2595e (merge-base) diff

Run configuration
run benchmark metadata
shards: 1
Trigger comment
run benchmark metadata
Details
group                                               base                                   changed
-----                                               ----                                   -------
decode metadata (wide) with schema                  1.00     25.6±0.12ms        ? ?/sec    1.00     25.7±0.45ms        ? ?/sec
decode metadata (wide) with skip PES                1.01     26.2±0.29ms        ? ?/sec    1.00     26.0±0.44ms        ? ?/sec
decode metadata (wide) with skip all stats          1.00     29.4±0.16ms        ? ?/sec    1.01     29.8±0.38ms        ? ?/sec
decode metadata (wide) with skip column stats       1.02     27.6±0.71ms        ? ?/sec    1.00     27.1±0.35ms        ? ?/sec
decode metadata (wide) with skip size stats         1.00     30.2±0.15ms        ? ?/sec    1.00     30.2±0.44ms        ? ?/sec
decode metadata (wide) with stats mask              1.00     25.6±0.22ms        ? ?/sec    1.00     25.5±0.43ms        ? ?/sec
decode metadata with schema                         1.00      4.2±0.02µs        ? ?/sec    1.01      4.2±0.01µs        ? ?/sec
decode metadata with skip PES                       1.00      7.1±0.08µs        ? ?/sec    1.00      7.1±0.09µs        ? ?/sec
decode metadata with skip column stats              1.02      7.0±0.17µs        ? ?/sec    1.00      6.9±0.02µs        ? ?/sec
decode metadata with stats mask                     1.00      7.0±0.14µs        ? ?/sec    1.00      7.0±0.11µs        ? ?/sec
decode parquet metadata                             1.00      7.3±0.02µs        ? ?/sec    1.01      7.4±0.01µs        ? ?/sec
decode parquet metadata (wide)                      1.01     27.9±0.17ms        ? ?/sec    1.00     27.7±0.41ms        ? ?/sec
decode parquet metadata no path_in_schema (wide)    1.00     26.9±0.17ms        ? ?/sec    1.00     27.0±0.36ms        ? ?/sec
decode parquet metadata w/ size stats (wide)        1.01     34.4±0.15ms        ? ?/sec    1.00     34.1±0.59ms        ? ?/sec
open(default)                                       1.00      7.8±0.17µs        ? ?/sec    1.00      7.8±0.14µs        ? ?/sec
open(page index)                                    1.00    134.9±0.16µs        ? ?/sec    1.00    134.4±0.06µs        ? ?/sec
read page index                                     1.00    126.8±0.10µs        ? ?/sec    1.00    126.4±0.10µs        ? ?/sec
read page index reduced columns                     1.00     13.5±0.03µs        ? ?/sec    1.00     13.4±0.01µs        ? ?/sec

Per-runner information
metadata — shard 1/1

Node: gk3-benchmark-cluster-nap-82xxsnow-cf225dd0-bg4k

Instance: c4a-highmem-16 (12 vCPU / 65 GiB)

uname:

Linux bench-c7288448604-5971-ntgfx 6.12.105+ #1 SMP Sat Sep 19 07:55:25 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):                                  16
On-line CPU(s) list:                     0-15
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     16
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:                               1 MiB (16 instances)
L1i cache:                               1 MiB (16 instances)
L2 cache:                                32 MiB (16 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-15
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 170.0s
Peak memory 124.8 MiB
Avg memory 62.3 MiB
CPU user 167.9s
CPU sys 0.1s
Peak spill 0 B

branch

Metric Value
Wall time 170.0s
Peak memory 148.8 MiB
Avg memory 66.6 MiB
CPU user 167.2s
CPU sys 0.1s
Peak spill 0 B

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 for the effort @ryanvickr, but I don't think I'm inclined to approve this PR. Many of the changes are validating fields that are either completely ignored within the crate or already validated where they are used. The remaining fields that can lead to a panic are already being addressed in #12369, which is tied to the same audit issue you reference.

While I can understand a desire to fully validate the metadata, I don't think it's necessarily this crate's responsibility to provide that blanket validation.

@ryanvickr

Copy link
Copy Markdown
Author

Makes sense — thanks for taking a look and running the benchmark! Since #12369 already covers the byte-range fields and Bloom filters are validated where used, I'll go ahead and close this out.

One small note in case it's useful: the required-field mask for column metadata currently includes the physical type field, even though the validation function doesn't check for it (so a missing type falls through without an error). Might be worth either dropping it from the required mask or adding the check if you're touching that area in #12369.

@ryanvickr ryanvickr closed this Dec 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

parquet parquet crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants