Repository navigation
Fix arrayResize with a Decimal size - #107389
Conversation
…r cap `arrayResize` read its size argument via `IColumn::getInt`, which for a `Decimal` column returns the raw unscaled value rather than the logical one. As a result `arrayResize([1, 2, 3], 1.5::Decimal(2, 1))` resized to 15 elements instead of 1, inconsistently with `Float` and integer sizes (which truncate towards zero). A tiny fractional value such as `-0.000000000000000000000006116852::Decimal(38, 30)` has a raw value of `-6116852`, so the array was padded with millions of elements. Convert a `Decimal` size to a plain integer before resizing, so its real (rounded towards zero) value is used. This was found by `FunctionsStress.stress` (`function_prop_fuzzer`), where the above query made a worker pad ~6 million elements one by one and get reported as stuck. The existing `arrayResize` argument cap did not prevent it: it only bounds the value from above (`value > limit`), so a large-magnitude negative size slips through, and for a `Decimal` it compares the logical value while the function used the raw one. Make the cap bound the magnitude instead (`abs(value) > limit`) so large negative sizes are clamped too. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=107319&sha=2603a4dd53466ae560f080b1a55ed3009d28fa9e&name_0=PR&name_1=Unit%20tests%20%28asan_ubsan%2C%20function_prop_fuzzer%29 Related: #107319 Co-Authored-By: Claude Opus 4.8 <[email protected]>
753d2d0 to
ec12cb3
Compare
|
Workflow [PR], commit [b0af15f] Summary: ✅
AI ReviewSummaryThis PR fixes Final VerdictStatus: ✅ Approve |
|
@groeneai, link the fix of |
|
Found it: #105286 |
|
The failure on this PR ( #105286 is the narrow fix: it filters only Both are still open and unmerged, so the bug is live on master (most recent master hits 2026-06-11). #106621 is the one to merge. |
…pus) Extracted from the AST-fuzzer logs (fuzzer.log of the failing run): the targeted/ old_compatibility fuzzer seeded from 01552_impl_aggfunc_cloneresize.sql (test_bm / test_bm_join, groupBitmapState + bitmapOrCardinality) and the PR's arrayResize test, then mutated them into bitmap self-joins, arrayResize(..., N) with huge N over num_10k, and ~97 fuzzed MergeTree table variants being written and merged. The test recreates the exact seed tables and replays those exact query families concurrently with the fuzzer's per-query max_memory_usage = 10 GiB, in a large container with ClickHouse limits at their defaults and swap disabled. Measured: this drives the node's real memory.current to ~7.3 GiB against the 8 GiB cgroup - faithfully reproducing the fuzzer's load. It does not fire the kernel OOM in the docker-in- docker integration runner, because there real memory tracks the tracker limit (~7.2 GiB) and stays just under the cgroup: the MemoryWorker's dirty-page purge - which lost the race on the fuzzer's real VM under sustained chaotic load, letting RSS drift above tracked - wins it in the cleaner/faster container, and --cgroupns=host makes the server misread its cgroup (RSS read ~10 GiB) and over-throttle. The kill reproduces where per-container memory is accounted as on the fuzzer's VM. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=107389&sha=ec12cb3ce0a49a403226cb0668b092f02a2fa3f6&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%2C%20targeted%2C%20old_compatibility%29 Related: #107389 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The docker mem_limit used by the integration runner is not enforced as a hard memory.max in the docker-in-docker setup (--cgroupns=host), so a real kernel OOM never fires there - which is why the kill could not be reproduced via the test harness. This script instead creates a cgroup v2 itself (which the kernel does enforce), starts clickhouse-server inside it (so the server reads the cgroup and keeps its limits intact), and runs sustained concurrent groupArrayState merge/insert churn. The allocator retention gap (resident memory above the tracked limit) pushes resident memory past the cgroup and the kernel OOM killer fires - the same mechanism that killed the AST-fuzzer's server (tracked 48.9 GiB, resident 52-57 GiB). Verified: cgroup memory.events oom_kill increments and dmesg shows "Memory cgroup out of memory: Killed process ... (clickhouse), oom_memcg=/ch_merge_oom" (constraint=CONSTRAINT_MEMCG). Requires root + cgroup v2 + a built clickhouse binary. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=107389&sha=ec12cb3ce0a49a403226cb0668b092f02a2fa3f6&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%2C%20targeted%2C%20old_compatibility%29 Related: #107389 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 6/24 (25.00%) | Lost baseline coverage: none · Uncovered code |
|
CI triage ( SELECT plus(1048577, xor(...)), toUInt16OrNull(toFixedString(toString(number), NULL))
FROM system.numbers
GLOBAL ALL FULL OUTER JOIN system.numbers AS alias0 ON equals(number, alias0.number)
GLOBAL FULL OUTER JOIN system.numbers AS alias1 ON equals(number, alias1.number)
LEFT JOIN system.numbers AS alias2 ON ...
WHERE 257 LIMIT 65537with Re-ran the failed job; no re-merge (merge-base is from today). |
A background merge runs under its own memory tracker (a child of the "Background process (mutate/merge)" tracker), not under the tracker of the query that triggered it. Consequently the per-query `max_memory_usage` limit does not bound a merge: merging parts that hold large values consumes memory regardless of how small `max_memory_usage` is. This is the mechanism behind the AST-fuzzer OOM where sequential, individually-small fuzzer queries left behind parts that the background merge subsystem then combined, growing server memory across query boundaries until the kernel OOM-killer reaped the server. The test inserts two parts of large arrays, sets a tiny `max_memory_usage`, and shows via `system.part_log` that the merge completes and its `peak_memory_usage` is far above the per-query limit. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=107389&sha=ec12cb3ce0a49a403226cb0668b092f02a2fa3f6&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%2C%20targeted%2C%20old_compatibility%29 Related: ClickHouse#107389 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…pus) Extracted from the AST-fuzzer logs (fuzzer.log of the failing run): the targeted/ old_compatibility fuzzer seeded from 01552_impl_aggfunc_cloneresize.sql (test_bm / test_bm_join, groupBitmapState + bitmapOrCardinality) and the PR's arrayResize test, then mutated them into bitmap self-joins, arrayResize(..., N) with huge N over num_10k, and ~97 fuzzed MergeTree table variants being written and merged. The test recreates the exact seed tables and replays those exact query families concurrently with the fuzzer's per-query max_memory_usage = 10 GiB, in a large container with ClickHouse limits at their defaults and swap disabled. Measured: this drives the node's real memory.current to ~7.3 GiB against the 8 GiB cgroup - faithfully reproducing the fuzzer's load. It does not fire the kernel OOM in the docker-in- docker integration runner, because there real memory tracks the tracker limit (~7.2 GiB) and stays just under the cgroup: the MemoryWorker's dirty-page purge - which lost the race on the fuzzer's real VM under sustained chaotic load, letting RSS drift above tracked - wins it in the cleaner/faster container, and --cgroupns=host makes the server misread its cgroup (RSS read ~10 GiB) and over-throttle. The kill reproduces where per-container memory is accounted as on the fuzzer's VM. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=107389&sha=ec12cb3ce0a49a403226cb0668b092f02a2fa3f6&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%2C%20targeted%2C%20old_compatibility%29 Related: ClickHouse#107389 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The docker mem_limit used by the integration runner is not enforced as a hard memory.max in the docker-in-docker setup (--cgroupns=host), so a real kernel OOM never fires there - which is why the kill could not be reproduced via the test harness. This script instead creates a cgroup v2 itself (which the kernel does enforce), starts clickhouse-server inside it (so the server reads the cgroup and keeps its limits intact), and runs sustained concurrent groupArrayState merge/insert churn. The allocator retention gap (resident memory above the tracked limit) pushes resident memory past the cgroup and the kernel OOM killer fires - the same mechanism that killed the AST-fuzzer's server (tracked 48.9 GiB, resident 52-57 GiB). Verified: cgroup memory.events oom_kill increments and dmesg shows "Memory cgroup out of memory: Killed process ... (clickhouse), oom_memcg=/ch_merge_oom" (constraint=CONSTRAINT_MEMCG). Requires root + cgroup v2 + a built clickhouse binary. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=107389&sha=ec12cb3ce0a49a403226cb0668b092f02a2fa3f6&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%2C%20targeted%2C%20old_compatibility%29 Related: ClickHouse#107389 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
arrayResizeread its size argument viaIColumn::getInt, which for aDecimalcolumn returns the raw unscaled value rather than the logical one. As a resultarrayResize([1, 2, 3], 1.5::Decimal(2, 1))resized to 15 elements instead of 1, inconsistently withFloatand integer sizes (which truncate towards zero). A tiny fractional value such as-0.000000000000000000000006116852::Decimal(38, 30)has a raw value of-6116852, so the array was padded with millions of elements.This is now fixed by converting a
Decimalsize to a plain integer before resizing, so its real (rounded-towards-zero) value is used.The bug was found by
FunctionsStress.stress(function_prop_fuzzer), where the above query made a worker pad ~6 million elements one by one and get reported as stuck. The existingarrayResizeargument cap in that test did not prevent it: it only bounds the value from above (value > limit), so a large-magnitude negative size slips through, and for aDecimalit compares the logical value while the function used the raw one. The cap is now changed to bound the magnitude (abs(value) > limit) so large negative sizes are clamped too.CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=107319&sha=2603a4dd53466ae560f080b1a55ed3009d28fa9e&name_0=PR&name_1=Unit%20tests%20%28asan_ubsan%2C%20function_prop_fuzzer%29
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix
arrayResizewith aDecimalsize argument: the size is now interpreted by its real value (e.g.arrayResize([1, 2, 3], 1.5::Decimal(2, 1))returns one element) instead of the raw unscaled representation.Documentation entry for user-facing changes
🤖 Generated with Claude Code
Version info
26.6.1.780