Repository navigation
Validate a verbatim codec's declared size in the passthrough read shortcut - #114344
Conversation
The compressed frame header carries two independent 32-bit size fields. size_compressed is bounded at DBMS_MAX_COMPRESSED_SIZE in both header parsers; size_decompressed is bounded nowhere, although it is the field that directly sizes output buffers. ICompressionCodec::readDecompressedBlockSize validates only that it is non-zero, and CompressedReadBuffer::nextImpl and readBig call memory.resize with it, so a header can ask for a reservation of up to 4 GiB for a frame that will fail to decode. validateChecksum does not gate this. It is an unkeyed CityHash128 over the frame body, compared against 16 bytes the same peer supplied, so a peer that crafts a header also computes its checksum. The path is therefore reachable at default settings over HTTP decompress=1. The impact stays low: the reservation is virtual, decompression fails immediately afterwards, and max_server_memory_usage caps it when configured. Bounding the reader alone would reject frames that current ClickHouse writes, because max_compress_block_size and clickhouse compressor --block-size are unclamped and Log, StripeLog and the backup temp path pass them straight to a compressed write buffer. So the writers are capped first: a frame's size_decompressed is offset(), which cannot exceed buffer capacity, and capacity comes from exactly two places in CompressedWriteBuffer (the initial allocation and adaptive_buffer_max_size) plus one in ParallelCompressedWriteBuffer. Capping all three is codec-independent, which is why no codec reserve computation is involved. With that invariant in place the reader bound is unconditional and on by default. Data written before the cap existed can still hold a larger frame, so the readers of such data opt out explicitly. Each site was traced to the writer that produces its bytes and opted out only where that writer's buf_size is unclamped; readers whose writers are a fixed size stay bounded, including checksums.txt at 64 KiB and statistics at 1 MiB. The opt-out in checkDataPart is per file rather than per site, because its lambda serves every compressed checksum entry including statistics. The direction of failure is what makes a short list the safe choice here. After the writer cap, a site missing from the list throws TOO_LARGE_SIZE_COMPRESSED on a legacy read, which is loud and one line to fix, while an over-broad entry silently leaves a path unbounded. The list is therefore deliberately minimal. A codec that stores its body verbatim also gains a header-time consistency check: the body length is the decompressed length, and the caller sizes its output buffer from size_decompressed before decompressing, so the two must agree. isNone() is overridden only by CompressionCodecNone and CompressionCodecQuantized, both of which already enforce that equality inside doDecompressData, so no legitimate writer is rejected. The boundary is inclusive, matching the sibling bound: exactly 0x40000000 is accepted and only a strictly larger value is rejected. The Native format spec documents both bounds, the inclusive boundary, and the legacy-data edge, since it previously stated neither limit. Co-Authored-By: Claude Fable 5 <[email protected]>
… reads Two defects in the previous commit, both found in review. Capacity at the bound is not enough. The two header fields come from different quantities: compress() serializes 9 + doCompressData(), and a codec may expand rather than shrink. NONE returns source_size unchanged, so a full-capacity frame serialized size_compressed = 1073741833, which the bounded reader then rejected; LZ4 on incompressible input is the same class. Both are reachable through clickhouse compressor and through Log with CODEC(NONE). The change advertised that a current writer never emits a frame a current reader rejects, so this had to hold rather than be documented away. capUncompressedFrameSize measures the codec's overhead at the bound and subtracts it, in closed form, with one getCompressedReserveSize call and no search, rounded down to a 32-byte multiple so a codec that rejects a partial element is never handed one. A codec can also answer nothing usable: a chain deep enough to overflow its own UInt32 reserve arithmetic returns a value below the frame it describes, and some codecs refuse the size outright. Neither answer is a bound, so neither is reduced by, and the request passes through unchanged. Treating those as infeasible instead was measurably wrong: a 40-deep FPC chain wraps its Multiple reserve to 9082261, and clamping on that produced 262144 frames where master produces 1. With the pass-through the same input is byte-identical to master, as are all ordinary buffer sizes. Since the cap now depends on the codec, the null codec is resolved before the base class initializer consumes buf_size, and setCodec re-caps both capacity sources. offset() is zero there, so nothing is dropped. No production caller switches from a looser codec to a tighter one, so that part is an invariant for future callers rather than a fix for a live path. Second, checkDataPart decided from the file name, and no name test can express what it needs. Secondary and text index substreams are .idx and .idx2, are written with max_compress_block_size, and are read through a stream that opts out, but they match neither .bin nor a mark nor .cidx. CHECK TABLE therefore reported a pre-cap part with a large skip index as broken while SELECT read it happily, and a spuriously broken part can be detached. The index extension is versioned as well, so a literal list would rot. The decision now comes from the three call sites, which already know the provenance. That leaves isCompressedFromFileName without an external caller, so it returns to its anonymous namespace and IMergeTreeDataPart.h is untouched. The spec said a Multiple codec bounds its nested frames inclusively; it bounds them exclusively. Corrected in the spec, not in the codec. The engine arm of the test carried a session-level max_compress_block_size that Log and StripeLog capture in their constructors, so it never applied; removed, and the arm now says in the test that it is a no-regression control and which arms carry the opt-out coverage. Co-Authored-By: Claude Fable 5 <[email protected]>
… invariant, bound 04848's cost
Three review findings, no blockers. No codec is touched: the diff against the base
adds nothing to src/Compression/CompressionCodec*.{cpp,h}.
1. CHECK TABLE opted statistics out while their readers stayed bounded.
Round 1 moved the bounded/unbounded decision from file names to the call sites, which
closed the asymmetry for skip-index files and opened it for one class in the other
direction. Statistics are written with a hardcoded 1 MiB frame
(StatisticsSerialization.cpp:33 packed, :69 wide) and carry is_compressed = true, and
they are absent from getFileNamesWithoutChecksums(), so they reach the directory pass
and received allow_unbounded_decompressed_size = true, while their readers
(IMergeTreeDataPart.cpp:1265, :1305) are deliberately bounded. A corrupt statistics
header up to 4 GiB was therefore rejected by a SELECT and accepted by CHECK TABLE,
which also reserves that much while hashing it.
The directory pass now classifies the statistics name and passes false for it. The
.bin call sites and the ends_with(".bin") fallback stay unbounded. That pass walks
whatever is on disk, so it has no per-class caller to take the decision from; an
unclassified name is left unbounded, since that only forgoes hardening there while the
opposite mistake reports a good legacy part as broken.
Measured on two binaries differing only in this predicate, each against a fresh copy
of the same fixture (countmin statistics, statistics_v.stats with
size_decompressed = 155606, on a build whose reader bound is lowered to 64 KiB so the
1 MiB writer frame is genuinely over-bound): before, a statistics-loading SELECT
throws Code: 39 while CHECK TABLE returns 1; after, both reject the frame.
2. The docs and changelog claimed a writer invariant the cap does not deliver.
capUncompressedFrameSize reduces a frame by the worst-case expansion the codec
reports, so a codec computing that figure in wrapping UInt32 arithmetic understates it
and the request passes through unreduced. For Gorilla(1) at 2^30,
items_count * max_item_size_bits is 17 * 2^30, which wraps to exactly 1073741824, so
the reported reserve is 134217746 and no reduction happens; a deep Multiple chain
takes the other fallback. Closing that would require 64-bit reserve arithmetic across
every codec, which is out of scope here, and the pre-existing size_compressed reader
bound already rejects such frames.
So the specification is narrowed rather than the arithmetic changed: the format spec,
the changelog entry, the description and the comment in capUncompressedFrameSize now
state that the cap is only as good as the codec's own reserve figure and that the
reader bound is the backstop. Frame sizes at ordinary block sizes remain byte-identical
to master for Gorilla, Gorilla(1), NONE and the default codec.
3. 04848 carried multi-GiB cost with no tag protecting any lane.
Tagged long with a "Memory limits: 10 GiB" header, both of which the harness parses.
Each large output is removed once its last assertion is done, and the incompressible
input is regenerated from a key instead of being kept on disk, so the two 1 GiB files
no longer coexist. Sampled through a full run, the disk peak drops from 3.01 GiB with
three large files alive to 1.00 GiB with one, and no arm's assertion was weakened.
Note that long also scales flaky-check repetitions by --long-test-runs-ratio
(default 0.1), so reproducing a 50-run sweep on this test needs that flag set to 1.
Verification: 04848 passes 50/50 randomized. A 270-test sweep over compression,
codecs, statistics, CHECK TABLE and log engines was run on this build and on a
pristine master snapshot with the same harness invocation and config: 32 failing
versus 33, and the symmetric difference is exactly one test, 04848, which fails on
master and passes here. Zero failures are unique to this build.
…e reader bound's ordering Round 3 is prose plus one test arm. No behaviour change, no codec touched. The writer cap can only subtract the worst-case expansion a codec reports, so it leaves the frame unreduced in two cases, not one. The first was already documented: a reserve computed in wrapping 32-bit arithmetic understates itself (Gorilla). The second was not: a reserve that is arithmetically honest but too large for the limit to absorb returns the request unreduced at ICompressionCodec.cpp:118-120. A 6x FPC chain reports 2176782471 for a 1 GiB request, which is below 2^32, so it is not a wrap. The spec, the changelog entry and the PR description all claimed that a codec reporting its expansion correctly never emits a frame a reader rejects; that is false for exactly this codec. All three now state what the code delivers and name the reader's own bound as the backstop in both cases. capUncompressedFrameSize returns zero for a zero request: the reserve is tiny, so the reserve <= limit branch returns the request unchanged. The header comment claimed it never returns zero. It now states the guarantee that does hold, that a nonzero request is never reduced to zero. Master already produced an empty working buffer for --block-size 0, so nothing here regresses and no clamp is added. CompressionCodecMultiple bounds the intermediate buffer length it tracks itself and each nested header's declared uncompressed_size. It never reads a nested declared compressed_size, and neither does anything else: readCompressedBlockSize has one caller in the tree, the outer parser. The spec said both nested fields were bounded. 04848 asserted only the exception text for the 2 GiB arm, which survives moving the bound after the header-size check, so it did not discriminate the ordering its label claimed. The frame helper takes an optional size_compressed override, leaving every existing arm's bytes identical, and a new 30-byte arm declares a size_compressed below the header size as well: reporting the size_decompressed message pins that the bound is reached first, hence inside the header parser and before any allocation. Moving the bound below that check reddens this arm and nothing else. Also stop discarding openssl's stderr in the incompressible-input helper, so a refusal is diagnosable rather than an empty pipe.
… statistics parser reject malformed output Round 4 is one comment, one test-helper hardening, one table setting and one 30-byte arm. No behaviour change, no codec touched. capUncompressedFrameSize can only subtract the worst-case expansion a codec reports, so it leaves a request unreduced when that expansion exceeds what the limit can absorb: a 6x FPC chain reports 2176782471 for a 1 GiB request, which is arithmetically honest rather than a wrap, and Gorilla passes through at widths 1, 2, 4 and 8. Of 24 codec and chain cases, 19 reduce and 5 pass through. Round 3 corrected the changelog, the spec and the second half of this header comment, but the first sentence still promised unconditionally that a full frame serializes both size fields within the limit, which is the sentence a caller would rely on. It now states the best-effort contract and names the reader's own bound as the backstop. CompressedReadBufferBase.h is untouched: its subject is size_decompressed, which min(buf_size, limit) caps on every path. The over_bound helper in 04848 merged stderr into its parser and special-cased one error code. Any other diagnostic fell through to the counting rule, where empty size fields compare as zero, so a failed read printed the same line as a clean one: feeding it a file that is not a compressed frame reported zero over-bound frames. Those four arms are the only oracle for the writer cap, so a cap regression that also malformed the output would have passed. The parser now counts a row only when it has three fields and both sizes are all-digits, and reports anything else. compressor --stat emits exactly those three fields per frame. packed_skip_index_max_bytes defaults to 1 MiB and the test runner randomizes it over five values, four of which bundle a minmax index over 1000 rows into skp_idx.packed. A packed substream carries no per-file checksum entry, so checkDataPart never visits it, and the CHECK TABLE arm reached the file class its comment claimed in one draw of five. The table now pins the setting to zero, the same mechanism the test already uses for compress_marks and min_bytes_for_wide_part, and the part carries a standalone skp_idx_idx_s.idx2. The verbatim-body check dispatches on isNone(), which Quantized overrides as well as None, and the spec paragraph names both codecs. The read path builds Quantized from its method byte alone, with no arguments and no experimental gate, so a new arm covers 0x9e for 30 bytes. Restricting the check to the None method byte reddens that arm and nothing else.
Internal second-model review (5 rounds, adjudicated)An independent model reviewed this change cold at each round. Verdicts below; every accepted Fixed in earlier rounds (round 4 closed the last four):
Not accepted: ❌ Nested Noted, not blocking: 💡 One imprecision follows from the above: the specification says a verbatim-body mismatch is 💡 💡 The new verbatim check turns a previously silent outcome loud. The Session id: cron:clickhouse-review-slot-10:20260811-133900 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-6:20260811-042900 |
|
cc @rschu1ze @alexey-milovidov, could you review this? The reader now rejects a |
|
@groeneai Lots of code is added while the PR description is an unreadable word soup. Please phrase in plain and simple English: What problem are you trying to solve? |
|
Rewritten, thanks. The problem in one sentence: a compressed block header declares an uncompressed size that nothing validates, and the reader allocates exactly that many bytes before decoding, so a peer sending a header that claims 4 GiB makes the reader ask for 4 GiB. The compressed size next to it has been bounded at 1 GiB all along; this gives its sibling the same bound. On the volume of code: the writer side is what makes it more than one |
|
Workflow [PR], commit [fe598b2] Summary: ✅
AI ReviewSummaryThis PR adds the missing body-length vs. Final Verdict
LLVM Coverage ReportMeasured on commit fe598b2.
Changed lines: Changed C/C++ lines covered: 6/8 (75.00%) · Uncovered code |
CI finish ledger - beebbd6Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
None of these is PR-caused. I checked the amd_tsan job specifically, because this PR does touch the #114326 is merged but not in this build, so a re-run picks it up. Verified from the run itself
#113397's fix is genuinely absent from this build, so that red is not evidence against it: Gates: (a) 175 check-runs, 0 incomplete non-exempt; (b) Session id: cron:our-pr-ci-monitor:20260812-063000 |
…ess hung check
CI finish ledger - 59805faCI is fully finished on this head and there are no failures to own. 176 checks: 157 success, 19 skipped, 0 failure. Session id: cron:our-pr-ci-monitor:20260812-120000 |
|
Understood, holding the review. #114189 is still open (mergeable state |
|
Confirmed, and thanks for the correction: the dependency is #113877, not #114189. I will ping you here once #113877 merges. Status there: #113877 is still open with @ rschu1ze's changes requested from 2026-08-10, and PedroTadim asked him on 2026-08-14 to continue the review, so nothing is pending from me on it. #114189 shares no files with this branch, so its approval today does not change anything here. |
…er helpers Master moved `use_adaptive_buffer_size` and `adaptive_buffer_max_size` into `BufferWithOwnMemory` behind `adaptiveBufferInitialSize` and `enableAdaptiveBufferGrowth`. Both bounds are now capped with `capBufferSize(codec, buf_size)` through those helpers, which keeps this fix's guarantee that neither the initial allocation nor the growth ceiling can exceed what the codec can describe in a frame header. `resolveCodec` in the initializer list subsumes master's null-codec check in the body. The translation unit was syntax-checked after the resolution. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 6 s compile time in total, 7 of them have a recent master baseline. |
|
The |
|
@groeneai refresh this PR. |
| ### Size limits {#frame-size-limits} | ||
|
|
||
| Both size fields are 32-bit on the wire, but each is capped at `0x40000000` (1 GiB) **inclusive**: exactly `0x40000000` is accepted and only a strictly larger value is rejected. A decoder checks both from the header alone, before allocating any buffer sized from either field, and fails with `TOO_LARGE_SIZE_COMPRESSED`. A `Multiple` codec applies the same constant to its nested frames, but exclusively (exactly `0x40000000` is rejected) and to two quantities only: the length of the intermediate buffer it tracks itself, and each nested header's declared `uncompressed_size`. A nested header's declared `compressed_size` is not inspected, because each nested decoder is handed the length the outer decoder tracks rather than one read off the nested header. | ||
|
|
||
| The checksum does not gate these checks. It is an unkeyed CityHash128 over bytes the sender chose, so it detects corruption in transit but not a crafted header, and a decoder that sized a buffer from `uncompressed_size` before checking it would honour whatever the sender declared. | ||
|
|
||
| A limit is not a validation, so for a method byte whose codec stores the body verbatim (`NONE`, `Quantized`) the two fields are checked against each other as well: they describe the same bytes, so `compressed_size - 9` must equal `uncompressed_size`, and a frame where they disagree is rejected. The same rule applies to a nested frame, where the body length is the length the outer decoder tracks for it rather than a field of the nested header, and the comparison runs before the buffer sized from `uncompressed_size` is allocated. | ||
|
|
||
| All of these checks belong to the decoder. Beyond them the format does not constrain the sizes a writer puts in a header. | ||
|
|
There was a problem hiding this comment.
No need to alter NativeFormat.mdx. These boundary checks are not worth mentioning there
There was a problem hiding this comment.
Reverted, the page is untouched now.
| /// A codec that stores data verbatim has body length equal to the decompressed length. | ||
| if (codec->isNone() && source_size - COMPRESSED_BLOCK_HEADER_SIZE != uncompressed_size) | ||
| throw Exception(decompression_error_code, | ||
| "The compressed data size without header ({}) does not match size_decompressed ({}) " | ||
| "for a codec that stores data uncompressed", | ||
| source_size - COMPRESSED_BLOCK_HEADER_SIZE, uncompressed_size); | ||
|
|
There was a problem hiding this comment.
This we already check in CompressionCodecNone, which is reached from here as we later call codec→decompress. Remove
There was a problem hiding this comment.
Removed. Checked it first: CompressionCodecMultiple.cpp:176 hands the nested frame to codec->decompress, which reaches CompressionCodecNone.cpp:33 (or CompressionCodecQuantized.cpp:55), and that rejects the mismatch, so the guard was redundant for correctness.
One consequence worth having on the record: uncompressed_buf is resized from the nested declaration at :173, before that call. A nested verbatim frame declaring just under 1 GiB behind a few bytes therefore still allocates and is refused afterwards. It is bounded by the >= 1_GiB guard at :161 and identical to master, so I left it alone.
| "the compressed data size ({}, this should include header size) is less than the header size ({})", | ||
| size_compressed_without_checksum, static_cast<size_t>(header_size)); | ||
|
|
||
| /// A codec that stores data verbatim has body length equal to the decompressed length. |
There was a problem hiding this comment.
Comment is obvious, remove. Remember forever that obvious comments shall not be written
There was a problem hiding this comment.
Removed, along with the check it sat on. Noted for future PRs.
| if (codec->isNone() && size_compressed_without_checksum - header_size != size_decompressed) | ||
| throw Exception(external_data ? ErrorCodes::CANNOT_DECOMPRESS : ErrorCodes::CORRUPTED_DATA, "Can't decompress data: " | ||
| "the compressed data size without header ({}) does not match size_decompressed ({}) " | ||
| "for a codec that stores data uncompressed", | ||
| size_compressed_without_checksum - header_size, size_decompressed); |
There was a problem hiding this comment.
The check is only missing in the isNone() shortcut in CompressedReadBufferBase::decompress, which re-points the output buffer at the body and never calls the codec. So the natural home is inside that shortcut
There was a problem hiding this comment.
Moved there in a17ae9d, and the copy in readHeaderAndGetCodecAndSize is gone. You are right that the shortcut is the only gap: both verbatim codecs check the relationship in their own doDecompressData, and ICompressionCodec::decompress:124 routes every other path through them, so the version I had was duplicating that check on the two paths that do call the codec.
Same ordering note as on the nested guard: CompressedReadBuffer::nextImpl:19 sizes memory from the declared value before decompress runs, so the allocation still precedes the rejection. That is unchanged from master, where the shortcut has no relationship check at all and the frame is accepted as well.
The nested test arms went with the nested guard; 03003_codec_multiple_buffer_overflow is back to its original expectation. The remaining arms in 04848 pin the shortcut in both mismatch directions and for both verbatim codecs, and with the check reverted they are the only lines that change. Title and description updated to match the reduced scope.
Both verbatim codecs already reject a body whose length contradicts the declared uncompressed size, in CompressionCodecNone::doDecompressData and CompressionCodecQuantized::doDecompressData. Every read path reaches one of them through codec->decompress except the isNone() shortcut in CompressedReadBufferBase::decompress, which re-points the output buffer at the body and never calls the codec, so that is the only place the check was missing and the only place it is now added. The two checks this branch previously carried elsewhere are removed: the one in readHeaderAndGetCodecAndSize duplicated the codec's own check on the two paths that do call it, and the one in CompressionCodecMultiple::doDecompressData duplicated it for a nested frame, which reaches the nested codec through codec->decompress. Their only remaining effect was to reject before the buffer sized from the declaration is allocated; that allocation is bounded at 1 GiB by DBMS_MAX_DECOMPRESSED_SIZE and by the Multiple codec's own 1 GiB guard, and it is unchanged from master either way. The NativeFormat.mdx section is dropped, and 03003_codec_multiple_buffer_overflow returns to its previous expectation now that its nested frame is refused by the codec again. 04848 keeps the arms that pin the shortcut, in both mismatch directions and for both verbatim codecs; with the check reverted those three arms are the only lines that change, and the nested arms went with the nested check. Co-Authored-By: Claude Opus 5 <[email protected]>
Multiple
CI finish ledger - a17ae9dEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only
157 pass, 18 skipping, 0 pending: no test leg failed on this head. Session id: cron:our-pr-ci-monitor:20260916-230116 |
| # No-regression control: the shortcut is the ordinary read path for compressed marks and for the Log | ||
| # family, so engines reading frames they wrote themselves have to keep working. |
There was a problem hiding this comment.
The test below doesn't reach the shortcut
There was a problem hiding this comment.
You are right, it did not. With a breakpoint on the new check, the old control entered it 0 times and entered the else branch that calls codec->decompress 22 times: the shortcut needs codec->isNone(), but marks_compression_codec and primary_key_compression_codec default to ZSTD(3) and the column data defaults to LZ4, so nothing that control read was a NONE frame.
Fixed in 85a2feb by storing the column, the marks and the primary key uncompressed, which takes the shortcut 13 times. StripeLog is gone from the control: StorageStripeLog.cpp:207 builds its single CompressedWriteBuffer with getDefaultCodec() and ignores the column codec, so it cannot reach the shortcut at all (measured 0 entries).
The control is also no longer vacuous. With the header subtraction dropped from the check, it now fails at CompressedReadBufferBase.cpp:314 on the first Log read, where the old control stayed green on the same binary.
The control created its tables with the default codec, so every read went through codec->decompress instead of the isNone() shortcut in CompressedReadBufferBase::decompress. Measured with a breakpoint on the new check: the control entered it 0 times and the else branch 22 times, and an off-by-header mutation of the check (comparing size_compressed_without_checksum itself rather than minus the header) left the control fully green. Store the column, the marks and the primary key uncompressed so the reads go through the shortcut, which makes the control fail on that same mutation. StripeLog is dropped from it because StorageStripeLog builds its single CompressedWriteBuffer with CompressionCodecFactory::getDefaultCodec() and ignores the column codec, so its reads can never reach the shortcut.
rienath
left a comment
There was a problem hiding this comment.
Very small nit, I don't see a reason to block this PR
| @@ -0,0 +1,86 @@ | |||
| #!/usr/bin/env bash | |||
| # Tags: no-fasttest | |||
There was a problem hiding this comment.
Nothing in it needed the tag, so I removed it in fe598b2.
It depends on python3, xxd, awk and clickhouse checksum-for-compressed-block. The Fast test image installs the first three (ci/docker/fasttest/Dockerfile:32,38,76), and programs/CMakeLists.txt:98,179 adds the subcommand unconditionally and links it into the binary, so ENABLE_LIBRARIES=0 does not drop it.
Verified rather than assumed: a server built with the cmake flags of ci/jobs/fast_test.py, its config installed by tests/config/install.sh --fast-test, and clickhouse-test --fast-tests-only run inside clickhouse/fasttest. With the tag it is skipped as "running fast tests only"; without it, 20 consecutive runs pass at about 0.55 sec each.
The test needs python3, xxd, awk and the clickhouse checksum-for-compressed-block subcommand. The Fast test image installs the first three, and programs/CMakeLists.txt adds the subcommand unconditionally, so ENABLE_LIBRARIES=0 does not drop it. Measured rather than argued: a server built with the cmake flags of ci/jobs/fast_test.py, its config installed by tests/config/install.sh --fast-test, and clickhouse-test run inside clickhouse/fasttest with --fast-tests-only. With the tag the test is skipped as "running fast tests only"; without it, 20 consecutive runs pass at about 0.55 seconds each.
…n the passthrough read shortcut
Backport #114344 to 26.9: Validate a verbatim codec's declared size in the passthrough read shortcut
Backport #114344 to 26.8: Validate a verbatim codec's declared size in the passthrough read shortcut
Backport #114344 to 26.7: Validate a verbatim codec's declared size in the passthrough read shortcut
…red size in the passthrough read shortcut
…red size in the passthrough read shortcut
Backport #114344 to 26.3: Validate a verbatim codec's declared size in the passthrough read shortcut
…red size in the passthrough read shortcut
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Reject a compressed block whose codec stores data verbatim (
NONE,Quantized) when its declared uncompressed size does not match the body length. Previously the passthrough read path accepted such a block while every other decompression path rejected itDescription
For a method byte whose codec stores the body verbatim, the declared uncompressed size and the body length describe the same bytes and must be equal.
CompressionCodecNone::doDecompressDataandCompressionCodecQuantized::doDecompressDataboth enforce that, and every read path reaches one of them throughcodec->decompress, with one exception: theisNone()shortcut inCompressedReadBufferBase::decompressre-points the output buffer at the body and never calls the codec. There the declared size was simply ignored, so a block that every other reader refuses was read as valid. The check now sits in that shortcut, which is the only place it was missing.Reachable at default settings on any transport that accepts a compressed block: the checksum is an unkeyed
CityHash128over bytes the sender chose, so a sender recomputes it for a header it crafted.Not changed here: a reader still sizes its buffer from the declared value before the shortcut runs, so a small block can still make it reserve up to the 1 GiB a header may declare, bounded by
DBMS_MAX_DECOMPRESSED_SIZEand, insideMultiple, by that codec's own 1 GiB guard. That ordering is the same as on master.03003_codec_multiple_buffer_overflowcarries a nested block of this shape and keeps its existing expectation, since the nested codec is what refuses it.Related: #117011
Workflow [PR]
Sync PR [sync-upstream/pr/114344]
Version info
26.10.1.499-master(included in26.10and later)26.9.2.32,26.8.11.40,26.7.14.39,26.3.33.156