Skip to content

Cherry pick #99680 to 25.8: Fix heap-buffer-overflow in T64 and abort in Multiple decompression codecs - #110832

Merged
robot-clickhouse-ci-2 merged 12 commits into
backport/25.8/99680from
cherrypick/25.8/99680
Jul 17, 2026
Merged

robot-clickhouse-ci-2 merged 12 commits into
backport/25.8/99680from
cherrypick/25.8/99680

Conversation

@robot-clickhouse-ci-2

Copy link
Copy Markdown
Contributor

Original pull-request #99680

Do not merge this PR manually

This pull-request is a first step of an automated backporting.
It contains changes similar to calling git cherry-pick locally.
If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.

The check results does not matter at this step - you can safely ignore them.

Troubleshooting

If the conflicts were resolved in a wrong way

If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

motsc and others added 11 commits March 16, 2026 17:13
`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]>
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]>
… 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
…s-checks

Fix heap-buffer-overflow in T64 and abort in Multiple decompression codecs
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default labels Jul 17, 2026
Resolve cherry-pick conflicts against the 25.8 base:

- CompressionCodecMultiple.cpp: keep the two added bounds checks.
- CompressionCodecT64.cpp: keep the 25.8 version unchanged. 25.8 has no
  unaligned trailing-byte memcpy path and already rejects a compressed
  size smaller than the min/max header, so neither T64 overflow is
  reachable here.
- gtest_compressionCodec.cpp: add the four regression tests on top of the
  25.8 test file; the two T64 cases assert 25.8 rejects short input at
  its existing header-size guard.
@robot-clickhouse-ci-2
robot-clickhouse-ci-2 merged commit 700d269 into backport/25.8/99680 Jul 17, 2026
1 check passed
@robot-clickhouse-ci-2
robot-clickhouse-ci-2 deleted the cherrypick/25.8/99680 branch July 17, 2026 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants