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


##########
lang/perl/lib/Avro/BinaryDecoder.pm:
##########
@@ -124,18 +124,130 @@ sub skip_bytes {
     my $class = shift;
     my $reader = pop;
     my $size = decode_long($class, undef, undef, $reader);
-    $reader->seek($size, 0);
+    if ($size < 0) {
+        throw Avro::Schema::Error::Parse(
+            "Invalid negative bytes/string length: $size");
+    }
+    # Skip forward by $size bytes relative to the current position
+    # (SEEK_CUR); whence 0 (SEEK_SET) would incorrectly seek to the
+    # absolute offset $size.
+    $reader->seek($size, 1);
     return;

Review Comment:
   Fixed in 25ab8ab266: skip_bytes now calls _ensure_available before skipping 
(mirroring decode_bytes), so a declared length that exceeds the remaining bytes 
is rejected on a size-reporting reader instead of silently seeking past EOF, 
and a failed seek is treated as fatal.
   
   While here I fixed the same absolute-vs-relative seek bug in two related 
paths that shared it: skip_fixed used seek(size, 0) (SEEK_SET) — now SEEK_CUR — 
and skip_block's negative-count branch ignored the block-size long, did an 
absolute seek of a negative offset, and re-looped on the same count (an 
infinite loop); it now reads the block size and skips it relatively. Added 
tests for skipping fixed/bytes writer fields absent from the reader schema and 
for rejecting an oversized skipped bytes length. Full suite (386 tests) and 
perlcritic pass.



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