Skip to content

Commit 2db3fd1

Browse files
committed
AVRO-4298: [php] Reject negative block size on negative array/map blocks
Addresses review feedback: when decoding a negative array or map block count, the subsequent block-size long was read and ignored without validation. Avro binary encoding specifies block size as a byte count, so a negative value is malformed. Reject it early to match skipArray/skipMap and prevent malformed input from proceeding further than necessary. Assisted-by: GitHub Copilot:claude-opus-4.8
1 parent 542afad commit 2db3fd1

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

lang/php/lib/Datum/AvroIODatumReader.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,10 @@ public function readArray(
317317
throw new AvroException('Invalid array block count');
318318
}
319319
$blockCount = -$blockCount;
320-
$decoder->readLong(); // Read (and ignore) block size
320+
$blockSize = $decoder->readLong(); // block byte-size
321+
if ($blockSize < 0) {
322+
throw new AvroException('Invalid negative array block size');
323+
}
321324
}
322325
self::ensureCollectionAvailable($decoder, count($items), $blockCount, $minBytes);
323326
for ($i = 0; $i < $blockCount; $i++) {
@@ -353,8 +356,10 @@ public function readMap(
353356
throw new AvroException('Invalid map block count');
354357
}
355358
$pair_count = -$pair_count;
356-
// Note: we're not doing anything with block_size other than skipping it
357-
$decoder->readLong();
359+
$blockSize = $decoder->readLong(); // block byte-size
360+
if ($blockSize < 0) {
361+
throw new AvroException('Invalid negative map block size');
362+
}
358363
}
359364

360365
// Map keys are strings (>= 1 byte length prefix) plus the value.

0 commit comments

Comments
 (0)