Repository navigation
Clamp extreme compress block sizes to prevent allocator crash - #101159
PedroTadim merged 8 commits into
Conversation
MergeTree settings like max_compress_block_size, min_compress_block_size, marks_compress_block_size, and primary_key_compress_block_size flow directly to buffer allocation constructors (CompressedWriteBuffer, WriteBufferFromFile) without size validation. When the AST fuzzer mutates these to values near INT64_MAX via CREATE TABLE SETTINGS, adding SIMD padding (~63 bytes) overflows past the allocator's checkSize() limit of 2^63, causing a LOGICAL_ERROR abort (server crash). Fix: clamp all compress block size settings to 256 MiB (matching the limit in PR ClickHouse#100298 for estimateCompressionRatio) in the MergeTreeWriterSettings constructor and the column-level override in MergeTreeDataPartWriterWide. Affected crash variants: STID 0883-4864, 0883-4856, 0883-5a5b, 0883-2066, 0883-22d2, 0883-45dc (24 hits in 30 days, 3 on master). The estimateCompressionRatio variant (0883-248c) was separately fixed by PR ClickHouse#100298. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Pre-PR Validation Gate (Session: cron:clickhouse-ci-task-worker:20260330-031500)a) Deterministic repro? ✅ CREATE TABLE t (x UInt64) ENGINE = MergeTree() ORDER BY x SETTINGS max_compress_block_size = 9223372036854775807;
INSERT INTO t SELECT number FROM numbers(100);
-- Crashes every time with: Logical error: 'Too large size (9223372036854775870) passed to allocator.'b) Root cause explained? ✅ c) Fix matches root cause? ✅ d) Test intent preserved / New test added? ✅ e) Both directions demonstrated? ✅
|
|
cc @CurtizJ @alesapin — could you review this? It clamps MergeTree compress block size settings (max/min_compress_block_size, marks_compress_block_size, primary_key_compress_block_size) to 256 MiB in MergeTreeWriterSettings to prevent server crash when the AST fuzzer sets these to INT64_MAX via CREATE TABLE SETTINGS. |
|
Workflow [PR], commit [b77e15d] Summary: ⏳
AI ReviewSummaryThis PR clamps extreme Missing context
ClickHouse Rules
Final Verdict
|
|
@groeneai it does not build: Build (arm_fuzzers) failure |
|
@alexey-milovidov thanks for reviewing — none of these failures are caused by this PR: Build (arm_fuzzers): Linker crash (Bus error / OOM at ~30GB RSS) during final linking of 03668_shard_join_in_reverse_order: Known pre-existing flaky test, tracked in #100870. test_overcommit_tracker/test_user_overcommit: Chronic flaky — 127 failures across 102 distinct PRs in the last 30 days. Could this get a CI retry for the arm_fuzzers build, or would the existing results be sufficient for merge? |
MergeTree settings like max_compress_block_size, min_compress_block_size, marks_compress_block_size, and primary_key_compress_block_size flow directly to buffer allocation constructors (CompressedWriteBuffer, WriteBufferFromFile) without size validation. When the AST fuzzer mutates these to values near INT64_MAX via CREATE TABLE SETTINGS, adding SIMD padding (~63 bytes) overflows past the allocator's checkSize() limit of 2^63, causing a LOGICAL_ERROR abort (server crash). Fix: clamp all compress block size settings to 256 MiB (matching the limit in PR ClickHouse#100298 for estimateCompressionRatio) in the MergeTreeWriterSettings constructor and the column-level override in MergeTreeDataPartWriterWide. Affected crash variants: STID 0883-4864, 0883-4856, 0883-5a5b, 0883-2066, 0883-22d2, 0883-45dc (24 hits in 30 days, 3 on master). The estimateCompressionRatio variant (0883-248c) was separately fixed by PR ClickHouse#100298. Co-Authored-By: Claude Opus 4.6 <[email protected]>
85b6510 to
a937442
Compare
…ub.com/groeneai/ClickHouse into fix/clamp-extreme-compress-block-sizes
|
The test |
|
The MSan stress test failure (MemorySanitizer: use-of-uninitialized-value, STID 4179-5154 or 4148-3044) is a known pre-existing issue unrelated to this PR. Fix: #102158 |
Cover the clamp in MergeTreeDataPartWriterWide::addStreams with a regression test using column-level SETTINGS (max_compress_block_size = INT64_MAX) on wide parts. Verified crash without fix (core dump on unpatched binary) and pass with fix (CI). Co-Authored-By: Claude Opus 4.6 <[email protected]>
LLVM Coverage Report
Changed lines: 100.00% (20/20) · Uncovered code |
|
@alexey-milovidov sorry for the delayed response on the And thanks for flagging the MSan issue as pre-existing (#102158). CI on the latest commit ( Should be ready to merge whenever convenient. |
|
@alexey-milovidov — friendly ping to expedite merge. This PR has been approved since 2026-03-30 (44 days). Meanwhile the bug continues hitting master: Master hits in last 7 days (STID 0883-4856 — exactly what this PR fixes):
You also re-acknowledged the issue today on #100399 ( PR state recap:
If you'd like a CI refresh first, I can push an empty commit to retrigger. Otherwise — could you merge it through? Happy to address anything I missed. Session: cron:clickhouse-ci-task-worker:20260513-024500 |
|
@groeneai can you make a separate PR to fix 04039_merge_tree_snapshot_teardown_race test? |
2dd6d57
Changelog category (leave one):
Changelog entry (a user-readable short description of the change):
Clamp MergeTree compress block size settings (max_compress_block_size, min_compress_block_size, marks_compress_block_size, primary_key_compress_block_size) to 256 MiB to prevent server crash when extreme values are set via CREATE TABLE SETTINGS.
What this PR does
MergeTree settings like
max_compress_block_sizeflow directly to buffer allocation constructors (CompressedWriteBuffer,WriteBufferFromFile) without any upper-bound validation. When the AST fuzzer mutates these settings to values nearINT64_MAXinCREATE TABLE SETTINGS, the buffer allocation adds ~63 bytes of SIMD padding, overflowing past the allocator'scheckSize()limit of 2^63, causing aLOGICAL_ERRORabort (server crash).Crash variants fixed: STID 0883-4864, 0883-4856, 0883-5a5b, 0883-2066, 0883-22d2, 0883-45dc — 24 hits across 3 master runs + 21 unrelated PRs in the last 30 days.
Note: The
estimateCompressionRatiovariant (STID 0883-248c) was separately fixed by #100298.Changes
MergeTreeIOSettings.h: AddMAX_COMPRESS_BLOCK_SIZE = 256 MiBconstant toMergeTreeWriterSettingsMergeTreeIOSettings.cpp: Clampmin_compress_block_size,max_compress_block_size,marks_compress_block_size, andprimary_key_compress_block_sizeto the limit in the constructorMergeTreeDataPartWriterWide.cpp: Clamp the column-levelmax_compress_block_sizeoverride04070_no_crash_extreme_compress_block_size— regression test covering all five affected code paths (wide parts, compact parts, primary key index, marks, min compress)Root cause
CREATE TABLE t (x UInt64) ENGINE = MergeTree() ORDER BY x SETTINGS max_compress_block_size = 9223372036854775807— accepted without validationINSERT INTO t SELECT ...triggers part writingMergeTreeWriterStreampassesmax_compress_block_size(= INT64_MAX) asbuf_sizetoWriteBufferFromFileBufferWithOwnMemoryadds 63 bytes of SIMD padding:9223372036854775807 + 63 = 9223372036854775870Allocator::checkSize()rejects values ≥ 2^63 →LOGICAL_ERRORabortReproduction
Before fix:
After fix: INSERT completes successfully (block size silently clamped to 256 MiB).
Version info
26.5.1.595