Repository navigation
Build the boolean fixture of 04308_arrow_oob_reads_value with two rows - #113593
Conversation
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.
Internal second-model review (click to expand)Two review rounds, each an independent cold read plus a separate second-model pass. Round 1 found ❌ 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 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 |
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.
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-41:20260805-212300 |
|
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 |
|
Workflow [PR], commit [87731cf] Summary: ❌
AI ReviewSummaryThis PR tightens the Final VerdictStatus: ✅ Approve |
ba143f3
CI finish ledger — 87731cfEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
No other check failed: 176 check-runs on this head, all completed, 58 success / 117 skipped / 1 failure, 0 still running. The failing check reported the row as Session id: cron:our-pr-ci-monitor:20260806-133000 |
…b_reads_value with two rows
Backport #113593 to 26.6: Build the boolean fixture of 04308_arrow_oob_reads_value with two rows
…b_reads_value with two rows
Backport #113593 to 26.7: Build the boolean fixture of 04308_arrow_oob_reads_value with two rows
Backport #113593 to 26.5: Build the boolean fixture of 04308_arrow_oob_reads_value with two rows
Backport #113593 to 26.3: Build the boolean fixture of 04308_arrow_oob_reads_value with two rows
…8_arrow_oob_reads_value with two rows
…8_arrow_oob_reads_value with two rows
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Make the boolean case of
04308_arrow_oob_reads_valuecorrupt 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-endianint64equal to the original row count. For theboolcase only, that sweep also hits a buffer-length field: a 1-row boolean is bit-packed into a single byte, so the literal1is a buffer length too. Of its four matching offsets two are row counts, one isBuffer[1].lengthand 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 in04307/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, so2matches only the two row counts and the buffer length stays honest, which an added assertion now pins.04307'sdict_indexescase already uses this idiom; larger counts collide with other metadata.inflate_row_countis 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 2048where the old one reported the envelope error, all nine cases still assertINCORRECT_DATAagainst an unchanged.reference, and 50/50 randomized runs pass.04358and04410still cover the envelope check.The fixture also becomes reader-agnostic, which matters for the in-flight
arrow25.0.0 backports (#113539, #113541, #113542): under arrow 25 the old fixture dies at the IO layer withFile too short, while the new one is read and then rejected for the undersized bool buffer.Version info
26.6.3.16,26.5.7.19,26.3.18.10