Skip to content

Bound declared object count by a schema-derived minimum record size - #34

Merged
alexey-milovidov merged 1 commit into
masterfrom
fix-badcount-readblock
Sep 19, 2026
Merged

alexey-milovidov merged 1 commit into
masterfrom
fix-badcount-readblock

Conversation

@PedroTadim

Copy link
Copy Markdown
Member

readDataBlock() already rejects a negative object/byte count, but a positive count larger than the payload could actually hold was still accepted at the header, letting a caller's header-only count shortcut report an invented row total instead of erroring.

Walk the schema once per file to compute a lower bound on how many bytes a single record can encode to, and reject a block whose declared object count cannot fit in the available bytes for NULL_CODEC (exact payload size) and SNAPPY_CODEC (decompressed eagerly above). Every case the bound can't determine returns 0, which only relaxes the check and never rejects a legitimate file.

ZSTD/deflate decompress lazily and are not covered by this check.

Make sure you have checked all steps below.

Jira

Tests

  • My PR adds the following unit tests OR does not need testing for this extremely good reason:

Commits

  • My commits all reference Jira issues in their subject lines. In addition, my commits follow the guidelines from "How to write a good git commit message":
    1. Subject is separated from body by a blank line
    2. Subject is limited to 50 characters (not including Jira issue reference)
    3. Subject does not end with a period
    4. Subject uses the imperative mood ("add", not "adding")
    5. Body wraps at 72 characters
    6. Body explains "what" and "why", not "how"

Documentation

  • In case of new functionality, my PR adds documentation that describes how to use it.
    • All the public functions and the classes in the PR contain Javadoc that explain what it does

readDataBlock() already rejects a negative object/byte count, but a
positive count larger than the payload could actually hold was still
accepted at the header, letting a caller's header-only count shortcut
report an invented row total instead of erroring.

Walk the schema once per file to compute a lower bound on how many
bytes a single record can encode to, and reject a block whose declared
object count cannot fit in the available bytes for NULL_CODEC (exact
payload size) and SNAPPY_CODEC (decompressed eagerly above). Every
case the bound can't determine returns 0, which only relaxes the check
and never rejects a legitimate file.

ZSTD/deflate decompress lazily and are not covered by this check.
@alexey-milovidov alexey-milovidov self-assigned this Sep 19, 2026
@alexey-milovidov
alexey-milovidov merged commit 57985a1 into master Sep 19, 2026
@PedroTadim
PedroTadim deleted the fix-badcount-readblock branch September 21, 2026 12:47
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants