ryanvickr opened a new pull request, #12514:
URL: https://github.com/apache/arrow-rs/pull/12514

   # Which issue does this PR close?
   
   - Relates to #12325
   
   # Rationale for this change
   
   `read_column_metadata` currently accepts several malformed `ColumnMetaData` 
Thrift payloads without returning an error:
   
   1. Field `1` (`type`) is decoded and discarded without verifying that it 
matches `column_descr.physical_type()`, and `validate_column_metadata` omits 
the `COL_META_TYPE` bit check even though `COL_META_TYPE` is part of 
`COL_META_ALL_REQUIRED`.
   2. Signed count, size, and offset fields (`num_values`, 
`total_uncompressed_size`, `total_compressed_size`, `data_page_offset`, 
`index_page_offset`, `dictionary_page_offset`, `bloom_filter_offset`, and 
`bloom_filter_length`) are stored as `i64`/`i32` in Thrift without rejecting 
negative values.
   
   Downstream code then converts or subtracts these values assuming they are 
non-negative, which can trigger arithmetic overflow, signed-to-unsigned 
wraparound, or panics in `ColumnChunkMetaData::byte_range()`.
   
   Validating these fields during Thrift decoding avoids breaking 
`ColumnChunkMetaData::byte_range(&self) -> (u64, u64)` or 
`ColumnChunkMetaDataBuilder::build(self)` and rejects corrupt footers before 
readers use them.
   
   # What changes are included in this PR?
   
   In `parquet/src/file/metadata/thrift/mod.rs`:
   
   - Check `mask & COL_META_TYPE == 0` in `validate_column_metadata` so missing 
required `type` returns `"Required field type is missing"`.
   - Verify decoded `ColumnMetaData.type` matches 
`column_descr.physical_type()` in `read_column_metadata`.
   - Reject negative values (`< 0`, allowing `0`) via `read_non_negative_i64` / 
`read_non_negative_i32` 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`.
   - Leave `ColumnChunkMetaData::byte_range()` and 
`ColumnChunkMetaDataBuilder::build()` unchanged (non-breaking).
   - Add unit tests covering type mismatch, missing required `type`, and 
negative vs. zero values for all eight numeric 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.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to