Repository navigation
Conversation
|
Workflow [PR], commit [dd28a0e] Summary: ✅
AI ReviewSummaryThis PR hardens deserialization of PR Metadata
Exact replacement: Findings💡 Nits
Final Verdict✅ No remaining code blockers found in the current diff. Update the changelog entry before merge. LLVM Coverage ReportMeasured on commit dd28a0e.
Changed lines: Changed C/C++ lines covered: 24/29 (82.76%) · Uncovered code |
| size_t size = 0; | ||
| readBinaryLittleEndian(size, buf); | ||
|
|
||
| data.reserve(size, arena); |
There was a problem hiding this comment.
Here was a problem because this code could read size from corrupted data, then multiply it by the size of Element and try to allocate without any boundary checks.
399c9c0 to
aed8d4d
Compare
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes5 object files changed (+22.21 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 units10 translation units recompiled, 38 s compile time in total, 10 of them have a recent master baseline. Median compile-time ratio to the baselines is ×1.06 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. |
The number of elements is read from the serialized state and was used for a single allocation upfront, so a state claiming 2^60 or more elements made the size of the allocation in bytes overflow and the following writes went past the allocated memory. The array now grows while the data is read.
The count of samples in a bucket comes from the serialized state, so a small state could ask for an arbitrarily large allocation. Only a bounded number of samples is reserved now and the buffer grows while the samples are read.
The number of buckets is read from the serialized state and was only checked against the bucket count derived from the function parameters. A huge window makes that count enormous, so a tiny state could ask for an arbitrarily large allocation: an 18-byte state of `timeSeriesChangesToGrid` allocated 1.25 GiB. Only a bounded number of buckets is reserved now and the map grows while the buckets are read.
6f12a8f to
e908ac1
Compare
| /// `bucket_count` is derived from the function parameters and a huge window makes it enormous, so the | ||
| /// number of buckets is only reserved up to a bound and the map grows while the buckets are read. That way | ||
| /// a corrupted count fails with an end-of-buffer error instead of allocating memory for the claimed number. | ||
| data(place)->buckets.reserve(std::min(buckets_size, MAX_BUCKETS_TO_RESERVE)); |
There was a problem hiding this comment.
The changelog entry still says only Fix out of bound in timeSeriesGroupArray(), but this hunk changes the shared AggregateFunctionTimeseriesBase deserializer too, so the published changelog will miss the whole timeSeries*ToGrid surface touched by the PR.
Please replace it with something specific and user-readable, for example: Fix out-of-bounds writes and oversized allocations when deserializing malformed timeSeriesGroupArray and timeSeries*ToGrid aggregate states.
…-timeseries-grouparray
PromQL Compliance ReportBaseline: S3 master
Note: score is unchanged vs baseline. |
Review round 2 on the previous commit. readStringBinaryInto stages a value that spans compressed blocks before committing it to the Arena, because an Arena cannot reuse a superseded block. Staging it as one tracked object per buffer refill made the cost a function of the block size rather than of the value: at 4-byte blocks a 1 MB value needs 250001 objects of 24 bytes each. Small blocks are supported and reachable, and 02124_uncompressed_cache pins 12 bytes, while the test harness randomizes both compress-block settings down to 1. Since the staging containers are memory-tracked and throwing, that overhead converted a state that used to load into MEMORY_LIMIT_EXCEEDED, so this is a compatibility fix as well as a simplification. Measured on a wide part with both block sizes pinned to 4, reading one legitimate 1 MB value back needs over 10 MB with per-refill staging and at most 1.5 MB with one growing container. The three TimeSeries/ deserializers are dropped from this change. ClickHouse#117404 covers all four sites they touched, so nothing is lost by leaving them to it. The two fixtures whose destination is operator new pin their path and error only, and their comment now says so. The tracker counts that destination but never refuses it: enforce_memory_limit is size >= min_allocation_size_to_ throw_on_memory_limit, a ServerSettings entry defaulting to UInt64::max, so no stateless test can make either side refuse. Arena and PODArray destinations do refuse, because Allocator.cpp allocates through CurrentMemoryTracker::alloc with the limit enforced, which is why the other sites here redden. Peak RSS for the -Map key improves from 1444 to 423 MiB. The refill fixture pins min_bytes_for_wide_part = 0 beside its two block sizes. Part type is randomized per run, and a compact part resolves its own 1 MiB bound: at a 64 KiB pin it wrote 2 blocks where the wide writer writes 31. Without the pin the block structure that arm depends on was not deterministic.
Backport #117404 to 26.8: Fix out of bound in timeSeriesGroupArray()
Merge the backport base while retaining the 26.3 time-series implementation. Apply bounded sample reservations in the three release implementations that precede the shared samples helper, and bound the outer bucket reservation. Adapt the regression test to a large grid and cover each sample deserializer. Related: #118551 Related: #117404
Cherry pick #117404 to 26.3: Fix out of bound in timeSeriesGroupArray()
Cherry pick #117404 to 26.7: Fix out of bound in timeSeriesGroupArray()
Backport #117404 to 26.7: Fix out of bound in timeSeriesGroupArray()
Backport #117404 to 26.3: Fix out of bound in timeSeriesGroupArray()
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix out of bound in
timeSeriesGroupArray()Workflow [PR]
Sync PR [sync-upstream/pr/117404]
Version info
26.9.1.535-master(included in26.9and later)26.8.3.56,26.7.14.33,26.3.33.139