Skip to content

Fix the text index postings unit test aborting on a null posting list codec - #116636

Merged
CurtizJ merged 1 commit into
ClickHouse:backport/26.7/115222from
groeneai:groeneai/fix-gtest-115222-26.7
Aug 27, 2026
Merged

CurtizJ merged 1 commit into
ClickHouse:backport/26.7/115222from
groeneai:groeneai/fix-gtest-115222-26.7

Conversation

@groeneai

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

...

Description

Related: #115222
Related: #116536

Base is backport/26.7/115222, the head branch of robot backport #116536, where
Unit tests (asan_ubsan) and Unit tests (tsan) fail.

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 passes nullptr. RoundTrip therefore aborts
inside the constructor, before deserialize runs. The test's comment is about deserialize,
where header = 0 indeed never consults the codec, but the constructor asserts first. Hence
every Build job is green (chassert is inert in release), the function_prop_fuzzer variants
pass because they filter this suite out, and TruncatedPayloadRejected never reported.

This passes a real Type::None codec instead. Two lines, test only. Coverage is unchanged:
PostingListCodecNone::decode is a no-op, so if the codec were consulted RoundTrip would get
an empty posting list and fail on cardinality; it passes, so the assertions still traverse the
readSafe bounding that #115222 added.

Validated with a Debug build on this branch's pinned clang-21, Build-ID asserted per arm.
Unpatched, RoundTrip aborts with Logical error: 'posting_list_codec'.; patched, both tests
pass. Reverting the merged readSafe bound while keeping this change makes
TruncatedPayloadRejected fail all four assertions, so the repaired test still catches the bug
the backport fixes.

I have no push access to backport/26.7/115222 (maintainerCanModify is false on #116536), so
this is a fork PR against that base. No checks run on it, since CI triggers only for a base of
master or a release branch; the gate is #116536's own Unit tests re-run once this is merged
into its head branch. The same rewritten file is already merged onto 26.3 (#116533) and 26.5
(#116534), where Unit tests is not a BackportPR job so the abort is unobservable there; out of
scope here.

… 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: ClickHouse#115222

Co-Authored-By: Claude Opus 5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai labels Aug 27, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 1 finding), plus my own cold review
of the resulting tree before that gate ran (2 nits).

# Sev Finding Verdict Evidence / action
1 ❌ An oversized num_bytes could bypass the readSafe bound, because the in-buffer test is written as istr.position() + num_bytes <= istr.buffer().end() (MergeTreeIndexText.cpp:321) DISAGREE, outside this change git diff --name-only 3e82ab400ce6..HEAD lists exactly one file, the gtest; MergeTreeIndexText.cpp is byte-identical to the parent commit, which is the Backport #115222 to 26.7 commit itself. The gate saw that file only because its base resolves to the 26.7 branch point, so the reviewed scope is the whole backport rather than my commit (GATE_B_DIFFSTAT: 2 files changed, 114 insertions(+), 2 deletions(-)). This change is test-only and asserts nothing about deserialize bounds. I did not reproduce it; see the note below.
2 💡 Relationship links used the short #NNNNN form, and #116536 had no explicit line AGREE, fixed The description now carries full-URL Related: lines, one per line, per .claude/CLAUDE.md:169.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal
per finding. Findings on hunks unchanged by this change are auto-dropped.

On finding 1, recorded as citations rather than as a claim of mine, since it is about the parent
commit and not about anything I wrote. On this branch deserialize writes the in-buffer test as
istr.position() + num_bytes <= istr.buffer().end(), while readNBytes
(src/IO/ReadHelpers.h:109-112) writes the same test as
size <= static_cast<size_t>(buf.buffer().end() - buf.position()) and carries a comment saying the
difference form is there to avoid pointer overflow UB on large sizes. Two things bound how far that
observation goes. I did not build or run anything against it, so I am reporting the asymmetry and
nothing more. And it is specific to the release-branch shape: on master this function no longer
exists in that form, having been split into deserializeToBitmap and deserializeToArray with the
uncompressed path routed through the codec, so readSafe and the length test are both absent there.
I am not proposing a change to it here, because widening a test-only fix into
MergeTreeIndexText.cpp would put production code on a base where no checks run.

Session id: cron:clickhouse-review-slot-9:20260827-024000

@clickhouse-gh clickhouse-gh Bot closed this Aug 27, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Aug 27, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes, 100%. taskset -c 0 build/src/unit_tests_dbms --gtest_filter='TextIndexPostingsDeserializationTest.*' on unpatched 3e82ab400ce6 aborts with rc=134 every run.
b Root cause explained? Yes. The gtest passes nullptr to PostingsSerialization, tripping chassert(posting_list_codec) at MergeTreeIndexText.cpp:218, so RoundTrip aborts in the constructor before deserialize runs. Confirmed by the runtime stack trace, not only by reading.
c Fix matches root cause? Yes. The test violated a precondition the production constructor states; the fix satisfies it. No bound widened, no tag added, no assertion relaxed, no production invariant weakened.
d Test intent preserved / new tests added? Preserved and measured. Nothing weakened, skipped or tagged. Reverting the merged readSafe bound while keeping this change makes TruncatedPayloadRejected fail all 4 assertions, so the repaired test still catches the bug the backport fixes; RoundTrip stays green there, so the mutant is narrow. Coverage rises from 0 executed assertions to both tests running.
e Both directions demonstrated? Yes, same command, distinct Build-IDs. Unpatched 4ef23b11...: rc=134, Logical error: 'posting_list_codec'.. Patched d8dd5e7f...: rc=0, [ OK ] RoundTrip, [ OK ] TruncatedPayloadRejected, [ PASSED ] 2 tests.
f Fix is general across code paths? Yes. git grep 'PostingsSerialization(' finds 4 production construction sites (MergeTreeIndexText.cpp:524, MergeTreeReaderTextIndex.cpp:127, TextIndexUtils.cpp:219, :227); all take their codec from PostingListCodecFactory::createPostingListCodec, which cannot return null. PostingsSerialization(nullptr has exactly one hit, the line fixed here. Both test helpers route through the single makeSerialization.
g Fix generalizes across inputs (params/datatypes/wrappers)? Not engaged, and the existing matrix is untouched: empty / array / bitset (30000 elements) / run containers, both buffer topologies, two truncation sizes.
h Backward compatible? (maintainer-approved exception only) Not engaged. Test only. No setting, default, serialization format, SettingsChangesHistory.cpp entry or upgrade path.
i Invariants and contracts preserved? Strengthened. "Every constructed PostingsSerialization carries a non-null codec" now holds at every site including the test. The unique_ptr is built at the call site and moved in, matching all four production sites; no lifetime, ownership, concurrency or error-path contract changes.

Session id: cron:clickhouse-impl-slot-5:20260827-015500

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @ahmadov, could you review this? The rewritten gtest_text_index_postings_deserialization on the #116536 backport branch passes nullptr for the posting list codec, which trips chassert(posting_list_codec) in the PostingsSerialization constructor, so RoundTrip aborts inside the constructor before deserialize runs. This passes a real Type::None codec instead, which leaves coverage unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants