Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lang/c/src/datafile.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,12 +451,24 @@ static int file_read_block_count(avro_file_reader_t r)
"Cannot read file block count: ");
check_prefix(rval, enc->read_long(r->reader, &len),
"Cannot read file block size: ");
if (len < 0) {
avro_set_error("Invalid block size: %" PRId64, len);
return EINVAL;
}
Comment on lines +454 to +457
Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a regression test that verifies the negative block size validation. While the fix was verified with AddressSanitizer fuzzing, a unit test with a malformed Avro file containing a negative block size would help prevent regressions. This could follow the pattern of other test files like test_avro_1237.c which test handling of malformed Avro files.

Copilot uses AI. Check for mistakes.

if (r->current_blockdata && len > r->current_blocklen) {
r->current_blockdata = (char *) avro_realloc(r->current_blockdata, r->current_blocklen, len);
if (!r->current_blockdata) {
avro_set_error("Cannot allocate block buffer");
return ENOMEM;
}
r->current_blocklen = len;
} else if (!r->current_blockdata) {
r->current_blockdata = (char *) avro_malloc(len);
if (!r->current_blockdata && len > 0) {
avro_set_error("Cannot allocate block buffer");
return ENOMEM;
}
r->current_blocklen = len;
}

Expand Down