Skip to content

Fix crashes of the Parquet, ORC and Iceberg readers on malformed input - #115703

Merged
alexey-milovidov merged 4 commits into
masterfrom
fix-format-readers-malformed-input
Aug 24, 2026
Merged

alexey-milovidov merged 4 commits into
masterfrom
fix-format-readers-malformed-input

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Aug 21, 2026 •

Copy link
Copy Markdown
Member

Fixes in the readers of the file formats, all of them on malformed input:

  • The lengths of a DELTA_BYTE_ARRAY Parquet page are themselves DELTA_BINARY_PACKED. When a page
    declares zero of them, the buffer for them has zero size, and DeltaBinaryPackedDecoder::decodeImpl
    still 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.
  • The filtered branch of DeltaByteArrayDecoder::decode cast the destination column to
    ColumnString unconditionally, while the unfiltered branch right above it decodes into a temporary
    column and converts when the converter is not trivial. For a BYTE_ARRAY column with a Decimal
    logical type the destination is a ColumnDecimal, and assert_cast is a plain static_cast in
    the release build, so ColumnString methods were called on it.
  • The content and the status of an entry of an Iceberg manifest file were cast to an enum without
    checking 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 new instead of the
default one of the library, which uses std::malloc: the default one returns a null pointer when the
allocation 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):

  • Critical Bug Fix (crash, data loss, RBAC)

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_ARRAY page with an empty length stream, a DELTA_BYTE_ARRAY page of a Decimal column 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

  • Merged into: 26.9.1.52 (included in 26.9 and later)
  • Backported to: 26.8.1.1997, 26.7.6.25, 26.6.4.56, 26.3.29.4, 25.8.34.5

@clickhouse-gh

clickhouse-gh Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [0d43830]

Summary: ✅


AI Review

Summary

This PR hardens malformed-input handling in the Parquet DELTA_BYTE_ARRAY, ORC, and Iceberg readers, and the code changes are consistent with the bugs described. I found one remaining evidence gap: the new regression coverage proves the Parquet fixes, but the Iceberg malformed-enum checks are still unproven by tests.

Tests
  • ⚠️ src/Storages/ObjectStorage/DataLakes/Common/AvroForIcebergDeserializer.cpp:121 and src/Storages/ObjectStorage/DataLakes/Iceberg/StatelessMetadataFileGetter.cpp:225 now reject out-of-range manifest enums, but the PR adds no Iceberg fixture or stateless query that would fail if either check were removed. A minimal malformed manifest / manifest-list test that expects ICEBERG_SPECIFICATION_VIOLATION would close this gap.
Final Verdict

The 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

Metric Baseline Current Δ
Lines 87.00% 87.00% +0.00%
Functions 91.90% 91.90% +0.00%
Branches 79.30% 79.30% +0.00%

Changed lines: Changed C/C++ lines covered: 54/77 (70.13%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! labels Aug 21, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 0d43830ee with master ef23be3ee (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 709.21 MiB 706.19 MiB -3.02 MiB (-0.43%)

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 units

12 translation units recompiled, 54 s compile time in total, 12 of them have a recent master baseline.

Job report

- `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.
@Avogar Avogar self-assigned this Aug 24, 2026
`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>();

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.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕵 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.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 24, 2026
Merged via the queue into master with commit cbbbd22 Aug 24, 2026
178 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-format-readers-malformed-input branch August 24, 2026 23:52
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Aug 25, 2026
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 25, 2026
clickhouse-gh Bot added a commit that referenced this pull request Aug 25, 2026
Backport #115703 to 26.8: Fix crashes of the Parquet, ORC and Iceberg readers on malformed input
robot-ch-test-poll4 added a commit that referenced this pull request Aug 27, 2026
Cherry pick #115703 to 25.8: Fix crashes of the Parquet, ORC and Iceberg readers on malformed input
robot-clickhouse added a commit that referenced this pull request Aug 27, 2026
robot-ch-test-poll4 added a commit that referenced this pull request Aug 27, 2026
Cherry pick #115703 to 26.3: Fix crashes of the Parquet, ORC and Iceberg readers on malformed input
robot-clickhouse added a commit that referenced this pull request Aug 27, 2026
robot-ch-test-poll4 added a commit that referenced this pull request Aug 27, 2026
Cherry pick #115703 to 26.5: Fix crashes of the Parquet, ORC and Iceberg readers on malformed input
robot-clickhouse added a commit that referenced this pull request Aug 27, 2026
robot-ch-test-poll4 added a commit that referenced this pull request Aug 27, 2026
Cherry pick #115703 to 26.6: Fix crashes of the Parquet, ORC and Iceberg readers on malformed input
robot-clickhouse added a commit that referenced this pull request Aug 27, 2026
robot-ch-test-poll4 added a commit that referenced this pull request Aug 27, 2026
Cherry pick #115703 to 26.7: Fix crashes of the Parquet, ORC and Iceberg readers on malformed input
robot-clickhouse added a commit that referenced this pull request Aug 27, 2026
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Aug 27, 2026
alexey-milovidov added a commit that referenced this pull request Aug 27, 2026
Backport #115703 to 25.8: Fix crashes of the Parquet, ORC and Iceberg readers on malformed input
pull Bot pushed a commit to admariner/ClickHouse that referenced this pull request Aug 27, 2026
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]>
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Aug 28, 2026
clickhouse-gh Bot added a commit that referenced this pull request Aug 29, 2026
Backport #115703 to 26.7: Fix crashes of the Parquet, ORC and Iceberg readers on malformed input
clickhouse-gh Bot added a commit that referenced this pull request Aug 31, 2026
Backport #115703 to 26.6: Fix crashes of the Parquet, ORC and Iceberg readers on malformed input
alexey-milovidov added a commit that referenced this pull request Sep 1, 2026
Backport #115703 to 26.3: Fix crashes of the Parquet, ORC and Iceberg readers on malformed input
bytehalo-infra added a commit to sentioxyz/ClickHouse that referenced this pull request Sep 25, 2026
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]>
bytehalo-infra added a commit to sentioxyz/ClickHouse that referenced this pull request Sep 25, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants