iemejia opened a new pull request, #3849:
URL: https://github.com/apache/avro/pull/3849

   ## What is the purpose of the change
   
   `GenericReader::read()` decodes arrays and maps by calling
   `r.resize(r.size() + m)`, where `m` is the block count returned by
   `Decoder::arrayStart()` / `mapStart()` / `arrayNext()` / `mapNext()`. 
Because the
   block count is read from the (potentially untrusted or truncated) input, a 
very
   large or malformed count could eagerly allocate an unbounded vector before 
any
   element is read (items such as `null` occupy no bytes on the wire).
   
   This validates the block count — per block and cumulatively — against a
   configurable maximum before resizing, 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. Exceeding it throws an
   `avro::Exception` before allocating.
   
   This is part of the umbrella issue AVRO-4277.
   
   ## Verifying this change
   
   This change added tests and can be verified as follows:
   
   - Added `testArrayBlockCountIsBounded` and `testMapBlockCountIsBounded` in
     `lang/c++/test/CodecTests.cc` 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: `ctest -R CodecTests` (852 cases pass)
   
   ## 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]

Reply via email to