charliec05 commented on code in PR #17963:
URL: https://github.com/apache/iceberg/pull/17963#discussion_r3939028873


##########
core/src/main/java/org/apache/iceberg/io/SingleBufferInputStream.java:
##########
@@ -82,6 +83,7 @@ public int read(byte[] bytes, int off, int len) throws 
IOException {
 
   @Override
   public void seek(long newPosition) throws IOException {
+    Preconditions.checkArgument(newPosition >= 0, "Position is negative: %s", 
newPosition);

Review Comment:
   `newPosition` is supplied by the caller through the public 
`ByteBufferInputStream.wrap(...).seek(...)` API. I have not identified a 
production call path that supplies a negative offset; I found this while 
testing invalid seek inputs.
   
   On the base revision, after reading the first byte and then calling 
`seek(-1)`, `SingleBufferInputStream` throws `IllegalArgumentException` but has 
already reset its position to 0, while `MultiBufferInputStream` accepts the 
call and also resets to 0. I reproduced both cases: the next read returns the 
first byte again. With this change, both reject the invalid offset while 
keeping position 1, and the next read returns the second byte.
   
   The motivation is defensive validation before mutating stream state, 
consistent with the existing negative-seek guards in `EagerInputStream`, 
`S3InputStream`, and `GCSInputStream`. The shared regression test checks 
rejection and position preservation for both implementations.
   



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to