Repository navigation
Fix crashes of the Parquet, ORC and Iceberg readers on malformed input - #115703
Conversation
|
Workflow [PR], commit [0d43830] Summary: ✅
AI ReviewSummaryThis PR hardens malformed-input handling in the Parquet Tests
Final VerdictThe fixes look reasonable, but I would not clear the PR without a focused Iceberg regression test for the new enum-validation paths. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 54/77 (70.13%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units12 translation units recompiled, 54 s compile time in total, 12 of them have a recent master baseline. |
- `HiveORCFile::prepareReader` now creates the liborc reader with the same memory pool as `NativeORCBlockInputFormat`, so a malformed ORC file coming through `StorageHive` does not reach the default `std::malloc` pool either. - The `content` of an entry of an Iceberg manifest *list* is validated before it is converted to `ManifestFileContentType`; consumers only test it for equality with `DELETE`, so an out-of-range value used to be silently treated as a data manifest. - Exclude the two hand-crafted `DELTA_BYTE_ARRAY` files from `00900_long_parquet_load_2`: one of them is malformed on purpose and made that test print an exception.
`ORCBlockOutputFormat` left `orc::WriterOptions` with the default pool of the library, so the buffers of `BufferedOutputStream`, the compression block and `orc::Writer::createRowBatch` were still allocated with `std::malloc`: invisible to the memory tracker, and a null pointer that the library dereferences when the allocation fails. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
| { | ||
| /// The value comes from the file and has to be validated: casting an arbitrary integer to | ||
| /// the enum and switching over it below would be undefined behaviour. | ||
| const auto content_type_value = getValueFromRowByName(row_index, c_data_file_content, TypeIndex::Int32).safeGet<UInt64>(); |
There was a problem hiding this comment.
This hardens the file-controlled Iceberg enums, but the PR still only adds Parquet regression coverage. I do not see a focused Iceberg fixture that would fail if the data_file.content / status validation here or the manifest-list f_content check in StatelessMetadataFileGetter.cpp were removed again.
Given the contract of this change is "malformed Iceberg metadata throws ICEBERG_SPECIFICATION_VIOLATION instead of running into UB", please add a small stateless Iceberg reproducer with an out-of-range manifest-entry enum and an out-of-range manifest-list content value.
There was a problem hiding this comment.
🕵 Added the requested Iceberg regression coverage in a follow-up (this PR is already merged): #116318. The test patches a single enum value in place in the Avro metadata of a well-formed IcebergLocal table and covers an out-of-range status and data_file.content of a manifest entry and an out-of-range and a negative content of a manifest list entry, all expecting ICEBERG_SPECIFICATION_VIOLATION.
Backport #115703 to 26.8: Fix crashes of the Parquet, ORC and Iceberg readers on malformed input
Cherry pick #115703 to 25.8: Fix crashes of the Parquet, ORC and Iceberg readers on malformed input
… readers on malformed input
Cherry pick #115703 to 26.3: Fix crashes of the Parquet, ORC and Iceberg readers on malformed input
… readers on malformed input
Cherry pick #115703 to 26.5: Fix crashes of the Parquet, ORC and Iceberg readers on malformed input
… readers on malformed input
Cherry pick #115703 to 26.6: Fix crashes of the Parquet, ORC and Iceberg readers on malformed input
… readers on malformed input
Cherry pick #115703 to 26.7: Fix crashes of the Parquet, ORC and Iceberg readers on malformed input
… readers on malformed input
Backport #115703 to 25.8: Fix crashes of the Parquet, ORC and Iceberg readers on malformed input
Regression test for the Iceberg part of ClickHouse#115703: an out-of-range `status` or `data_file.content` of a manifest entry and an out-of-range (or negative) `content` of a manifest list entry must throw `ICEBERG_SPECIFICATION_VIOLATION` instead of casting the unchecked value to a C++ enum. The test creates a well-formed table with the `IcebergLocal` engine and rewrites a single enum value in place: the Avro metadata files are written with the null codec, so a schema-driven walk over the first record finds the field without a third-party Avro library. Co-Authored-By: Claude Fable 5 <[email protected]>
…nd Iceberg readers on malformed input
Backport #115703 to 26.7: Fix crashes of the Parquet, ORC and Iceberg readers on malformed input
Backport #115703 to 26.6: Fix crashes of the Parquet, ORC and Iceberg readers on malformed input
Backport #115703 to 26.3: Fix crashes of the Parquet, ORC and Iceberg readers on malformed input
PROTO: malformed Parquet (DELTA_BYTE_ARRAY, incl. a Decimal column under a filter), Iceberg manifest enum, ORC allocation -> crash. Effect in the production build a394e92: the upstream test crashes the production build (SIGSEGV) on a DELTA_BYTE_ARRAY Decimal column under PREWHERE. Upstream patch, with its test(s): 00900_long_parquet_load_2, 05035_parquet_delta_byte_array_malformed. The hunk of `00900_long_parquet_load_2.sh` does not apply because the fork lacks an earlier fixture (ClickHouse#112498); the two new fixtures are added to that test's skip list by hand. The binary fixtures are taken from the backport PR and checked against the blob ids of the upstream diff. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…o reader bugs tests/decimal512/tools/parquet/parquet_decimal_writer.py writes Parquet DECIMAL columns with exactly the physical layout a test asks for (standard library only, no pyarrow): any FIXED_LEN_BYTE_ARRAY width 1..64 with any declared precision, BYTE_ARRAY values of 0..64 bytes, PLAIN / BYTE_STREAM_SPLIT / DELTA_BYTE_ARRAY / RLE_DICTIONARY, UNCOMPRESSED or GZIP, data page V1 or V2, REQUIRED or OPTIONAL, with an independent oracle for the expected text. - 10317_parquet_decimal512_read_matrix: Decimal512 read through every value offset of the big-endian decoder (widths 1..64, lengths 0..64) in 16 layouts; passes on the production build and on the candidates (a coverage test for the padded read, no bug). - 10318_parquet_decimal512_width_mismatch: a FIXED_LEN_BYTE_ARRAY wider than 32 bytes with a narrower declared precision (the Int512 decoder wrote 64 bytes per value into a 32/8/4-byte column: wrong sums and heap corruption on the production build) and a BYTE_ARRAY DECIMAL(100, 2) with DELTA_BYTE_ARRAY under PREWHERE (SIGSEGV on the production build); fixed by the backports of ClickHouse#113046 and ClickHouse#115703. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fixes in the readers of the file formats, all of them on malformed input:
DELTA_BYTE_ARRAYParquet page are themselvesDELTA_BINARY_PACKED. When a pagedeclares zero of them, the buffer for them has zero size, and
DeltaBinaryPackedDecoder::decodeImplstill wrote the first value through it, because the special case for the first value did not look
at the number of values it was asked for.
DeltaByteArrayDecoder::decodecast the destination column toColumnStringunconditionally, while the unfiltered branch right above it decodes into a temporarycolumn and converts when the converter is not trivial. For a
BYTE_ARRAYcolumn with aDecimallogical type the destination is a
ColumnDecimal, andassert_castis a plainstatic_castinthe release build, so
ColumnStringmethods were called on it.contentand thestatusof an entry of an Iceberg manifest file were cast to an enum withoutchecking the value, and the switch over the content type has no default branch, so an out-of-range
value fell off the end of a function that has to return a value.
Also, the ORC reader now allocates through a memory pool that goes to
operator newinstead of thedefault one of the library, which uses
std::malloc: the default one returns a null pointer when theallocation fails and the library dereferences it, and its allocations were invisible to the memory
tracker. A malformed file can make the library ask for an arbitrarily large buffer.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix crashes of the Parquet, ORC and Iceberg readers on malformed input: a
DELTA_BYTE_ARRAYpage with an empty length stream, aDELTA_BYTE_ARRAYpage of aDecimalcolumn read under a filter, an out-of-range enum in an Iceberg manifest file and an oversized allocation in the ORC library.Workflow [PR]
Sync PR [sync-upstream/pr/115703]
Version info
26.9.1.52(included in26.9and later)26.8.1.1997,26.7.6.25,26.6.4.56,26.3.29.4,25.8.34.5