Copilot commented on code in PR #3861:
URL: https://github.com/apache/avro/pull/3861#discussion_r3567380249
##########
lang/py/avro/io.py:
##########
@@ -832,23 +1016,37 @@ def read_map(self, writers_schema:
avro.schema.MapSchema, readers_schema: avro.s
The actual count in this case
is the absolute value of the count written.
"""
- read_items = {}
+ read_items: Dict[str, object] = {}
+ # Map keys are strings (>= 1 byte length prefix) plus the value.
+ min_bytes = 1 + _min_bytes_per_element(writers_schema.values)
+ zero_byte_limit, structural_limit = _collection_limits()
block_count = decoder.read_long()
while block_count != 0:
if block_count < 0:
block_count = -block_count
decoder.skip_long()
+ self._ensure_collection_available(decoder, len(read_items),
block_count, min_bytes, zero_byte_limit, structural_limit)
Review Comment:
`read_map()` passes `len(read_items)` into `_ensure_collection_available()`,
but `len(read_items)` counts only unique keys. Avro maps can legally contain
duplicate keys (later entries overwrite earlier ones), so this can undercount
the number of decoded key/value pairs and allow the structural limit to be
exceeded (especially for non-seekable decoders where the bytes-remaining check
can’t run). Track a separate cumulative `items_read` counter (like `skip_map()`
does) and use that for the limit check.
--
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]