You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "barry3406 (via GitHub)" <gi...@apache.org> on 2026/04/09 11:38:08 UTC

[PR] API: Fix FileRange validation to reject negative offset/length [iceberg]

barry3406 opened a new pull request, #15926:
URL: https://github.com/apache/iceberg/pull/15926

   ## Summary
   
   - `FileRange` constructor validates `length()` and `offset()` (getters) before assigning fields, so negative inputs bypass validation silently since field defaults are 0
   - Changed to validate constructor parameters directly instead of getters
   - Added `TestFileRange.java` with test cases for negative offset, negative length, null byteBuffer, and valid construction
   
   ## Root Cause
   
   ```java
   // BEFORE — length() returns 0 (field default), not the parameter value
   Preconditions.checkArgument(
       length() >= 0, "Invalid length: %s in range (must be >= 0)", length);
   
   // AFTER — validates the actual parameter
   Preconditions.checkArgument(
       length >= 0, "Invalid length: %s in range (must be >= 0)", length);
   ```
   
   ## Test Plan
   
   - [x] Added `TestFileRange.java` covering negative offset, negative length, null byteBuffer, and valid range
   - [ ] Existing CI tests should pass
   
   Fixes #15922


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] API: Fix FileRange validation to reject negative offset/length [iceberg]

Posted by "huaxingao (via GitHub)" <gi...@apache.org>.
huaxingao commented on PR #15926:
URL: https://github.com/apache/iceberg/pull/15926#issuecomment-4257163402

   Thanks @barry3406 for the PR! Thanks everyone for the review!


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] API: Fix FileRange validation to reject negative offset/length [iceberg]

Posted by "mukund-thakur (via GitHub)" <gi...@apache.org>.
mukund-thakur commented on code in PR #15926:
URL: https://github.com/apache/iceberg/pull/15926#discussion_r3082340929


##########
api/src/main/java/org/apache/iceberg/io/FileRange.java:
##########
@@ -31,10 +31,8 @@ public class FileRange {
   public FileRange(CompletableFuture<ByteBuffer> byteBuffer, long offset, int length)
       throws EOFException {

Review Comment:
   created a pr to remove this https://github.com/apache/iceberg/pull/15973. Please take a look. Thanks. 



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] API: Fix FileRange validation to reject negative offset/length [iceberg]

Posted by "barry3406 (via GitHub)" <gi...@apache.org>.
barry3406 commented on code in PR #15926:
URL: https://github.com/apache/iceberg/pull/15926#discussion_r3067727972


##########
api/src/main/java/org/apache/iceberg/io/FileRange.java:
##########
@@ -31,10 +31,8 @@ public class FileRange {
   public FileRange(CompletableFuture<ByteBuffer> byteBuffer, long offset, int length)
       throws EOFException {

Review Comment:
   yep, nothing in the body throws it. `ParquetIO.convertRanges` catches `EOFException` around `new FileRange(...)` though, so the two are coupled — got added together in #13997. figured I'd leave that cleanup outside this one.



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] API: Fix FileRange validation to reject negative offset/length [iceberg]

Posted by "huaxingao (via GitHub)" <gi...@apache.org>.
huaxingao merged PR #15926:
URL: https://github.com/apache/iceberg/pull/15926


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] API: Fix FileRange validation to reject negative offset/length [iceberg]

Posted by "barry3406 (via GitHub)" <gi...@apache.org>.
barry3406 commented on PR #15926:
URL: https://github.com/apache/iceberg/pull/15926#issuecomment-4222130178

   Thanks for the review @huaxingao! Let me know if there's anything else needed on my end before merge — happy to address it.


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] API: Fix FileRange validation to reject negative offset/length [iceberg]

Posted by "anoopj (via GitHub)" <gi...@apache.org>.
anoopj commented on code in PR #15926:
URL: https://github.com/apache/iceberg/pull/15926#discussion_r3066874251


