Repository navigation
Check the overflow when allocating a block of aggregate function states - #117370
Algunenano merged 4 commits into
Conversation
A block of `AggregateFunction` states is deserialized into a single allocation of the size of one state times the number of rows, and both of them come from the data, so their product could wrap around: the block was then allocated smaller than what was written into it, and the states were created outside of it. A `Native` block of 110 bytes that declares 2^24 rows of a state of 2^40 bytes was enough to make the server write far outside the allocation. Every column that sizes itself by an element count is protected by `PODArray`, which checks the multiplication, so this was the only deserialization path computing a number of bytes as a product of two values taken from the data and handing it straight to the arena. The number of rows also comes from the data, so the row pointers are now reserved only after the size has been validated. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Workflow [PR], commit [69acbd3] Summary: ❌
AI ReviewSummaryThis PR hardens Final VerdictStatus: ✅ Approve LLVM Coverage Report |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes418 object files changed (+37.30 KiB total), 0 added.
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units3655 translation units recompiled, 16880 s compile time in total, 3655 of them have a recent master baseline. |
The number of rows of a block comes from the data, and so does the size of a state, so the product of the two must not be allocated upfront: it wraps around, and a block of a hundred bytes can ask for an allocation of any size. The states are allocated in blocks bounded by the size of the array of pointers that is reserved for them anyway, so a block of rows of an ordinary state still takes a single allocation, and a state larger than that bound is allocated on its own. `NativeReader` avoids preallocating from the row count for the same reason. The arena adds the alignment, the padding and the rounding to the page size on top of the size it is given, and these additions wrap around for a size close to the maximum, which makes it allocate a chunk smaller than requested. Sizes that the allocator refuses outright are cut off there as well, so that data-driven sizes are reported as a data error instead of the logical error the allocator reports. Arena allocation is unchanged for a block of states of an ordinary size: `ArenaAllocBytes` is the same before and after for a block of 65409 states of 32 bytes. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`createAndDeserializeBatch` appends the pointer to a deserialized state outside of the block that destroys the state when the deserialization throws. Appending allocates, so it can throw as well, and the state would then be neither destroyed nor owned by the column. This used to be unreachable only because the callers reserved the whole range beforehand. The batch of a state of zero size is bounded as well, so that the number of rows, which comes from the data, is never passed to the helper as is. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…e-bulk-alloc-overflow
f9ed874
Cherry pick #117370 to 26.3: Check the overflow when allocating a block of aggregate function states
…of aggregate function states
Cherry pick #117370 to 26.6: Check the overflow when allocating a block of aggregate function states
…of aggregate function states
Backport #117370 to 26.8: Check the overflow when allocating a block of aggregate function states
Backport #117370 to 26.7: Check the overflow when allocating a block of aggregate function states
Backport #117370 to 26.6: Check the overflow when allocating a block of aggregate function states
Backport #117370 to 26.3: Check the overflow when allocating a block of aggregate function states
…g a block of aggregate function states
…g a block of aggregate function states
AGG: malformed Native block of aggregate states -> crash (OOB write). Effect in the production build a394e92: wrong/failing (the upstream test fails on it and passes on official 26.8.8.8; evidence/fix_ci_20260925/upstream_repro/residual/117370.PROD263.txt). Upstream patch unchanged, with its test(s): 05055_aggregate_state_bulk_deserialization_overflow. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Follow-up for #115701.
A block of
AggregateFunctionstates is deserialized into a single allocation of the size of one state times the number of rows, and both of them come from the data, so their product could wrap around: the block was then allocated smaller than what was written into it, and the states were created outside of it. Bounding the size of a single state, as the previous pull request did for theResamplecombinator, shrinks the exponent but does not remove the wrap-around: aNativeblock of 110 bytes that declares 2^24 rows of a state of 2^40 bytes is enough to make the server write far outside the allocation, which reproduces as aSIGSEGV.Every column that sizes itself by an element count is protected by
PODArray, which checks the multiplication, so this was the only deserialization path computing a number of bytes as a product of two values taken from the data and handing it straight to the arena. The number of rows also comes from the data, so the row pointers are now reserved only after the size has been validated.Related: #115701
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Check the overflow when allocating a block of aggregate function states on deserialization: a malformed
Nativeblock could make the server write out of bounds.Workflow [PR]
Sync PR [sync-upstream/pr/117370]
Version info
26.8.3.24,26.7.7.15,26.6.5.42,26.3.30.8