Skip to content

Conversation

@OwenSanzas
Copy link

Summary

Fix missing validation for negative block size values in file_read_block_count() function in datafile.c.

Problem

The block size is read using zigzag encoding which can decode to negative numbers from malicious Avro container files. These negative values were passed directly to avro_malloc(), causing:

  • allocation-size-too-big when negative int64_t is cast to size_t
  • Potential crash or undefined behavior when opening malformed .avro files

Changes

  • Add len < 0 check in file_read_block_count() before allocation
  • Return EINVAL with descriptive error message on invalid input

Testing

Verified with AddressSanitizer fuzzing - crash no longer reproduces.

# Before fix:
==ERROR: AddressSanitizer: requested allocation size 0xffffffffffffffff
    #1 in file_read_block_count datafile.c:459

# After fix:
No crash - invalid input rejected with error

Generated with Claude Code

The file_read_block_count() function in datafile.c reads block size
using zigzag encoding, which can produce negative numbers from
malicious Avro container files. These negative values were passed
directly to avro_malloc(), causing allocation failures.

This patch adds validation to reject negative block size values with
a clear error message before attempting memory allocation.

Bug: Negative block size from varint decoding causes
     allocation-size-too-big when cast to size_t

Impact: DoS via crafted .avro file

Co-Authored-By: Claude <[email protected]>
@github-actions github-actions bot added the C label Jan 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant