iemejia commented on code in PR #3846:
URL: https://github.com/apache/avro/pull/3846#discussion_r3564349313
##########
lang/php/lib/Datum/AvroIODatumReader.php:
##########
@@ -43,10 +43,37 @@
*/
class AvroIODatumReader
{
+ /**
+ * Default upper bound on the number of items in a single decoded array or
+ * map. The block count of an array or map is read from the (potentially
+ * untrusted or truncated) input and drives allocation of the resulting
+ * collection. Reading a collection that declares more items than this
limit
+ * throws an {@see AvroIOCollectionSizeException} instead of attempting a
+ * potentially huge allocation. Mirrors the Java SDK's collection item
limit.
+ */
+ public const DEFAULT_MAX_COLLECTION_ITEMS = 2147483639; // 2^31 - 8
Review Comment:
Fixed in 175b42fecd. The value 2147483639 is intentional (it matches Java's
`Integer.MAX_VALUE - 8`); corrected the misleading `2^31 - 8` comment
accordingly.
##########
lang/php/lib/Datum/AvroIODatumReader.php:
##########
@@ -290,6 +317,7 @@ public function readArray(
$blockCount = -$blockCount;
$decoder->readLong(); // Read (and ignore) block size
}
+ $this->checkCollectionItems(count($items), $blockCount);
for ($i = 0; $i < $blockCount; $i++) {
Review Comment:
Good catch — fixed in 175b42fecd. `readArray` now uses a loose comparison
(`0 != $blockCount`) so the loop terminates when `readLong()` returns a numeric
string under GMP on 32-bit, matching `readMap`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]