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:
textsoftware.amazon.awssdk.services.s3.model.S3Exception: The requested range is not satisfiable. (Service: S3, Status Code: 416)Reproduction
bash# 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 using command. Additionally, you can use and to temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you call ) using or commands. However you don't need to use or before 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 understanding the issue. The bug is about S3 GetObject with a suffix byte range (like
bytes=-1) failing for empty objects. The issue is inS3Controller.handleRangeRequestwhich computesstart = 0andend = -1for an empty object, then rejects the range.Let me first explore the repository structure to understand the codebase.
Assistant
Let me find the S3Controller file since that's what the issue mentions.
Assistant
Let me open the S3Controller file to find the
handleRangeRequestmethod.Assistant
Let me open the S3Controller file and look at the handleRangeRequest method.
Assistant
Now I understand the issue. Let me trace through the logic:
- For an empty object,
totalSize = 0 - For a suffix range like
bytes=-1:start = max(0, 0 - 1) = 0,end = 0 - 1 = -1 - Then
start >= totalSizeevaluates to0 >= 0= true, so it returnsInvalidRange
Let me first look for any existing tests related to this functionality:
- For an empty object,
Assistant
I need to find any existing tests for range requests and understand the codebase better. Let me search for range-related tests.
Assistant
Let me check the S3IntegrationTest.java for existing range tests to understand the test structure.
Assistant
Let me see the test structure and the setup for creating test objects:
Assistant
Now I understand the test structure. Let me first write a reproduction script to confirm the bug, then fix it.
Assistant
Now I have a clear understanding of the issue. Let me analyze the problem:
For an empty object (
totalSize = 0) with a suffix range likebytes=-1:start = max(0, 0 - 1) = 0,end = 0 - 1 = -1- The validation
start >= totalSizeevaluates to0 >= 0 = true - This causes the
InvalidRange(416) response
The fix should handle the case where an empty object receives a suffix range request - it should succeed with an empty body.
Let me first create a reproduction script to confirm the bug:
Assistant
Let me understand the build system first, then create a test script to reproduce the bug.
Assistant
Now let me understand the issue better and look at how tests are run:
Assistant
There seems to be an issue with the mvnw script. Let me try to set HOME and run again.
Assistant
Good, tests run. There's an unrelated test failure. Let me now focus on creating a reproduction and fixing the bug. Let me first write a simple test to reproduce the issue:
Assistant
Now I have a clear understanding. Let me:
- First, create a test script to reproduce the bug
- Then fix the code
- Run the test to confirm the fix works
Let me create a simple reproduction test:
Assistant
Now I understand the issue clearly. For empty objects (
totalSize = 0), a suffix range likebytes=-1computesstart = 0,end = -1, and then the validationstart >= totalSize(0 >= 0) returns true, causing the InvalidRange error.The fix should handle the empty object case. For an empty object, any valid suffix range request should succeed with an empty body. Let me now fix the
handleRangeRequestmethod:Assistant
Now I understand the issue clearly. For an empty object with a suffix range request (e.g.,
bytes=-1):start = max(0, 0 - 1) = 0end = 0 - 1 = -1- The validation
start >= totalSize(0 >= 0) is true, so it fails
The fix should handle empty objects specially: when the object is empty and a suffix range is requested, it should return a successful 206 response with an empty body.
Assistant
The key change needed is in the suffix range branch. When
totalSize == 0, a suffix range request should succeed with an empty body. Let me modify the logic:For the suffix range case (
before.isEmpty()):- If
totalSize == 0, we should return a successful 206 with empty body - If
totalSize > 0, current logic works
Let me update the code to handle this edge case.
- If
Assistant
Now I have a clear understanding of the issue. For an empty object (
totalSize = 0) with a suffix range likebytes=-1:start = max(0, 0 - 1) = 0end = 0 - 1 = -1- The validation
start >= totalSizeevaluates to0 >= 0 = true, causing InvalidRange
The fix needs to handle empty objects specially - suffix range requests on empty objects should succeed with an empty body.
Assistant
I need to specify the file path. Let me use the --file option.
Assistant
I need to use the correct syntax for the edit command. Let me try again with the --file option.
Assistant
I see the edit didn't work correctly - the closing brace and subsequent lines got mixed up. Let me view the current state of the method and fix it properly.
Assistant
The edit got corrupted. Let me restore the file and redo the edit properly.
Assistant
Let me verify the file is restored.
Assistant
Good, the file is restored. Now let me make the edit more carefully. I need to:
- Handle the empty object case specially
- For suffix ranges on empty objects, return success with empty body
- For prefix ranges on empty objects, return InvalidRange
Assistant
I see there's an extra closing brace
}at line 668 that was part of the original code but now causes a syntax error. Let me fix that.Assistant
There are duplicate lines now. Let me restore and start fresh with a cleaner approach.
Assistant
Let me take a different approach using sed to make a precise edit:
Assistant
Now let me use the replace command to replace the validation block with my new logic that handles empty objects:
Assistant
Let me use the proper replace syntax.
Assistant
I need to provide proper arguments for the replace command. Let me try again with the correct syntax.
Assistant
Let me use the proper REPLACE syntax with >>> SEARCH and >>> REPLACE markers.
Assistant
Let me use sed to make the edit instead:
Assistant
I need to replace lines 643-645 (the validation block) with my new logic that handles empty objects. Let me use sed to do this replacement.
Assistant
Let me verify the changes:
Assistant
There's an extra closing brace at line 668. Let me fix that:
Assistant
There's an extra
}on line 668. Let me remove it:Assistant
Let me verify the fix looks correct now:
Assistant
The fix looks correct now. Let me verify the code compiles by running the tests:
Assistant
The issue is that
beforeis declared inside the try block, but my check is outside. Let me fix this by moving the empty object check inside the try block.Assistant
I see the problem -
beforeis declared inside the try block, but my check is outside. Let me fix this by moving the empty object handling inside the try block:Assistant
Let me look at the full method structure again:
Assistant
Now I understand the full structure. The
beforeandaftervariables are declared inside the try block, so I need to place the empty object check inside the try block where those variables are available. Let me do this properly by inserting the empty object check afterbeforeandafterare declared.Assistant
Let me verify the changes look correct now.
Assistant
The code was inserted in the wrong position (inside an if block). Let me restore and fix this properly.
Assistant
Let me view the exact line numbers more carefully and use a more precise edit.
Assistant
I need to insert the empty object handling logic inside the try block, after line 628 (after the empty before/after check) but before line 629 (the before.isEmpty() check for suffix ranges). Let me use sed to insert after line 628.
Assistant
Let me use a Python script to do this replacement more reliably:
Assistant
Let me try using python or perl instead.
Assistant
Perl is available. Let me use it:
Assistant
Let me verify the changes:
Assistant
The perl replacement didn't insert the code. Let me try a different approach - I'll write the replacement to a temporary file and use sed to include it:
Assistant
Let me try a different approach. I'll create a complete replacement for the method using a heredoc.
Assistant
Now let me find the exact line range of the method and replace it:
Assistant
The method
handleRangeRequeststarts at line 613 andinvalidRangeResponsestarts at line 665. So I need to replace lines 613-664 (the handleRangeRequest method).Assistant
Let me verify the changes:
Assistant
The code looks correct now. Let me verify it compiles and run the tests:
Assistant
The code compiles and the tests run. The only failure is
copyObjectWithNonAsciiKeySucceedswhich was already failing before my changes (unrelated bug). Let me verify the range-related tests specifically passed:Assistant
The issue is that
*GetObjectWith*tests depend on other tests that run first (they use@Orderannotation). Let me check the full test results for the range tests:Assistant
The 404 errors are because when running tests individually without their ordering, the bucket/object doesn't exist yet. The full test run with all 98 tests showed only 1 failure which was the pre-existing
copyObjectWithNonAsciiKeySucceedsissue. Let me verify by looking at the range-specific test results from the full run:Assistant
These are all 404s because the tests need to run in order. Let me run the full S3IntegrationTest and look specifically at the range tests:
Assistant
All range-related tests pass (the only failure is the pre-existing
copyObjectWithNonAsciiKeySucceedswhich is unrelated to range requests). Now let me create a test script to specifically verify the empty object suffix range fix:Assistant
The fix is working. All 5 tests passed, confirming that:
- Empty object with suffix range (
bytes=-1) now returns 206 with empty body instead of 416 - Empty object with prefix range still correctly returns 416 InvalidRange
- Empty object with large suffix range also works
Now let me clean up and run the full test suite to ensure nothing is broken:
- Empty object with suffix range (
Assistant
Let me run the existing S3 tests to make sure nothing is broken.
Assistant
The only failure is the pre-existing
copyObjectWithNonAsciiKeySucceedsissue which is unrelated to my changes. All range-related tests pass.Let me also run a broader test to make sure other S3 tests aren't affected:
Assistant
Let me check if this error is related to my changes or pre-existing:
Assistant
This is a pre-existing issue with non-ASCII characters in file paths, not related to my changes. Let me verify by checking git status:
Assistant
Let me view the final diff to confirm the changes are correct:
Assistant
The diff looks correct. I notice there's a minor whitespace change (a blank line was removed). Let me fix that and verify the complete solution:
Assistant
I need to restore the blank line between methods:
Assistant
Now let me verify the final diff looks correct.
Assistant
The diff is now clean. Let me run the tests one final time to confirm everything works:
Assistant
All tests pass except for the pre-existing
copyObjectWithNonAsciiKeySucceedsfailure which is unrelated to my changes. My fix for the empty object suffix range bug is confirmed working.Let me summarize the fix:
Summary
The bug was in
S3Controller.handleRangeRequest()- when an empty object (0 bytes) received a suffix range request likebytes=-1, the method would computestart = 0andend = -1, then reject it asInvalidRange(416) becausestart >= totalSize(0 >= 0) was true.The fix: Added special handling for empty objects inside the try block (where the
before/aftervariables are available):- For suffix ranges (
bytes=-N) on empty objects: Return 206 with an empty body (the expected behavior for reading the "tail" of an empty file) - For prefix ranges (
bytes=N-) on empty objects: Still return 416 InvalidRange (correctly - you can't start reading at byte 0 when there are no bytes)
- For suffix ranges (
Assistant
The user is reminding me that I need to use a tool call. I've completed the fix and verified it works. I should now submit my changes using the submit command.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.