Skip to content

AVRO-4325: [Trevni] Validate column-file header counts and lengths before allocating - #3921

Open
iemejia wants to merge 1 commit into
apache:mainfrom
iemejia:AVRO-4325-trevni-header-validation
Open

AVRO-4325: [Trevni] Validate column-file header counts and lengths before allocating#3921
iemejia wants to merge 1 commit into
apache:mainfrom
iemejia:AVRO-4325-trevni-header-validation

Conversation

@iemejia

@iemejia iemejia commented Aug 5, 2026

Copy link
Copy Markdown
Member

What changes were proposed in this pull request?

The Trevni readers sized several allocations directly from values read from the file header/metadata without validating them against the input actually available. For a malformed, corrupted, or truncated file these counts/lengths could greatly exceed the bytes present, driving oversized allocations, or overflow to a negative size.

This adds a shared InputBuffer.remaining() / InputBuffer.checkLength(count, minBytesPerElement) helper that rejects a negative value and any value that could not be backed by the bytes remaining, and applies it to the reader paths that size allocations from header/metadata values:

  • ColumnFileReader.readHeader — column count
  • ColumnDescriptor.ensureBlocksRead — block count
  • InputBuffer.readBytes / readString — length-prefixed byte arrays
  • ColumnValues.startBlock — compressed block size; this path now also uses Math.addExact for the + checksum.size() addition to guard against integer overflow.

Reading a malformed file now fails fast with a clear IOException; valid files read unchanged.

How was this patch tested?

  • New test in TestColumnFile:
    • oversizedColumnCountIsRejected — a file whose header column count is overwritten with Integer.MAX_VALUE now fails fast instead of attempting a large allocation.
  • Full trevni-core module test suite passes.

JIRA

The Trevni readers sized several allocations directly from values read from the
file header/metadata without validating them against the input available. For a
malformed, corrupted, or truncated file these counts/lengths could greatly
exceed the bytes present, driving oversized allocations, or overflow to a
negative size.

Add a shared InputBuffer.checkLength/remaining helper that rejects a negative
value and one that could not be backed by the bytes remaining, and apply it to:
- ColumnFileReader.readHeader (column count)
- ColumnDescriptor.ensureBlocksRead (block count)
- InputBuffer.readBytes/readString (length-prefixed byte arrays)
- ColumnValues.startBlock (compressed block size), which now also uses
  Math.addExact for the checksum size to guard against integer overflow.

Reading a malformed file now fails fast with a clear IOException; valid files
read unchanged.
@github-actions github-actions Bot added the Java Pull Requests for Java binding label Aug 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Java Pull Requests for Java binding

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant