iemejia opened a new pull request, #3846:
URL: https://github.com/apache/avro/pull/3846
## What is the purpose of the change
When decoding an array or map, the block count is read from the input and
drives
allocation of the resulting collection. A very large or malformed block count
(for example from truncated or hostile input) could request an unbounded
allocation, since items such as `null` occupy no bytes on the wire.
This validates the block count — per block and cumulatively — against a
configurable maximum before allocating, mirroring the Java SDK's collection
item
limit (`org.apache.avro.limits.collectionItems.maxLength`, AVRO-3819). The
limit
defaults to `2^31 - 8` items and can be overridden with the
`AVRO_MAX_COLLECTION_ITEMS` environment variable, or per reader via
`AvroIODatumReader::setMaxCollectionItems()`. Exceeding it throws the new
`Apache\Avro\Datum\AvroIOCollectionSizeException`.
This is part of the umbrella issue AVRO-4277.
## Verifying this change
This change added tests and can be verified as follows:
- Added tests in `lang/php/test/IODatumReaderTest.php` covering: a single
block
count above the limit (array and map), a cumulative limit across blocks, a
negative block count bounded by its absolute value, and a within-limit
collection still decoding correctly.
- Run: `composer test` (or `php vendor/bin/phpunit -c lang/php/phpunit.xml
--filter IODatumReaderTest`)
## Documentation
- Does this pull request introduce a new feature? (no — hardening/robustness)
- If yes, how is the feature documented? (not applicable; the new
`AVRO_MAX_COLLECTION_ITEMS` environment variable is documented in code
comments)
--
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]