Repository navigation
Bound text index posting list deserialization - #115222
Conversation
`PostingListCodecNone::decode` handed the payload to `PostingList::read`, which wraps `roaring_bitmap_portable_deserialize` and trusts the container headers found inside that payload. A container claiming more values than the declared size holds made the deserializer read past the end of the buffer and return the leaked bytes as row ids, so a corrupted or forged text index file - for example one delivered by `RESTORE TABLE` - turned into a heap out-of-bounds read of up to ~24 KiB per query. Use `PostingList::readSafe`, which bounds every container read by the declared size, as `DeleteBitmap`, `AggregateFunctionGroupBitmapData` and `PuffinBlockInputFormat` already do. It is free: croaring's `read` is `readSafe` with `maxbytes = SIZE_MAX`. ClickHouse/clickhouse-private#69184 Co-Authored-By: Claude Opus 5 <[email protected]>
|
Workflow [PR], commit [eebc3ff] Summary: ❌
AI ReviewSummaryThis PR switches uncompressed text-index posting list deserialization from Findings
Final VerdictChanges requested. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 38/38 (100.00%) · Uncovered code |
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, 10 s compile time in total, 7 of them have a recent master baseline. |
b69c8ef
|
@groeneai fix conflicts in all cherry-picks created for this PR. |
|
@CurtizJ I looked at all five. The textual conflict is misleading on every one of them, so I want to flag two things before opening PRs. 25.8 (#116306) cannot take this PR. There is no text index on that branch: On 26.3/26.5/26.6/26.7 the conflicted function is not the code that reads. There, The equivalent unbounded deserialization on those branches is in
so the port is The gtest cannot be ported as written, since it drives Two asks: is the 25.8 One mechanical note: I have no push access to |
Cherry pick #115222 to 26.3: Bound text index posting list deserialization
Cherry pick #115222 to 26.5: Bound text index posting list deserialization
Cherry pick #115222 to 26.6: Bound text index posting list deserialization
Cherry pick #115222 to 26.7: Bound text index posting list deserialization
Backport #115222 to 26.5: Bound text index posting list deserialization
Backport #115222 to 26.3: Bound text index posting list deserialization
… codec `PostingsSerialization`'s constructor asserts its codec is non-null (`chassert(posting_list_codec)`, `MergeTreeIndexText.cpp:218`), and the rewritten `gtest_text_index_postings_deserialization.cpp` on this branch passes `nullptr`. The first `decodePostingsInPlace` call in `RoundTrip` therefore aborts inside the constructor, before `deserialize` is entered. That is why `Unit tests (asan_ubsan)` and `Unit tests (tsan)` fail on the backport while every `Build` job is green (`chassert` is inert in release), why the `function_prop_fuzzer` variants pass (they filter this suite out), and why `TruncatedPayloadRejected` never reported. The test's comment is accurate about `deserialize`: with `header = 0` the uncompressed branch never consults the codec. The constructor asserts first, though, so the precondition has to be satisfied regardless. A `Type::None` codec keeps coverage identical, because `PostingListCodecNone::decode` is a no-op: had the codec been consulted, `RoundTrip` would deserialize an empty posting list and fail on cardinality. It passes, so the assertions still traverse the `PostingList::readSafe` bounding this backport adds. Reverting that bound while keeping this change makes `TruncatedPayloadRejected` fail all four assertions, so the repaired test still catches the defect it was written for. `MergeTreeIndexText.h` includes only `IPostingListCodec.h`, so the codec header has to be included here; the version of this test on `master` carries the same include. Related: #115222 Co-Authored-By: Claude Opus 5 <[email protected]>
Backport #115222 to 26.7: Bound text index posting list deserialization
Backport #115222 to 26.6: Bound text index posting list deserialization
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed an out-of-bounds read while deserializing corrupted posting lists of a text index.
Workflow [PR]
Sync PR [sync-upstream/pr/115222]
Version info
26.8.1.1632(included in26.8and later)26.7.6.20,26.6.4.47,26.3.24.4