Skip to content

Conversation

@OwenSanzas
Copy link

Summary

Fix missing validation for negative length values in read_bytes() and read_string() functions in encoding_binary.c.

Problem

The read_long() function uses zigzag encoding which can decode to negative numbers from malicious input. 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

Changes

  • Add len < 0 check in read_bytes() before allocation
  • Add str_len < 0 check in read_string() 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 0xffffffffffffffe9
    #1 in read_string encoding_binary.c:179

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

Generated with Claude Code

The read_bytes() and read_string() functions in encoding_binary.c
decode length values using zigzag encoding, which can produce negative
numbers from malicious input. These negative values were passed directly
to avro_malloc(), causing allocation failures or undefined behavior.

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

Bug: Negative length values from varint decoding cause
     allocation-size-too-big when cast to size_t

Impact: DoS via crafted binary input

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