Repository navigation
Fix buffer overflow in CompressionCodecMultiple - #60731
Merged
alexey-milovidov merged 2 commits intoMar 4, 2024
Merged
Conversation
Contributor
|
This is an automated comment for commit 7609856 with description of existing statuses. It's updated for the latest CI running ❌ Click here to open a full report in a separate page Successful checks
|
CheSema
approved these changes
Mar 4, 2024
alexey-milovidov
deleted the
fix-buffer-overflow-in-compression-codec-multiple
branch
March 4, 2024 15:57
This was referenced Mar 4, 2024
robot-clickhouse
added a commit
that referenced
this pull request
Mar 4, 2024
This was referenced Mar 4, 2024
robot-clickhouse
added a commit
that referenced
this pull request
Mar 4, 2024
This was referenced Mar 4, 2024
robot-clickhouse
added a commit
that referenced
this pull request
Mar 4, 2024
alexey-milovidov
added a commit
that referenced
this pull request
Mar 4, 2024
Backport #60731 to 23.12: Fix buffer overflow in CompressionCodecMultiple
alexey-milovidov
added a commit
that referenced
this pull request
Mar 4, 2024
Backport #60731 to 24.2: Fix buffer overflow in CompressionCodecMultiple
alexey-milovidov
added a commit
that referenced
this pull request
Mar 4, 2024
Backport #60731 to 24.1: Fix buffer overflow in CompressionCodecMultiple
robot-clickhouse
added a commit
that referenced
this pull request
Mar 6, 2024
robot-clickhouse
added a commit
that referenced
this pull request
Mar 6, 2024
alexey-milovidov
added a commit
that referenced
this pull request
Mar 10, 2024
Backport #60731 to 23.8: Fix buffer overflow in CompressionCodecMultiple
alexey-milovidov
added a commit
that referenced
this pull request
Mar 10, 2024
Backport #60731 to 23.3: Fix buffer overflow in CompressionCodecMultiple
pull Bot
pushed a commit
to Mattlk13/ClickHouse
that referenced
this pull request
Sep 1, 2026
CompressionCodecMultiple compounded each stage's reserved size in a UInt32
without checking for overflow. Every codec reserves at least its own input, so
a long enough chain wrapped the reserve below its own input; the destination
buffer was then sized from the wrapped number while the real payload kept
growing, and the copy at the end of doCompressData wrote past the end of it.
On master a plain INSERT into a Float32 column with 150 chained FPC codecs
kills the server with a SIGSEGV on a write to an unmapped address, and ASAN
reports a heap-buffer-overflow. No setting is needed to reach it: the chain is
accepted by CREATE TABLE without a warning.
Three checks are added, in the order they can fire:
- The codec count is stored in a single byte and read back from it when
decompressing, so a chain of more than 255 codecs is refused. Before this
the count truncated: a 256-codec chain wrote a part whose header claimed
zero codecs, so CREATE and INSERT succeeded and the part was committed
unreadable (CORRUPTED_DATA on every later SELECT).
- Each stage's reserve is compared against that stage's input. A codec never
reserves less than its input, so a smaller result means the UInt32
arithmetic wrapped, wherever inside the callee it happened.
- The total is capped so that getCompressedReserveSize, which adds
getHeaderSize() to it in UInt32, cannot wrap in turn.
A final check compares the bytes actually written against the reserved size.
That one is computed from each codec's real output rather than from a bound, so
it still holds if a bound is ever computed wrongly.
Chains between 105 and 134 FPC stages returned correct results before this
change and are now rejected. Past the wrap the reserved size is meaningless;
those chains avoided the overflow only because the payload had not yet caught
up with it, and a 120-stage chain already writes 294,937,560 bytes from 20 KB
of input.
The decompress path in this same file was hardened the same way in ClickHouse#60731.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Fix buffer overflow that can happen if the attacker asks the HTTP server to decompress data with a composition of codecs and size triggering numeric overflow. Fix buffer overflow that can happen inside codec NONE on wrong input data. This was submitted by TIANGONG research team through our Bug Bounty program.