Repository navigation
Fix allocator abort in validateColumnOfFixedSize for huge index_granularity - #108650
Conversation
…larity
The debug-only writer validator MergeTreeDataPartWriterWide::validateColumnOfFixedSize
re-reads each granule via deserializeBinaryBulk, passing the per-mark granularity as the
row count. For a non-adaptive part (index_granularity_bytes = 0) created with an absurd
index_granularity (the setting is only rejected when < 1, so a value near the unsigned
64-bit range is accepted), that count is the huge granularity. deserializeBinaryBulk
eagerly resizes the column to it, tripping the allocator overflow guard
("Too large size passed to allocator") and aborting the server in debug builds, long
before reaching EOF.
Found by the AST fuzzer (STID 1367-1ab3) across several unrelated PR runs, always with
the same value 9223372036854775933 (2^63 + 125), e.g.
CREATE TABLE t (x UInt8) ENGINE = MergeTree ORDER BY tuple()
SETTINGS index_granularity_bytes = 0, index_granularity = 9223372036854775933;
INSERT INTO t SELECT number FROM numbers(100000);
Read the column in bounded batches (grow on demand) instead of resizing to the untrusted
count up front. The column ends up holding only the rows actually present, which the
existing column->size() != index_granularity_rows check still uses to detect a real
mark/data mismatch, so the validator's behavior is unchanged for valid parts.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-3:20260626-191500 |
|
cc @CurtizJ @alesapin — could you review this? The debug-only |
|
Workflow [PR], commit [ee26965] Summary: ✅
AI ReviewSummaryThis PR changes the debug-only wide-part validator to read fixed-size columns in bounded batches instead of passing the raw mark granularity straight into Final Verdict✅ Approve LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 1/22 (4.55%) · Uncovered code |
CI finish ledger - 1ee4ef4CI fully finished (Finish Workflow and Mergeable Check passed; no checks queued or in progress; >20 min since the last check completed). Every failure below has an owner.
Session id: cron:our-pr-ci-monitor:20260627-003000 |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 1/22 (4.55%) | Lost baseline coverage: none · Uncovered code |
CI finish ledger — a1568e1CI fully finished (Finish Workflow pass). The reds are an infra env-setup error and the chronic hung-check family, none PR-caused.
Session id: cron:our-pr-ci-monitor:20260703-053000 |
CI finish ledger — a1568e1CI fully finished on this head (Finish Workflow completed 2026-06-29T02:18:06Z, 0 checks queued/in_progress). Every failure has an owner.
This PR ( Session id: cron:our-pr-ci-monitor:20260704-170000 |
|
Correction to the ledger above: the
Session id: cron:our-pr-ci-monitor:20260704-170000 |
|
Status update (drive-to-merge, per the request on #110144):
Mergeable and ready. |
|
Dear @azat, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
…size-granularity-overflow
The .sql regression test carried a 10-line preamble naming C++ internals (MergeTreeDataPartWriterWide::validateColumnOfFixedSize, deserializeBinaryBulk) and the fuzzer STID. A test comment should say what the statement asserts; the class and function that were broken belong here in the commit message. Context that used to sit in the test: a non-adaptive MergeTree (index_granularity_bytes = 0) created with an index_granularity near the unsigned 64-bit range (the setting is only rejected when < 1) aborted the server in debug builds with "Too large size (...) passed to allocator". The debug-only validator re-read each granule using the per-mark granularity as the row count, which for such a table is that huge index_granularity, so the column was resized to ~2^63 elements before reaching EOF. Also dropped the helper's first comment line, which restated its signature.
The test could pass with the fix reverted. finishDataSerialization only
validates a column whose kind stack is exactly {DEFAULT}, and the test runner
randomizes ratio_of_defaults_for_sparse_serialization down to 0. The inserted
UInt8 data contains 391 default values, so the column could be written sparse,
the validator was skipped, and the check became vacuous. Measured on a pre-fix
binary: with the ratio forced to 0 the query returns normally, with the ratio
pinned to 1 it aborts as expected. Pin the setting.
Also add a granule larger than the read batch (2000000 rows against a
1048576-row batch). The first case only ever needs one bounded read, so an
implementation that stopped after a single batch would still pass it while
rejecting valid marks that span several batches.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units7 translation units recompiled, 13 s compile time in total, 7 of them have a recent master baseline. |
CI finish ledger - db03a99Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
Details, since the shape of this one is easy to misread:
The rest of the matrix is green: 172 unique jobs, Session id: cron:our-pr-ci-monitor:20260820-030000 |
|
Fixing PR for the ledger line above ( It adds |
alexey-milovidov
left a comment
There was a problem hiding this comment.
A little bit excessive, but LGTM.
…size-granularity-overflow Earlier criss-cross merges on the branch had mangled unrelated files, so all conflicts outside the PR's own files were resolved by taking master's version; the resulting tree differs from master by exactly the intended fix in `MergeTreeDataPartWriterWide.cpp` plus the regression test 04412.
The merge-conflict resolution accidentally kept the branch's stale submodule pointer; this PR does not intend to change any submodule.
|
@groeneai @alexey-milovidov — ClickGap found the following in this PR:
Close anything that's wrong or already addressed. |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a server abort (
Too large size passed to allocator) in debug builds when writing a non-adaptive MergeTree part (index_granularity_bytes = 0) created with an extremely largeindex_granularity.Description
The debug-only writer validator
MergeTreeDataPartWriterWide::validateColumnOfFixedSizere-reads each granule viadeserializeBinaryBulk, passing the per-mark granularity as the row count to read. For a non-adaptive part (index_granularity_bytes = 0) the per-mark granularity is theindex_granularitysetting itself, which is only rejected when< 1, so a value near the unsigned 64-bit range is accepted.deserializeBinaryBulkeagerly resizes the column to that count before reading, which trips the allocator overflow guard (Too large size (...) passed to allocator) and aborts the server in debug builds, long before reaching EOF.Found by the AST fuzzer (STID
1367-1ab3) onAST fuzzer (amd_debug, targeted, old_compatibility), reproduced across several unrelated PR runs, always with the same value9223372036854775933(2^63 + 125):Stack (key frames):
Minimal deterministic reproducer (debug build):
Fix: read the column in bounded batches (grow on demand) instead of resizing to the untrusted count up front. The column ends up holding only the rows actually present, which the existing
column->size() != index_granularity_rowscheck still uses to detect a real mark/data mismatch, so the validator's behavior is unchanged for valid parts. Regression test added in04412_validate_fixed_size_column_huge_granularity.No related open issue found (the previous validator fix for non-adaptive parts was #103538, issue #98585, a distinct mismatch).
Workflow [PR]
Sync PR [sync-upstream/pr/108650]