ShivanshhhG opened a new pull request, #19210:
URL: https://github.com/apache/iceberg/pull/19210
Addresses #18505.
## Problem
When parsing a REST file scan task with `delete-file-references`,
`RESTFileScanTaskParser.fromJson` validates the upper bound of reference
indices against the delete file count:
```java
Preconditions.checkArgument(
indices.isEmpty() || Collections.max(indices) < allDeleteFiles.size(),
...);
```
However, the lower bound is not validated. If a server returns negative
indices (such as `"delete-file-references": [-1]`), the check passes because
`-1 < allDeleteFiles.size()`. Later, when mapping references via
`allDeleteFiles::get`, an `IndexOutOfBoundsException: index (-1) must not be
negative` is thrown, obscuring the malformed server response.
## Fix
Validate that all reference indices satisfy `0 <= index <
allDeleteFiles.size()` when non-empty:
```java
Preconditions.checkArgument(
indices.isEmpty()
|| (Collections.min(indices) >= 0
&& Collections.max(indices) < allDeleteFiles.size()),
"Invalid delete file references: %s, expected 0 <= indices < %s",
indices,
allDeleteFiles.size());
```
## Validation
- Added unit tests in `TestPlanTableScanResponseParser.java` verifying:
- Negative reference without delete files (e.g. `[-1]` when count is 0)
throws `IllegalArgumentException: Invalid delete file references: [-1],
expected 0 <= indices < 0`
- Negative reference with delete files (e.g. `[-1]` when count is 1)
throws `IllegalArgumentException: Invalid delete file references: [-1],
expected 0 <= indices < 1`
- Mixed references containing a negative index (e.g. `[0, -1]`) throws
`IllegalArgumentException: Invalid delete file references: [0, -1], expected 0
<= indices < 1`
- Out of bounds upper index (e.g. `[1]` when count is 1) throws
`IllegalArgumentException: Invalid delete file references: [1], expected 0 <=
indices < 1`
- Executed `./gradlew :iceberg-core:test --tests
org.apache.iceberg.rest.responses.TestPlanTableScanResponseParser` (passed).
- Executed `./gradlew :iceberg-core:test --tests
"org.apache.iceberg.rest.*"` (passed).
- Executed `./gradlew :iceberg-core:spotlessCheck` (passed).
--
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]