Repository navigation
Reject a data file block header declaring a negative count - #33
Merged
Merged
Conversation
DataFileReaderBase::readDataBlock zigzag-decodes the block's object count and byte count straight off the wire and checked neither. A corrupted header can make both negative, and each fails in its own way: hasMore() tested the object count with `!= 0` while decr() only decrements, so a negative count never reached zero and the reader reported rows without end; a negative byte count wrapped in the cast to size_t into an effectively unbounded payload limit, letting the block read run past its own end. The spec has both as non-negative, so reject them where they are read. hasMore() now tests `> 0` and throws on a negative count, so a caller that decrements without asking fails there instead of looping. Reported as a non-terminating `SELECT count()` over a corrupted Avro file in ClickHouse/ClickHouse#115437; the same block header is parsed for Iceberg manifest deserialization. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Member
Author
|
@Avogar @scanhex12 very easy to review |
Member
Author
|
Going to merge, feel free to revert later on |
groeneai
added a commit
to groeneai/ClickHouse
that referenced
this pull request
Aug 25, 2026
ClickHouse/avro#33 rejects a data file block header declaring a negative object or byte count, and hardens hasMore() to test > 0 instead of != 0. That removes the non-termination on a negative declared count at the layer that owns the header, so termination no longer depends on the caller asking before it decrements. The test asserts the error class instead of one message, because the rejection can now come either from the library at the block header or from the read path when the payload runs out. It gains a negative declared byte count case, which the existing fixtures could not reach because the block helper hardcoded a byte count of zero. A block with a corrupted declared count is also a block that runs out of input, so the class assertion alone cannot tell the header check from payload exhaustion. Both negative counts therefore also assert the header diagnostic by name, on both settings. Measured on this tree, the same test file on three binaries: - with the bump and no count shortcut: passes. - without the bump: 12 lines differ, including all four header diagnostics and the negative object count reaching the query deadline. - with the bump and the count shortcut restored: 2 lines differ, the oversized declared count still answering 1000005000 from the header.
PedroTadim
added a commit
that referenced
this pull request
Sep 21, 2026
The test declared a six-long record and then wrote a single uint32_t through it, so the header promised at least six bytes per record over a four-byte payload. Since #34 the reader cross-checks a block's declared object count against the payload it carries, and rejects that file: Object count 1 in block header cannot fit in 4 payload byte(s) for this schema Rejecting it is the check working - the file is internally inconsistent - so fix the test rather than the check. Write a conforming record through the Pair/GenericRecord idiom the rest of the file already uses. All six doc assertions, which are what the test is for, are unchanged. Bisected by running this suite in isolation: it passes at 7b7f6a5 and at f2d65e1 (#33) and fails from 57985a1 (#34) on. Isolation was needed because boost aborts the run at the first fatal error, and an unrelated test0/testWrite segfault on those older commits - fixed since - hides this one. DataFileTests is now 69/69. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
DataFileReaderBase::readDataBlock zigzag-decodes the block's object count and byte count straight off the wire and checked neither. A corrupted header can make both negative, and each fails in its own way: hasMore() tested the object count with
!= 0while decr() only decrements, so a negative count never reached zero and the reader reported rows without end; a negative byte count wrapped in the cast to size_t into an effectively unbounded payload limit, letting the block read run past its own end.The spec has both as non-negative, so reject them where they are read. hasMore() now tests
> 0and throws on a negative count, so a caller that decrements without asking fails there instead of looping.Reported as a non-terminating
SELECT count()over a corrupted Avro file in ClickHouse/ClickHouse#115437; the same block header is parsed for Iceberg manifest deserialization.Make sure you have checked all steps below.
Jira
Tests
Commits
Documentation