##########
api/src/main/java/org/apache/iceberg/io/FileRange.java:
##########
@@ -31,10 +31,8 @@ public class FileRange {
   public FileRange(CompletableFuture<ByteBuffer> byteBuffer, long offset, int length)
       throws EOFException {

Review Comment:
   This is existing code, but I don't see any place in the constructor that can throw `EOFException`. 



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] API: Fix FileRange validation to reject negative offset/length [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #15926:
URL: https://github.com/apache/iceberg/pull/15926#discussion_r3067125440


##########
api/src/test/java/org/apache/iceberg/io/TestFileRange.java:
##########
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iceberg.io;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.io.EOFException;
+import java.nio.ByteBuffer;
+import java.util.concurrent.CompletableFuture;
+import org.junit.jupiter.api.Test;
+
+public class TestFileRange {
+
+  @Test
+  public void validRange() throws EOFException {
+    CompletableFuture<ByteBuffer> future = new CompletableFuture<>();
+    FileRange range = new FileRange(future, 10L, 100);
+    assertThat(range.offset()).isEqualTo(10L);
+    assertThat(range.length()).isEqualTo(100);
+    assertThat(range.byteBuffer()).isSameAs(future);
+  }
+
+  @Test
+  public void negativeLength() {
+    CompletableFuture<ByteBuffer> future = new CompletableFuture<>();
+    assertThatThrownBy(() -> new FileRange(future, 0L, -1))
+        .isInstanceOf(IllegalArgumentException.class)
+        .hasMessageContaining("Invalid length");

Review Comment:
   the tests should all check for the exact error msg by using `hasMessage(...)`



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] API: Fix FileRange validation to reject negative offset/length [iceberg]

Posted by "barry3406 (via GitHub)" <gi...@apache.org>.
barry3406 commented on code in PR #15926:
URL: https://github.com/apache/iceberg/pull/15926#discussion_r3067694057


##########
api/src/main/java/org/apache/iceberg/io/FileRange.java:
##########
@@ -31,10 +31,8 @@ public class FileRange {
   public FileRange(CompletableFuture<ByteBuffer> byteBuffer, long offset, int length)
       throws EOFException {

Review Comment:
   good catch — you're right, nothing in the constructor throws that. it was leftover from the original file. dropped the `throws` and cleaned up the unreachable try/catch in `ParquetIO.convertRanges` in 8ffa366.



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] API: Fix FileRange validation to reject negative offset/length [iceberg]

Posted by "barry3406 (via GitHub)" <gi...@apache.org>.
barry3406 commented on code in PR #15926:
URL: https://github.com/apache/iceberg/pull/15926#discussion_r3067632497


##########
api/src/test/java/org/apache/iceberg/io/TestFileRange.java:
##########
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iceberg.io;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.io.EOFException;
+import java.nio.ByteBuffer;
+import java.util.concurrent.CompletableFuture;
+import org.junit.jupiter.api.Test;
+
+public class TestFileRange {
+
+  @Test
+  public void validRange() throws EOFException {
+    CompletableFuture<ByteBuffer> future = new CompletableFuture<>();
+    FileRange range = new FileRange(future, 10L, 100);
+    assertThat(range.offset()).isEqualTo(10L);
+    assertThat(range.length()).isEqualTo(100);
+    assertThat(range.byteBuffer()).isSameAs(future);
+  }
+
+  @Test
+  public void negativeLength() {
+    CompletableFuture<ByteBuffer> future = new CompletableFuture<>();
+    assertThatThrownBy(() -> new FileRange(future, 0L, -1))
+        .isInstanceOf(IllegalArgumentException.class)
+        .hasMessageContaining("Invalid length");

Review Comment:
   done, switched to hasMessage with the exact strings



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] API: Fix FileRange validation to reject negative offset/length [iceberg]

Posted by "barry3406 (via GitHub)" <gi...@apache.org>.
barry3406 commented on code in PR #15926:
URL: https://github.com/apache/iceberg/pull/15926#discussion_r3067694057


##########
api/src/main/java/org/apache/iceberg/io/FileRange.java:
##########
@@ -31,10 +31,8 @@ public class FileRange {
   public FileRange(CompletableFuture<ByteBuffer> byteBuffer, long offset, int length)
       throws EOFException {

Review Comment:
   good catch — you're right, nothing in the constructor throws that. it was leftover from the original file. dropped the `throws` and cleaned up the unreachable try/catch in `ParquetIO.convertRanges` in 8ffa366.



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org