Skip to content

Build the boolean fixture of 04308_arrow_oob_reads_value with two rows - #113593

Merged
PedroTadim merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-04308-bool-fixture-two-rows
Aug 6, 2026
Merged

PedroTadim merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-04308-bool-fixture-two-rows

Conversation

@groeneai

@groeneai groeneai commented Aug 6, 2026 •

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):

Make the boolean case of 04308_arrow_oob_reads_value corrupt only the declared row count, so it reaches the per-element bit-packed buffer guard it is meant to cover.

Description

Each fixture is corrupted by inflate_row_count, which rewrites every 8-aligned little-endian int64 equal to the original row count. For the bool case only, that sweep also hits a buffer-length field: a 1-row boolean is bit-packed into a single byte, so the literal 1 is a buffer length too. Of its four matching offsets two are row counts, one is Buffer[1].length and one a body byte, so the file declares a 16384-byte buffer inside an 8-byte body.

It is therefore rejected earlier than intended, by the generic message-envelope check, and the guard case 8 is documented to cover (the per-element bit-packed read) is never reached. The assertion still passes, so the arm is silently weak rather than red. Decoding every write(inflate_row_count( fixture in 04307/04308/04309 (7 + 9 + 7 = 23) shows this is the only one affected.

Fix: build the fixture with two rows and inflate on orig_n = 2. A 2-row boolean is still one byte, so 2 matches only the two row counts and the buffer length stays honest, which an added assertion now pins. 04307's dict_indexes case already uses this idiom; larger counts collide with other metadata. inflate_row_count is untouched, so the other eight fixtures stay byte-identical.

Validated on a master build at this base: the fixed fixture reports Arrow IPC bool buffer is too small: have 1 bytes, need 2048 where the old one reported the envelope error, all nine cases still assert INCORRECT_DATA against an unchanged .reference, and 50/50 randomized runs pass. 04358 and 04410 still cover the envelope check.

The fixture also becomes reader-agnostic, which matters for the in-flight arrow 25.0.0 backports (#113539, #113541, #113542): under arrow 25 the old fixture dies at the IO layer with File too short, while the new one is read and then rejected for the undersized bool buffer.

Version info

  • Backported to: 26.6.3.16, 26.5.7.19, 26.3.18.10

The test corrupts each fixture by inflating the declared row count:
inflate_row_count rewrites every 8-aligned little-endian int64 equal to
the original count. For the bool case only, that sweep also rewrites two
buffer-length fields, because a 1-row boolean is bit-packed into a single
byte, so the literal 1 is a buffer length as well as a row count.

Measured on the current fixture: four offsets match (200, 240, 256, 272).
Patching each alone shows 200 and 256 are row counts, while 240 and 272
are buffer lengths. Inflating those declares a 16384-byte buffer inside a
450-byte file, which is a different corruption from the intended one, and
it is rejected by the generic message-envelope check before any
per-element read. So case 8 never reaches readColumnWithBooleanData, the
per-element bit-packed buffer guard the test header says it covers. The
assertion still passes, so nothing is red today; the arm is silently
weak. Sibling 04307 does reach its per-type guard, which makes bool the
only case in the family whose intended guard is unpinned.

Build the fixture with two rows and inflate on orig_n = 2 instead. A
2-row boolean is still one byte, so 2 matches only the two row-count
fields and the buffer length stays honest. The row count is load-bearing:
sweeping n from 2 to 9 and classifying every matching offset shows 4 and
8 reintroduce the same collateral patching (they collide with other
metadata fields), so the comment records not to use them. Choosing a
count distinct from the buffer lengths is the idiom 04307's dict_indexes
case already uses. inflate_row_count is untouched, so the other eight
fixtures are byte-identical, verified by extracting the embedded
generator from both versions and comparing md5s.

Validated on a master build at this base: the fixed fixture reports
"Arrow IPC bool buffer is too small: have 1 bytes, need 2048" (the
per-type guard at RecordBatchDecoder.cpp:234) where the old one reported
the envelope error at MessageReader.cpp:134; the uncorrupted 2-row file
still reads back true/false; all nine cases assert INCORRECT_DATA with an
unchanged .reference; 50 of 50 randomized runs pass; the 12 sibling Arrow
OOB tests pass.

The same change makes the fixture reader-agnostic, which matters for the
in-flight arrow 25.0.0 backports: arrow 25 refuses the over-long declared
read at its IO layer with CANNOT_READ_ALL_DATA before any ClickHouse
guard runs. This commit does not touch those branches.
The two-row fixture works because 2 appears only in RecordBatch.length and
FieldNode[0].length, so inflate_row_count corrupts the declared row count and
nothing else. Nothing in the test said so, so a future pyarrow layout change
that put the row count back into a buffer-length field would silently restore
the old envelope rejection while the reference stayed nine INCORRECT_DATA
lines: the arm would be weak again, and green.

Assert the count at the bool call site instead. The enumeration is equivalent
to the helper's own find()-plus-alignment sweep, verified to produce identical
offset lists on all twelve fixtures probed, so it counts exactly what will be
patched. It must be an equality, not a lower bound, because the defect is
extra matches.

Reverting to one row, or moving to four, now makes fixture generation abort
and the whole test fail rather than merely changing which guard rejects the
file. Measured identical on pyarrow 22.0.0, which the stateless-test image
pins, and 24.0.0.

Also drop a plural: exactly one buffer-length field holds the needle.
@groeneai

groeneai commented Aug 6, 2026

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

Two review rounds, each an independent cold read plus a separate second-model pass. Round 1 found
one substantive gap and sent the change back; this round verified the remedy and re-checked the
contract. Final second-model pass returned 0 findings.

❌ Round 1 — the fix's mechanism was demonstrated but not pinned (fixed)

The original change was correct, but the assertion that makes it stay correct existed only in the
investigation record, not in the test. Without it, a future pyarrow layout change that
reintroduced a length-field collision would silently restore the old, weaker behaviour while the
test still reported nine INCORRECT_DATA lines and passed.

Fixed by pinning it at the call site:

pos = [i for i in range(0, len(d) - 7, 8) if struct.unpack_from('<q', d, i)[0] == 2]
assert len(pos) == 2, f'expected exactly 2 aligned int64==2 (the row counts), got {pos}'

Four properties were then measured rather than assumed, on both pyarrow 22.0.0 (what
ci/docker/stateless-test/requirements.txt pins) and 24.0.0:

  • equivalent to the sweep it guards: the assertion enumerates [200, 256] and
    inflate_row_count patches [200, 256] — identical lists, so it counts exactly what will be
    written;
  • discriminating: reverting to one row gives 4 offsets and fires; orig_n = 4 gives 4 and
    fires; orig_n = 8 gives 4 and fires. That is precisely the regression class it exists to catch;
  • live: a firing assertion aborts fixture generation, so all nine check calls fail and the
    .reference diff is 9 lines — and independently the traceback fails the case through
    clickhouse-test's having stderror: path. Either channel alone is enough;
  • not stripped: no PYTHONOPTIMIZE and no python -O anywhere in the CI stateless path. 29
    stateless tests already use a bare assert inside a python heredoc.

⚠️ An == 2 pin must not fire on an unrelated pyarrow bump (checked)

A too-tight pin turns a green test red on someone else's dependency bump, so the layout was swept
across five versions spanning the CI pin, the integration pin and the version currently being
bumped to:

pyarrow 2-row fixture assertion 1-row mutant
21.0.0 len 450, [200, 256] passes 4 → fires
22.0.0 (CI pin) len 450, [200, 256] passes 4 → fires
23.0.1 len 450, [200, 256] passes 4 → fires
24.0.0 len 450, [200, 256] passes 4 → fires
25.0.0 len 450, [200, 256] passes 4 → fires

Identical in all five.

💡 The reader-agnostic claim, measured against arrow 25.0.0 rather than inferred

pyarrow 25.0.0 embeds arrow C++ 25.0.0, so the claim about the in-flight bump is directly
testable without building a release branch:

old 1-row corrupted fixture → OSError: File too short: expected to be able to read
                              16384 bytes, got 8        (killed at arrow's IO layer)

new 2-row corrupted fixture → read back, then rejected as
                              Buffer #1 too small in array of type bool and length
                              16384: expected at least 2048 byte(s), got 1

One measurement confirms both that the fix relocates the rejection to the per-element guard case 8
documents, and that the new fixture survives arrow 25's stricter IO layer where the old one does
not.

💡 Carrier scope, enumerated independently

All nine fixtures in this file were rebuilt and their matched offsets decoded on both pyarrow
versions. After the fix every one matches exactly two offsets — the two row counts — so bool was
the only affected case and no other fixture in the file over-patches.

⚠️ A wrong count in the description (corrected before publishing)

The description said "all 24 inflate_row_count fixtures". The number is 23
(04307 7 + 04308 9 + 04309 7); the 24 came from a grep that also counted a prose comment in
04307 mentioning the helper. The sentence now ships the predicate that reproduces the figure
rather than a bare digit, so it can be re-checked with one command.

One further wording point was not changed: "a 16384-byte buffer inside an 8-byte body" reads
oddly, but 8 is exactly what arrow itself reports as available (... got 8), so the sentence is
accurate as written.

@groeneai

groeneai commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. Nothing is red on master, so the "repro" is the deterministic guard-message difference, reproduced on demand on a master build at this base: the fixed fixture stops at the per-type guard (RecordBatchDecoder.cpp:234, Arrow IPC bool buffer is too small: have 1 bytes, need 2048), the current one at the generic envelope check (MessageReader.cpp:134). The offset classification is deterministic too: 4 matching offsets before, 2 after. On the release branches the red is deterministic per the runner's own diagnosis (4/4 and 5/5 failures with randomization disabled).
b Root cause explained? Yes. inflate_row_count rewrites every 8-aligned little-endian int64 equal to orig_n. A 1-row boolean is bit-packed into one byte, so the literal 1 is also a buffer length. Decoding the record-batch flatbuffer classifies the four matching offsets: 200 = RecordBatch.length and 256 = FieldNode[0].length (row counts), 240 = Buffer[1].length (the one buffer-length field), and 272 = the first byte of the record-batch body, i.e. the bit-packed data, not a length field. Inflating 240 declares a 16384-byte buffer inside an 8-byte body (Message.bodyLength stays 8), so the reader refuses it at the envelope check before any per-element read. Every other case has a buffer of 2, 4, 8 or 16 bytes, so the ambiguity cannot arise there.
c Fix matches root cause? Yes. The defect is in the fixture, so the fixture is where it is fixed: two rows and orig_n = 2 make the row count the only value that matches, so the corruption becomes more specific and the read gets further into the reader. Not a band-aid: no bound widened, no data reduced, no skip tag, no no-random-* tag, no guard added in src/, and the oracle is untouched.
d Test intent preserved / new tests added? Preserved and strengthened. All nine cases are kept, .reference is unchanged (nine INCORRECT_DATA lines) and the grep -qF 'INCORRECT_DATA' oracle is untouched. The change is itself a test change, so no separate regression test applies. The bool call site additionally asserts that the sweep matches exactly two 8-aligned int64s equal to the row count, which pins the fix's mechanism and not just its outcome: two mutation arms (reverting to one row, and moving to four rows) each make that assertion fire and the whole test FAIL, so the new arm is not vacuous.
e Both directions demonstrated? Yes, on a master build whose Build ID was asserted equal to SELECT lower(buildId()) before every verdict. Fixed fixture: Arrow IPC bool buffer is too small: have 1 bytes, need 2048, and the test passes 9/9 with an unchanged .reference. Reverted to the 1-row form: Arrow IPC buffer (offset 0, length 16384) is out of the message body of size 8, the patched-offset count returns to 4 (one of them the Buffer[1].length field), and the new call-site assertion fires, so the whole test now FAILS on the pre-fix fixture instead of passing silently. Positive control: the uncorrupted 2-row file reads back true/false, so the fixture is a valid Arrow file broken only by the inflation.
f Fix is general across code paths? Yes, and bounded by measurement. All 23 inflate_row_count fixtures across 04307 (7), 04308 (9) and 04309 (7) were generated with the helper instrumented, and every matched offset was classified by decoding the record-batch flatbuffer: only 04308's 1-row bool case patches a buffer-length field, so bool is the only affected path. Two 04309 cases (list, map) match more than two offsets, but those extras are FieldNode[i].length row counts of nested children plus body data bytes, never a buffer length, so they are not this defect. The siblings are deliberately untouched (one concern per PR); tests/queries/0_stateless/*arrow*oob*.sh is 12 tests including this one, and the 11 others pass.
g Fix generalizes across inputs (params/datatypes/wrappers)? The wrapper axis is N/A: the fixtures are bare 1 or 2-row arrays with no Nullable, LowCardinality, Const, Array or Map involved. The relevant axis is the row count, swept from 2 to 9 and classified: 4 collides with the schema message and the footer, 8 additionally collides with Message.bodyLength; every other value patches exactly the two row-count fields, so 2 is load-bearing and recorded as such in the test comment. The fix depends only on Arrow format bit-packing, not on any pyarrow error message or version-specific text, and both layouts were re-measured identical on pyarrow 22.0.0 (the version ci/docker/stateless-test/requirements.txt pins) and 24.0.0.
h Backward compatible? (maintainer-approved exception only) N/A. Test-only change: no setting default, no serialization format, no SettingsChangesHistory.cpp entry owed, no src/ change at all.
i Invariants and contracts preserved? Yes. The fixture invariant is that the declared row count is inflated while every buffer length stays honest, so the too-short buffer is caught by the per-type guard; the fix restores it for bool. The shared inflate_row_count contract is unchanged, and its other eight callers were shown to generate byte-identical fixtures by extracting the embedded generator from both versions and comparing md5s (8 of 8 identical, bool differing as intended).

Session id: cron:clickhouse-impl-slot-41:20260805-212300

@groeneai

groeneai commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator Author

cc @Algunenano, could you review this? The bool case of the OOB test you added in ea02ba4 is a silently weak arm: a 1-row boolean is bit-packed into one byte, so inflate_row_count rewrites Buffer[1].length as well as the row counts and the file is rejected by the generic envelope check instead of the per-element bit-packed guard the header says it covers. Building the fixture with two rows keeps the buffer length honest, and an added assertion pins that the sweep matches exactly the two row counts.

@PedroTadim PedroTadim self-assigned this Aug 6, 2026
@PedroTadim PedroTadim added the can be tested Allows running workflows for external contributors label Aug 6, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [87731cf]

Summary: ❌

job_name test_name status info comment
Stress test (amd_tsan) FAIL
Logical error: '(isConst() || isSparse() || isReplicated() || rhs.isConst() || rhs.isSparse() || rhs.isReplicated()) ? getDataType() == rhs.getDataType() : typeid(*this) == typeid(rhs)' (STID: 2508-30f6) FAIL cidb IGNORED

AI Review

Summary

This PR tightens the 04308_arrow_oob_reads_value boolean fixture so inflate_row_count only corrupts the declared row count instead of also colliding with the bit-packed buffer-length metadata. I reviewed the current diff and prior discussion, checked the changed test against the surrounding Arrow OOB fixtures, and independently validated the serialized layout on pyarrow 22.0.0 and pyarrow 25.0.0: the new 2-row fixture patches only the two row-count fields, while the old 1-row fixture still collides with extra aligned fields. I did not find any remaining correctness, coverage, or PR-metadata issues in the current patch.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Aug 6, 2026
@PedroTadim
PedroTadim added this pull request to the merge queue Aug 6, 2026
Merged via the queue into ClickHouse:master with commit ba143f3 Aug 6, 2026
178 of 180 checks passed
@groeneai

groeneai commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 87731cf

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stress test (amd_tsan) / Logical error: '... typeid(*this) == typeid(rhs)' (STID 2508-30f6) chronic trunk abort in HashJoin::buildAdditionalFilter -> assertTypeEquality, reached through JOIN + PREWHERE over mismatched column types. 196 rows across 118 unrelated pull requests and 12 check flavours in 90 days, including 13 master rows, first seen 2026-05-08. This diff rewrites the boolean fixture of one Arrow stateless test and touches no join or column code fixing pull request 113534 (external, open)

No other check failed: 176 check-runs on this head, all completed, 58 success / 117 skipped / 1 failure, 0 still running. Config Workflow and Finish Workflow both succeeded. Past the 20-minute CIDB ingestion buffer.

The failing check reported the row as IGNORED, and the fix is external and open, so re-merging master would not clear it.

Session id: cron:our-pr-ci-monitor:20260806-133000

@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 6, 2026
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Aug 7, 2026
@robot-ch-test-poll robot-ch-test-poll added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Aug 7, 2026
clickhouse-gh Bot pushed a commit that referenced this pull request Aug 7, 2026
clickhouse-gh Bot added a commit that referenced this pull request Aug 7, 2026
Backport #113593 to 26.6: Build the boolean fixture of 04308_arrow_oob_reads_value with two rows
clickhouse-gh Bot pushed a commit that referenced this pull request Aug 7, 2026
clickhouse-gh Bot added a commit that referenced this pull request Aug 7, 2026
Backport #113593 to 26.7: Build the boolean fixture of 04308_arrow_oob_reads_value with two rows
PedroTadim added a commit that referenced this pull request Aug 7, 2026
Backport #113593 to 26.5: Build the boolean fixture of 04308_arrow_oob_reads_value with two rows
PedroTadim added a commit that referenced this pull request Aug 7, 2026
Backport #113593 to 26.3: Build the boolean fixture of 04308_arrow_oob_reads_value with two rows
@groeneai groeneai added the groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding label Aug 19, 2026
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Aug 24, 2026
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Aug 24, 2026
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-ci-master PR origin: master/nightly CI monitoring finding pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-ci pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v26.3-must-backport v26.5-must-backport v26.6-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants