Repository navigation
Fix heap-buffer-overflow in T64 and abort in Multiple decompression codecs - #99680
Conversation
`CompressionCodecT64::doDecompressData` had two heap-buffer-overflow vulnerabilities discovered via fuzzing: - `memcpy(dst, src, bytes_to_skip)` at the start had no check that `bytes_size >= bytes_to_skip`, allowing a read past the compressed source buffer - The header read (`memcpy(&min, src, sizeof(MinMaxType))`) had no check that `bytes_size >= header_size` (16 bytes), causing OOB reads on short inputs `CompressionCodecMultiple::doDecompressData` had two vulnerabilities: - No check that `compression_methods_size + 1 <= source_size` before constructing the `PODArray` from `&source[n+1]..&source[m]`; if `n >= m`, the reversed range caused the allocator to attempt a ~2^64-byte allocation, aborting the process - No check that `source_size >= COMPRESSED_BLOCK_HEADER_SIZE` (9 bytes) before calling `readDecompressedBlockSize`, which reads at `source[5..8]` Crash reproducer for T64 (9 bytes): `85 68 85 3b 8d 85 0a fd 81 2c` Crash reproducer for Multiple (9 bytes): `00 00 00 00 00 00 db 00 9a`
Add two `ASSERT_THROW` regression tests that reproduce the exact crash inputs found by fuzzing: - `T64Test::DecompressMalformedInput` — 2-byte payload `81 2c` with `decompressed_size = 26757` triggered a heap-buffer-overflow in `decompressData` because `bytes_to_skip > bytes_size` with no bounds check before the trailing-bytes `memcpy`. - `CompressionCodecMultipleTest::DecompressMalformedInput` — 1-byte payload `9a` claiming 154 codecs triggered a process abort in `doDecompressData` because `PODArray` was constructed from a reversed pointer range (`&source[155]..&source[1]`), causing a ~2^64-byte allocation attempt. Both inputs now throw `Exception` instead of crashing. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
The test `04004_alter_modify_column_ttl_without_type` uses `today()` which makes the test non-deterministic and can cause failures around midnight or in different timezones. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Resolve conflict in gtest_compressionCodec.cpp by keeping both the T64/Multiple malformed-input regression tests and the new ALP codec tests added on master. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
|
Workflow [PR], commit [2de7f1b] Summary: ✅ AI ReviewSummaryThis PR hardens malformed-input handling in ClickHouse Rules
Final Verdict
|
| if (compressed_buf.size() >= 1_GiB) | ||
| throw Exception(decompression_error_code, "Too large compressed size: {}", compressed_buf.size()); | ||
|
|
||
| if (source_size < COMPRESSED_BLOCK_HEADER_SIZE) |
There was a problem hiding this comment.
❌ The new short-header guard checks source_size, but this variable is the outer block size and no longer tracks the current compressed_buf after each decompression step.
On later iterations, compressed_buf.data() can still contain fewer than COMPRESSED_BLOCK_HEADER_SIZE bytes while source_size remains larger, so readDecompressedBlockSize(compressed_buf.data()) may still read past the end.
Please validate compressed_buf.size() here instead of source_size.
There was a problem hiding this comment.
I am thinking source_size is the right check here. It tracks the actual content length in compressed_buf, not the buffer's allocated size. After the swap at line 124, compressed_buf.size() includes the padding from line 120, so it's always >= source_size. Switching to compressed_buf.size() would be a weaker guard — it'd let through cases that source_size < COMPRESSED_BLOCK_HEADER_SIZE already catches.
… checks
Cover the two additional guards added in the fix commit:
- `T64Test::DecompressMalformedInputShortHeader` — payload present but
shorter than the 16-byte min/max header required by T64
(`bytes_size < header_size`, Bug 1b).
- `CompressionCodecMultipleTest::DecompressMalformedInputShortBlockHeader` —
compressed data after the methods list is shorter than
`COMPRESSED_BLOCK_HEADER_SIZE` (9), triggering the OOB read (Bug 1d).
Also rename existing tests to clarify which guard each covers, and fix
`CompressionCodecMultiple` construction to use the byte-code path instead of
`get("Multiple", {})` which throws `Codec Multiple cannot be specified directly`.
…cks' into fix/compression-codec-bounds-checks
Co-authored-by: Yakov Olkhovskiy <[email protected]>
Co-authored-by: Yakov Olkhovskiy <[email protected]>
LLVM Coverage Report
PR changed lines: PR changed-lines coverage: 90.22% (83/92, 0 noise lines excluded) |
Cherry pick #99680 to 25.8: Fix heap-buffer-overflow in T64 and abort in Multiple decompression codecs
… Multiple decompression codecs
Backport #99680 to 25.8: Fix heap-buffer-overflow in T64 and abort in Multiple decompression codecs
| ASSERT_THROW(codec->decompress(source, source_size, dest.data()), Exception); | ||
| } | ||
|
|
||
| TEST(CompressionCodecMultipleTest, DecompressMalformedInputReversedRange) |
There was a problem hiding this comment.
Both tests below do not hit the check this PR introduced because we set decompressed_size = 0
Summary
Two crash-triggering bugs found by new libFuzzer targets (
t64_decompress_fuzzerandmultiple_decompress_fuzzer):CompressionCodecT64— heap-buffer-overflowdecompressData<T, bool>inCompressionCodecT64.cpphad two missing bounds checks:memcpy(dst, src, bytes_to_skip)at the start — no check thatbytes_to_skip <= bytes_size, allowing a read past the compressed source buffer.memcpy(&min, src, sizeof(MinMaxType))— no check thatbytes_size >= 16(the min/max header size), causing an OOB read on short inputs.Crash reproducer (10-byte fuzzer input):
85 68 85 3b 8d 85 0a fd 81 2cCompressionCodecMultiple— process abortdoDecompressDatainCompressionCodecMultiple.cpphad two missing bounds checks:compression_methods_size + 1 <= source_sizebefore constructingPODArrayfrom&source[n+1]..&source[m]. Whenn >= m(reversed range),PODArrayattempts a ~2^64-byte allocation, which aborts the process viaabortOnFailedAssertion— uncatchable bycatch(...).source_size >= COMPRESSED_BLOCK_HEADER_SIZE(9 bytes) before callingreadDecompressedBlockSize, which reads atsource[5..8].Crash reproducer (9-byte fuzzer input):
00 00 00 00 00 00 db 00 9aChanges
src/Compression/CompressionCodecT64.cpp: two bounds checks withExceptionthrowssrc/Compression/CompressionCodecMultiple.cpp: two bounds checks withExceptionthrowssrc/Compression/tests/gtest_compressionCodec.cpp:ASSERT_THROWregression tests for both crash reproducersTest plan
T64Test::DecompressMalformedInput— verifies the 2-byte T64 reproducer throwsExceptionCompressionCodecMultipleTest::DecompressMalformedInput— verifies the 1-byte Multiple reproducer throwsExceptionT64Test::TranscodeRawInput— existing round-trip test still passes for all integer typesChangelog category
Bug Fix
Changelog entry
Fixed heap-buffer-overflow in
CompressionCodecT64and process abort inCompressionCodecMultiplewhen decompressing malformed compressed data. Both issues were found by new libFuzzer targets. The codecs now throw an exception instead of crashing.Version info
26.3.1.858(included in26.3and later)25.8.29.23