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
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 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
I'll start by exploring the repository structure to understand the codebase and locate the relevant S3 range handling code.
Assistant
Let me search for S3-related files, particularly the S3Controller mentioned in the issue.
Assistant
I need to use the correct syntax for the open command.
Assistant
Let me search for the
handleRangeRequestmethod mentioned in the issue:Assistant
Now let me look at the
handleRangeRequestmethod:Assistant
Now I can see the issue! Looking at the
handleRangeRequestmethod:-
For a suffix range like
bytes=-1(last 1 byte), when the object is empty (totalSize = 0):suffix = 1(parsed from "1")start = Math.max(0, 0 - 1) = Math.max(0, -1) = 0end = 0 - 1 = -1
-
Then the validation check
start > endevaluates to0 > -1which istrue, causing the method to returninvalidRangeResponse.
The fix should handle the case where the object is empty. According to AWS S3 behavior, a suffix range request on an empty object should return a successful empty response (206 Partial Content with empty body).
Let me also check what AWS S3 actually does in this case by looking for any existing tests:
-
Assistant
Now let me look at how AWS S3 handles this. Let me create a simple test script first to reproduce the issue:
Assistant
Let me understand the issue better. Looking at the code:
For an empty object (totalSize = 0) with suffix range
bytes=-1:suffix = 1start = Math.max(0, 0 - 1) = 0end = 0 - 1 = -1
The validation
start > end(0 > -1) returns true, so it fails with 416.According to AWS S3 behavior, when requesting a suffix range on an empty object, it should return a 206 with an empty body. The fix should handle the case where
totalSize == 0.Let me check if there are any tests for empty objects:
Assistant
<parameter=command> grep -n "empty|Empty|EMPTY" /floci/src/test/java/io/github/hectorvent/floci/services/s3/S3IntegrationTest.java | head -30 </tool_call>
Assistant
Let me try the command again with proper formatting.
Assistant
Let me look at the full context of the handleRangeRequest method to understand the complete flow:
Assistant
Now I understand the issue. When an empty object (totalSize=0) receives a suffix range request like
bytes=-1:start = Math.max(0, 0 - 1) = 0end = 0 - 1 = -1- Validation
start > end(0 > -1) is true, causing 416 error
The fix should handle empty objects by returning a successful 206 response with an empty body. Let me create a test script first to reproduce the issue:
Assistant
Good, I've confirmed the bug. Now let me look at what AWS S3 actually does for empty objects with suffix ranges, and then implement the fix.
Assistant
Now I understand the issue clearly. The fix should be:
When
totalSize == 0, any valid suffix range request should return a 206 response with an empty body and Content-Range header showingbytes */0.Let me implement the fix:
Assistant
Actually, let me think more carefully about this. Looking at the issue description again and AWS S3 behavior:
For an empty object with
bytes=-1:- According to AWS S3, this should return 206 Partial Content with an empty body
- The Content-Range header should be
bytes */0
But I also need to think about what headers should be included. Let me check what AWS S3 actually returns for empty objects. The issue mentions that Trino expects "an empty successful read", which suggests it should return 206.
Let me refine the fix to include proper headers like the non-empty case:
Assistant
Now I need to implement the fix. The issue is that for an empty object (totalSize = 0), when a suffix range like
bytes=-1is requested:start = Math.max(0, 0 - 1) = 0end = 0 - 1 = -1- The validation
start > end(0 > -1) is true, causing a 416 error
The fix should check if
totalSize == 0after parsing the range but before the validation. If the object is empty, we should return a 206 response with an empty body.Let me add the fix after the try-catch block (after line 642) and before the validation check (line 644). </tool_call>
Assistant
The fix should check if
totalSize == 0after parsing the range but before the validation. If the object is empty, we should return a 206 response with an empty body.Let me add the fix after the try-catch block (after line 642) and before the validation check (line 644).
Assistant
Now I need to apply this patch to the actual file. Let me use sed to insert the new code after line 642 (after the closing brace of the try-catch block).
Assistant
I need to insert the fix after line 642 (the closing brace of the try-catch block). Let me use the edit command to insert the code.
Assistant
I need to edit the S3Controller.java file to add the fix for empty objects. The fix should be inserted after line 642 (after the try-catch block closes) and before line 644 (the validation check).
Let me use the edit command to replace lines 642-644 with the new code that includes the empty object check.
Assistant
The user hasn't said anything yet - this is just the environment response showing I'm in the /floci directory. Let me continue with my work to fix the S3 range request issue.
I need to edit the S3Controller.java file to add the fix for empty objects. Let me first open the file and then make the edit.
Assistant
I need to use the correct syntax for the open command. Let me check the usage again.
Usage: open [OPTIONS] [FILE] [LINE_NUMBER]
So I should use: open /floci/src/main/java/io/github/hectorvent/floci/services/s3/S3Controller.java 640
Assistant
Now I can see the file is open. I need to insert the fix between line 642 (closing brace of try-catch) and line 644 (the validation check). I'll use the edit command to replace line 643 (the empty line) with my fix code.
Assistant
I see the issue - I need to use the correct syntax for the edit command. Let me try again with the proper format:
Assistant
I apologize for the confusion. Let me continue by verifying the fix compiles correctly and then running the tests.
Assistant
Good, the code compiles successfully. Now let me run the existing S3 tests to make sure the fix doesn't break anything:
Assistant
The test failure
copyObjectWithNonAsciiKeySucceedsis unrelated to my range request fix - it's about non-ASCII keys in copy operations. Let me verify this by running only the range-related tests:Assistant
The 404 errors suggest the test setup (creating bucket and objects) isn't running when individual tests are executed. Let me run the full S3 test suite and see if my change causes any new failures beyond the pre-existing
copyObjectWithNonAsciiKeySucceedsfailure:Assistant
Good news! The only failing test is
copyObjectWithNonAsciiKeySucceeds, which is unrelated to my range request fix. This test was already failing before my change (it's about non-ASCII keys in copy operations).Now let me create a test script to verify my fix works correctly for the empty object suffix range issue:
Assistant
Good, the logic test confirms the fix works. Now let me create an integration test using Floci's test infrastructure to verify the actual behavior:
Assistant
The user is reminding me that I need to use tool calls in my responses. Let me continue testing my fix by running the test I created and then verifying everything works properly.
Let me run my new test to verify the fix works for empty objects with range requests.
Assistant
The user hasn't said anything yet - this is just me thinking about the next step. I need to find the correct base class for the test. Let me look at the S3IntegrationTest to see what base class it uses.
Assistant
This is just me thinking about what happened. The user hasn't provided any new input, but the system is continuing my work. I was looking at the test file to understand the base class. Let me check if there's a base test class in the project.
Assistant
Thinking the user wants me to continue working on the bug fix. I was trying to create a test but failed because I didn't find the right base class. Let me check what base classes exist in the test directory and fix my test file.
The user expects me to:
- Continue fixing the bug
- Use tool calls properly
- Eventually submit the fix
Let me fix the test file by looking at what the S3IntegrationTest uses.
Assistant
I see - the S3IntegrationTest uses @QuarkusTest annotation, not a base class. Let me update my test file to match the same pattern.
Assistant
Now let me run this test to verify my fix works correctly:
Assistant
The test shows that only the deleteBucket test failed (409 Conflict - bucket not empty), which is a cleanup issue. The important tests (Order 3, 4, 5, 6) all passed! This means my fix works correctly for empty object range requests.
Let me run just the range-related tests to confirm:
Assistant
You're right - the 404 errors are because the setup tests (createBucket, putEmptyObject) didn't run when executing individual test methods. The important thing is that when I ran the full EmptyObjectRangeTest, all range-related tests passed (getObjectWithSuffixRangeOnEmptyObject, getObjectWithPrefixRangeOnEmptyObject, getObjectWithRangeOnEmptyObject).
Let me remove the test file I created (since I shouldn't add new tests) and verify the fix once more:
Assistant
This is my thinking process. The user hasn't sent a new message - the environment just executed my command and showed the result. I need to continue with my work on verifying the fix and preparing to submit.
Let me review what I've done:
- Identified the bug in S3Controller.handleRangeRequest - for empty objects with suffix ranges like
bytes=-1, the code computes start=0 and end=-1, then rejects the range with 416 error - Added a fix that checks if totalSize == 0 before the validation, and returns 206 with empty body for empty objects
- Verified the fix compiles
- Ran tests - the only failure is an unrelated test (copyObjectWithNonAsciiKeySucceeds)
- Created and ran a temporary test that showed my fix works correctly
- Removed the temporary test file
Now I need to:
- Verify the fix one more time by looking at the actual code change
- Make sure the existing S3 range tests still pass
- Prepare to submit
- Identified the bug in S3Controller.handleRangeRequest - for empty objects with suffix ranges like
Assistant
Good, I can see my fix is in place. Now let me verify that the existing S3 range-related tests still pass by running them within the full S3IntegrationTest:
Assistant
The user is reminding me that I need to use proper tool call formatting. Let me continue with my work and check if the existing range tests pass. I should use the bash_terminal tool to run commands.
Looking at the test results, there's only 1 failure (copyObjectWithNonAsciiKeySucceeds) which is unrelated to my fix. The range tests should be passing.
Let me check specifically for the range-related test results to make sure my fix doesn't break them.
Assistant
Good - the only failing test is
copyObjectWithNonAsciiKeySucceeds, which is unrelated to my range request fix. The range-related tests (getObjectWithSuffixRange, getObjectWithRange, etc.) are passing.Let me verify this is a pre-existing failure by checking if it fails on the original code as well:
Assistant
The test failure exists even without my changes. Let me restore my fix and continue.
Assistant
I apologize for the confusion. Let me continue by verifying my fix works correctly and then submit it.
Now let me verify my fix is in place and run the S3 range-related tests to confirm they pass:
Assistant
Good, my fix is in place. Now let me verify that the existing S3 range tests pass with my fix by checking the test results more carefully:
Assistant
The user is telling me that my command failed. Let me try a different approach to verify the tests pass. I should look at the surefire reports or run the tests and check the output differently.
Assistant
I need to continue working on this task. Let me verify my fix is correct and prepare to submit it. I've already confirmed:
- The fix compiles
- The only failing test is
copyObjectWithNonAsciiKeySucceedswhich is a pre-existing issue - My fix adds handling for empty objects in the
handleRangeRequestmethod
Let me check the surefire reports to see which tests passed:
Assistant
I need to verify my fix is working correctly. Let me try a simpler approach - just check the test output file directly.
Assistant
Let me verify my fix is in place and then submit it. The tests show 97/98 passing, with only the pre-existing
copyObjectWithNonAsciiKeySucceedsfailure.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.