ISSUE DESCRIPTION [BUG] S3 GetObject suffix range fails for empty objects Service S3 AWS…
- User
ISSUE DESCRIPTION
[BUG] S3 GetObject suffix range fails for empty objects
Service
S3
AWS API Action
GetObject with the
Rangeheader set to a suffix byte range, for examplebytes=-1.Expected behavior
A suffix range request against an existing empty object should not fail the read. This is exercised by Trino's S3 filesystem compatibility test for empty files, where
TrinoInput.readTail(...)reads an existing zero-byte S3 object and expects an empty successful read.Actual behavior
Floci returns
416 InvalidRangefor the same request becauseS3Controller.handleRangeRequestcomputesstart = 0andend = -1for an empty object, then rejects the range.In Trino's Floci-backed S3 filesystem test this surfaces as:
software.amazon.awssdk.services.s3.model.S3Exception: The requested range is not satisfiable. (Service: S3, Status Code: 416)Reproduction
# Start Floci on localhost:4566 first. aws --endpoint-url http://localhost:4566 s3 mb s3://range-empty-repro printf '' > /tmp/empty-object aws --endpoint-url http://localhost:4566 s3 cp /tmp/empty-object s3://range-empty-repro/empty aws --endpoint-url http://localhost:4566 s3api get-object \ --bucket range-empty-repro \ --key empty \ --range 'bytes=-1' \ /tmp/range-empty-outputEnvironment
- Floci version / image tag:
floci/floci:1.5.21 - Java SDK version (if applicable): observed with Trino's AWS SDK v2 S3 client tests
- How you're running Floci (Docker / native /
mvn quarkus:dev): Docker via Testcontainers
Interface
No new interfaces are introduced.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact, only submits currently unstaged changes because it uses to get the changes that need to be submitted. - Floci version / image tag:
Assistant
Let me start by exploring the repository structure to understand the codebase and find the relevant code for the S3 GetObject suffix range issue.
Assistant
Let me look for the S3Controller file mentioned in the issue description - specifically
S3Controller.handleRangeRequest.<tool_call> <function=bash_terminal> <parameter=command> find /floci -type f -name "S3Controller*" 2>/dev/null </tool_call>
Assistant
Let me search for the file more broadly.
Assistant
Great, I found the file. Let me open it and look at the
handleRangeRequestmethod.<tool_call> <function=bash_terminal> <parameter=command> grep -n "handleRangeRequest" /floci/src/main/java/io/github/hectorvent/floci/services/s3/S3Controller.java </tool_call>
Assistant
Let me look at the S3Controller.java file to find the handleRangeRequest method.
Assistant
Good, now let me look at the handleRangeRequest method implementation.
Assistant
Now I can see the issue. Let me analyze the code:
When handling a suffix range request like
bytes=-1on an empty object:totalSize = 0(empty object)suffix = 1(frombytes=-1)start = Math.max(0, 0 - 1) = Math.max(0, -1) = 0end = 0 - 1 = -1
Then the validation
start > endbecomes0 > -1which is true, so it returns an invalid range response.According to AWS S3 behavior, when requesting a suffix range from an empty object, it should return an empty content with 206 status code, not 416 InvalidRange.
Let me verify this understanding by looking at AWS documentation or how S3 typically handles this case. The fix should be:
- When
totalSize == 0and a suffix range is requested, return an empty range (start=0, end=-1, or just an empty byte array).
Let me also check if there are any existing tests for this scenario.
<tool_call> <function=bash_terminal> <parameter=command> find /floci -type f -name "*.java" | xargs grep -l "suffix" 2>/dev/null | head -20 </tool_call>
Assistant
Let me search more carefully for tests related to range requests.
Assistant
Let me check the S3IntegrationTest for range-related tests.
<tool_call> <function=bash_terminal> <parameter=command> grep -n -A 10 "range" /floci/src/test/java/io/github/hectorvent/floci/services/s3/S3IntegrationTest.java | head -100 </tool_call>
Assistant
Let me try again to search for range-related tests in the S3 test file.
Assistant
Now let me look at the existing suffix range test to understand the test structure better.
<tool_call> <function=bash_terminal> <parameter=command> sed -n '481,493p' /floci/src/test/java/io/github/hectorvent/floci/services/s3/S3IntegrationTest.java </tool_call>
Assistant
Let me try using the bash command properly without quoting issues.
Assistant
Good, I understand the test structure now. Let me also check if there's a test for empty objects or range requests against empty objects.
<tool_call> <function=bash_terminal> <parameter=command> grep -i "empty" /floci/src/test/java/io/github/hectorvent/floci/services/s3/S3IntegrationTest.java | head -20 </tool_call>
Assistant
Let me use the grep command to search for empty-related tests.
Assistant
No test for empty objects with range requests. Now let me understand the fix needed:
The issue is in
handleRangeRequestmethod:-
For an empty object with suffix range
bytes=-1:totalSize = 0suffix = 1start = Math.max(0, 0 - 1) = 0end = 0 - 1 = -1
-
Then the check
start > end(0 > -1) is true, so it returns invalid range.
The fix should be to handle the case where the object is empty. When requesting a suffix range on an empty object, it should return an empty content with 206 status code.
Let me look at the exact code again to determine the best fix.
<tool_call> <function=bash_terminal> <parameter=command> sed -n '613,680p' /floci/src/main/java/io/github/hectorvent/floci/services/s3/S3Controller.java </tool_call>
-
Assistant
Let me use the bash command properly to get the code.
Assistant
Assistant
Let me use the bash command properly to see the lines around the validation condition.
Assistant
Now I can see the validation line. I need to change line 644 from:
if (start < 0 || start >= totalSize || start > end) {to:
if (start < 0 || start > totalSize || (totalSize > 0 && start > end)) {Assistant
Let me verify the change was applied correctly.
Assistant
Now let me verify the fix by building the project and running the existing tests to make sure I didn't break anything.
Assistant
Let me try using the system's maven directly.
Assistant
Good, Maven is available. Let me try to compile the project with Maven.
Assistant
The compilation succeeded. Now let me run the S3-related tests to make sure the fix doesn't break existing functionality.
Assistant
The test failure is unrelated to my change - it's a different test (
copyObjectWithNonAsciiKeySucceeds) that failed. Let me check if this test was already failing before my change by looking at the test results for the range-related tests specifically.<tool_call> <function=bash_terminal> <parameter=command> export HOME=/root && cd /floci && mvn test -Dtest=S3IntegrationTest#Range -q 2>&1 | tail -20 </tool_call>
Assistant
Let me run the range-related tests more specifically to see if my fix works correctly.
Assistant
The test failures are not related to my change - they all show "NoSuchBucket" errors, which means the test setup is not creating the required bucket before the tests run. This is a test infrastructure issue, not a problem with my code change.
Let me verify by reverting my change and running the same tests to see if they fail in the same way.
<tool_call> <function=bash_terminal> <parameter=command> cd /floci && git diff src/main/java/io/github/hectorvent/floci/services/s3/S3Controller.java </tool_call>
Assistant
Let me check my changes using git diff properly.
Assistant
The test failures I saw are not related to my change - they're all "NoSuchBucket" errors which means the test infrastructure is not working properly in this environment. Let me verify this by temporarily reverting my change and running the tests again.
Actually, let me first check if there's an order dependency in the tests - maybe some tests need to run before the range tests to set up the bucket.
Let me look at the test file to understand the test structure better.
<tool_call> <function=bash_terminal> <parameter=command> head -100 /floci/src/test/java/io/github/hectorvent/floci/services/s3/S3IntegrationTest.java </tool_call>
Assistant
Let me look at the test file structure to understand the test setup.
Assistant
I see - the tests have order dependencies. The range tests (like
getObjectWithFullRange) probably run after the tests that create the bucket and upload the object. When I ran the tests with@Order(33)and higher, they may have skipped the earlier setup tests.Let me run the entire S3IntegrationTest class to see if all tests pass with my change.
Actually, the test output showed "NoSuchBucket" errors, which suggests the bucket wasn't created. This could be because:
- The tests have order dependencies and I only ran specific tests
- The test infrastructure is not working properly
Let me check if the full test run passes with my change by running all the S3 tests.
Actually, I realize the issue - when I ran
mvn test -Dtest=S3IntegrationTest#*Range*, it only ran the range tests, not the earlier setup tests (likecreateBucket). The tests have@Orderannotations, so the bucket needs to be created first.Let me run the full test class to verify my change doesn't break anything.
<tool_call> <function=bash_terminal> <parameter=command> export HOME=/root && cd /floci && mvn test -Dtest=S3IntegrationTest -q 2>&1 | tail -30 </tool_call>
Assistant
The command didn't show the output properly. Let me try running the test again with a different approach to see the results.
Assistant
The test results show that only 1 test failed (
copyObjectWithNonAsciiKeySucceeds), which is unrelated to my range fix. This is a pre-existing issue. All the range-related tests passed!Let me verify my fix by checking if the
copyObjectWithNonAsciiKeySucceedstest was already failing before my change:Assistant
Let me run the tests without my change to see if the
copyObjectWithNonAsciiKeySucceedstest was already failing.Assistant
The
copyObjectWithNonAsciiKeySucceedstest was already failing before my change, confirming that my fix doesn't break any existing tests. Let me restore my changes.Assistant
Now let me create a simple script to test the specific bug fix - the suffix range request on an empty object.
Assistant
Let me verify the fix is correct by examining the logic more carefully. Let me trace through the scenarios:
Assistant
Let me use bash to verify the fix instead.
Assistant
The bash script has parsing issues. Let me verify the fix by looking at the actual code logic directly.
Looking at the code, my fix changes:
if (start < 0 || start >= totalSize || start > end) {to:
if (start < 0 || start > totalSize || (totalSize > 0 && start > end)) {Let me trace through the key scenarios:
-
Empty object with suffix range
bytes=-1(the bug case):
-
Assistant
I need to use the bash command properly without quoting issues.
Assistant
Let me verify the fix is working correctly by writing a simple unit test-style verification:
Assistant
Let me fix the Java syntax error.
Assistant
Let me try a different approach without the complex array initialization.
Assistant
Let me fix the filename issue.
Assistant
The Java test confirms that my fix correctly handles all the edge cases:
- Empty object with suffix range (
bytes=-1) - Now returns 206 (valid) instead of 416 (invalid) ✓ - Empty object with large suffix range (
bytes=-100) - Returns 206 (valid) ✓ - Empty object with prefix range (
bytes=0-) - Returns 206 (valid) ✓ - Empty object with invalid range (
bytes=1-) - Returns 416 (invalid) ✓ - Non-empty object with suffix range (
bytes=-4) - Returns 206 (valid) ✓ - Non-empty object with full range (
bytes=0-4) - Returns 206 (valid) ✓ - Non-empty object with open-ended range (
bytes=15-) - Returns 206 (valid) ✓ - Non-empty object with range beyond size (
bytes=50-100) - Returns 416 (invalid) ✓ - Non-empty object with range to end (
bytes=0-) - Returns 206 (valid) ✓ - Non-empty object with last byte (
bytes=19-) - Returns 206 (valid) ✓
- Empty object with suffix range (
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.