Copilot commented on code in PR #3864:
URL: https://github.com/apache/avro/pull/3864#discussion_r3566958136
##########
lang/perl/lib/Avro/BinaryDecoder.pm:
##########
@@ -296,13 +504,18 @@ sub decode_map {
my $block_count = decode_long($class, @_);
my $writer_values = $writer_schema->values;
my $reader_values = $reader_schema->values;
+ # A map key is a non-empty string (decode_map rejects empty keys below), so
+ # its minimum on-wire size is 2 bytes: a 1-byte length prefix plus at least
+ # 1 byte of key data, in addition to the value.
+ my $min_bytes = 2 + _min_bytes_per_element($writer_values);
while ($block_count) {
my $block_size;
if ($block_count < 0) {
$block_count = -$block_count;
$block_size = decode_long($class, @_);
## XXX we can skip with $reader_schema?
}
+ _ensure_collection_available($reader, scalar(keys %hash),
$block_count, $min_bytes);
for (1..$block_count) {
Review Comment:
_ensure_collection_available() is using scalar(keys %hash) as the "existing"
element count for maps. This undercounts when the input contains duplicate keys
(later entries overwrite earlier ones), which can let a multi-block map exceed
the structural/zero-byte cumulative caps without being rejected. Track the
number of decoded map entries separately and use that counter for the
cumulative 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]