Copilot commented on code in PR #3864:
URL: https://github.com/apache/avro/pull/3864#discussion_r3567561814


##########
lang/perl/lib/Avro/BinaryDecoder.pm:
##########
@@ -206,7 +371,14 @@ sub decode_enum {
     my ($writer_schema, $reader_schema, $reader) = @_;
     my $index = decode_int($class, @_);
 
-    my $w_data = $writer_schema->symbols->[$index];
+    my $symbols = $writer_schema->symbols;
+    ## A negative or out-of-range index is malformed; reject it before indexing
+    ## (Perl's negative indexing would otherwise select the wrong symbol).
+    if ($index < 0 || $index >= scalar @$symbols) {
+        throw Avro::Schema::Error::Parse(
+            "Enum symbol index $index out of range for " . scalar(@$symbols) . 
" symbols");
+    }

Review Comment:
   decode_enum now rejects negative/out-of-range indexes, but skip_enum (used 
when skipping writer fields absent from the reader schema) still aliases to 
skip_int and will accept invalid indexes. That makes malformed data decode 
successfully under projection even though decoding the enum directly would 
fail; skip_enum should apply the same bounds check.



##########
lang/perl/lib/Avro/BinaryDecoder.pm:
##########
@@ -273,7 +502,8 @@ sub decode_array {
 sub skip_map {
     my $class = shift;
     my ($schema, $reader) = @_;
-    skip_block($reader, sub {
+    # Map entries always carry a >= 1 byte key, so pass a positive minimum.
+    skip_block($reader, 1 + _min_bytes_per_element($schema->values), sub {

Review Comment:
   skip_map currently skips the key via skip_string, which permits a 
zero-length key. However decode_map rejects empty keys ("key of map is 
invalid"), so malformed inputs can be accepted when the map field is skipped 
during projection but rejected when decoded. Skipping should enforce the same 
non-empty-key constraint to keep validation consistent.



-- 
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