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


##########
lang/perl/t/03_bin_decode.t:
##########
@@ -84,6 +84,68 @@ EOJ
     is $dec, "a", "Binary_Encodings.Complex_Types.Unions-a";
 }
 
+## union and enum index bounds
+{
+    my $union = Avro::Schema->parse(q(["string","null"]));
+    # Index 2 (zig-zag long 0x04) is out of range for a 2-branch union.

Review Comment:
   The union branch index is encoded as an int per the Avro spec (and 
BinaryDecoder.pm’s own comment in decode_union). This test comment says 
“zig-zag long”, which is misleading even though the decoder currently reads it 
via decode_long().



##########
lang/perl/t/03_bin_decode.t:
##########
@@ -84,6 +84,68 @@ EOJ
     is $dec, "a", "Binary_Encodings.Complex_Types.Unions-a";
 }
 
+## union and enum index bounds
+{
+    my $union = Avro::Schema->parse(q(["string","null"]));
+    # Index 2 (zig-zag long 0x04) is out of range for a 2-branch union.
+    open my $reader, '<', \"\x04" or die "Can't open memory file: $!";
+    throws_ok {
+        Avro::BinaryDecoder->decode(
+            writer_schema => $union,
+            reader_schema => $union,
+            reader        => $reader,
+        );
+    } 'Avro::Schema::Error::Parse', "union branch index out of range is 
rejected";
+
+    # Index -1 (zig-zag long 0x01) must not wrap to a valid branch.

Review Comment:
   Similarly, this comment refers to the union index as a “zig-zag long”, but 
union branch indexes are encoded as ints. Keeping the wording consistent with 
the spec makes the test easier to reason about.



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