Repository navigation
Fix heap-use-after-free in Parquet UUID writer column statistics - #103692
alexey-milovidov merged 3 commits into
Conversation
`ConverterUUID::getBatch` reuses a member `PODArray<UUID> swapped_buf`, filling `buf[i].ptr = &swapped_buf[i]` before returning. The Parquet writer loop then feeds those pointers into `StatisticsFixedStringRef`, which keeps raw `const uint8_t *` `min`/`max`. After a page is flushed, `total_statistics.merge(page_statistics)` propagates these pointers into `total_statistics`. When the next batch of values exceeds the current capacity (e.g. after a low-density null run, where `data_count` swings from near 0 to near `write_batch_size`), `swapped_buf.resize(count)` reallocates and frees the prior buffer. The `total_statistics.min`/`max` pointers are now dangling. The next call to `merge` performs `memcmp(p, total_statistics.min, 16)` and reads from freed memory — heap-use-after-free, detected by AddressSanitizer in BuzzHouse with STID 1288-3e88. Switch `ConverterUUID::Statistics` to `StatisticsFixedStringCopy<16, false>`, which stores min/max as inline 16-byte arrays and copies bytes via memcpy on update/merge, eliminating the lifetime dependency. UUIDs are written big-endian and Parquet's UUID logical type compares as unsigned binary, so `SIGNED=false` is correct. Other Parquet converters using `StatisticsFixedStringRef` / `StatisticsStringRef` (e.g. `ConverterFixedString`, `ConverterString`, `ConverterEnumAsString`) point into the source column's stable storage (`column.getChars()`, the enum's name table) rather than an owned buffer that resizes between batches, so they are unaffected. Add a stateless regression test that triggers the bug pre-fix and passes post-fix: 100k Nullable(UUID) rows with clustered nulls, small `output_format_parquet_data_page_size`, custom encoder enabled. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100366&sha=f8d1795edeee81e2ec015f68c1a82721803c80f8&name_0=PR&name_1=BuzzHouse%20%28arm_asan_ubsan%29 PR with original sanitizer hit: ClickHouse#100366
|
cc @al13n321 @Avogar — could you review this? It fixes a heap-use-after-free in the Parquet writer's UUID column statistics path: |
|
Pre-PR validation gate (per worker policy, session
Related fuzzer-found bug already fixed earlier in the same STID (1288-3e88) — MSAN side at |
|
Workflow [PR], commit [00a406c] Summary: ✅
AI ReviewSummaryThis PR fixes the Final VerdictStatus: ✅ Approve |
|
@groeneai, the test does not reproduce the issue in the "Bug fix validation check". Either make the test stronger, or change the changelog category. |
|
@alexey-milovidov went with the second option: changed the changelog category to Reason the test cannot be made stronger here: this is a heap-use-after-free that only aborts reliably under a sanitizer build. The The real fix and the regression test are unchanged. The note Could you remove the |
…ats-uaf-1288-3e88
|
Continued work on this PR:
The fix itself is confirmed correct: |
LLVM Coverage Report
Changed lines: Changed C/C++ lines coverable by tests: 0 (nothing to score) | Lost baseline coverage: none · Uncovered code |
CI Ledger — covered SHA:
|
A heap-use-after-free in the Parquet writer's UUID column statistics path,
detected by AddressSanitizer in BuzzHouse fuzzing (STID 1288-3e88). Hit on
PR #100366 (
Optimize minmax skip index evaluation performance) at commitf8d1795edeee81e2ec015f68c1a82721803c80f8onBuzzHouse (arm_asan_ubsan).ConverterUUID::getBatchreuses a memberPODArray<UUID> swapped_buf,filling each output
parquet::FixedLenByteArray::ptr = &swapped_buf[i]before returning. The Parquet writer loop in
writeColumnImplfeeds thosepointers into
StatisticsFixedStringRef, which keeps rawconst uint8_t *min/max. After a page flush,total_statistics.merge(page_statistics)propagates the same raw pointers into
total_statistics.When the next batch's
data_countexceeds the current capacity (e.g. aftera low-density null run, where
data_countswings from near 0 to nearwrite_batch_size),swapped_buf.resize(count)reallocates, freeing theprior buffer.
total_statistics.min/maxare now dangling. The nextmergeperformsmemcmp(p, total_statistics.min, 16)and reads from freedmemory.
Fix: switch
ConverterUUID::StatisticstoStatisticsFixedStringCopy<sizeof(UUID), /*SIGNED=*/ false>, which storesmin/max as inline 16-byte arrays and copies bytes via
memcpyonupdate/merge, with no lifetime dependency on the converter's buffer. UUIDs
are written big-endian and Parquet's UUID logical type compares as unsigned
binary, so
SIGNED=falseis correct.Other Parquet converters using
StatisticsFixedStringRef/StatisticsStringRef(ConverterFixedString,ConverterString,ConverterFixedStringAsString,ConverterEnumAsString) point into thesource column's stable storage (
column.getChars, the enum's name table)rather than an owned buffer that resizes between batches, so they are not
affected.
Local AddressSanitizer reproducer (deterministic, fails first try without
the fix, passes 50/50 with the fix):
Codified as
tests/queries/0_stateless/04141_parquet_uuid_statistics_uaf.sh.Recategorized from
Bug FixtoCI Fix or Improvementper maintainerrequest: the bug is a heap-use-after-free that only aborts reliably under a
sanitizer build, but the
Bugfix validation (functional tests)job runs themaster HEAD release binary, where the freed read does not deterministically
fail (the test's round-trip row and null counts are unaffected by the
corrupted statistics bytes). The fix and the regression test are kept; only
the changelog category changes so the
pr-bugfixvalidation contract nolonger applies.
CI report (original sanitizer hit):
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100366&sha=f8d1795edeee81e2ec015f68c1a82721803c80f8&name_0=PR&name_1=BuzzHouse%20%28arm_asan_ubsan%29
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Documentation entry for user-facing changes
Version info
26.6.1.452