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
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,submitonly submits currently unstaged changes because it uses to get the changes that need to be submitted. - Floci version / image tag:
Assistant
Let me analyze this issue. The bug is about S3 GetObject with a suffix byte range (like
bytes=-1) failing for empty objects. The S3Controller.handleRangeRequest computes start=0 and end=-1 for an empty object, then rejects the range with a 416 InvalidRange error.Let me first explore the repository structure to understand the codebase and find the relevant code.
Assistant
Let me find the S3 controller file specifically.
Assistant
Good, found the S3Controller.java file. Let me examine it.
Assistant
I need to use the correct opening syntax for files. Let me just use the open command without the file parameter or use a different approach.
Assistant
Let me search for the
handleRangeRequestmethod specifically:Assistant
Now let me look at the
handleRangeRequestmethod:Assistant
Now I understand the issue. Let me analyze the code:
-
When a suffix range like
bytes=-1is received for an empty object (size = 0):suffix = 1(parsed from "1")start = Math.max(0, totalSize - suffix)=Math.max(0, 0 - 1)=0end = totalSize - 1=0 - 1=-1
-
Then the validation check:
if (start < 0 || start >= totalSize || start > end)evaluates to:start >= totalSize→0 >= 0→true
So it returns a 416 InvalidRange error.
According to AWS S3 behavior, a range request on an empty object should return a 206 with an empty body. Let me verify by checking what AWS expects for this case.
The fix should handle the case when
totalSizeis 0 (empty object). In this case, a suffix range request should return successfully with an empty response body.Let me also look at the
getObjectmethod to understand the full flow:-
Assistant
Now let me check if there are any existing tests for S3 range requests:
Assistant
Let me look at the existing test structure to understand how they're written:
Assistant
Now let me understand the fix needed. The problem is:
For an empty object (totalSize = 0) with suffix range
bytes=-1:suffix = 1start = Math.max(0, 0 - 1) = 0end = 0 - 1 = -1- Then the check
start >= totalSize→0 >= 0→true, so it returns 416
According to AWS S3 behavior, when requesting a range from an empty object, the request should succeed with an empty response body. Let me first create a test script to reproduce the issue, then fix it.
Let me check what build system this project uses:
Assistant
It's a Maven project. Let me now implement the fix. The fix should handle the case when the object is empty (totalSize = 0). In that case, any valid range request should return a 206 with an empty body.
Assistant
Now I understand the issue clearly. The fix should handle the case when
totalSize == 0. For empty objects, a valid range request should return a 206 Partial Content response with an empty body.The fix should be added right after parsing the range, before the validation check. When
totalSize == 0, we should return a successful 206 response with empty content.Let me open the file and make the edit:
Assistant
Now I need to modify line 644 to handle the empty object case. The condition
start >= totalSizefails whentotalSize == 0becausestart = 0and0 >= 0is true. For empty objects, we should allow the range request to succeed with an empty body.The fix: Add a special case for when
totalSize == 0. In this case, if we've parsed a valid range (reached the validation check), return a 206 with empty content.Assistant
Now let me apply the fix. I'll modify the validation condition on line 644 to also check if
totalSize > 0before rejecting whenstart >= totalSize:Assistant
Let me verify the change:
Assistant
Good, the condition is updated. However, I notice there's still a potential issue. When
totalSize == 0:- For suffix range
bytes=-1:start = 0,end = -1 - The check
start > endwould be0 > -1→true, so it would still fail!
I need to also handle the case when
totalSize == 0specially. Let me add a check at the beginning of the range validation to handle empty objects:- For suffix range
Assistant
I see the issue more clearly now. The problem is that when
totalSize == 0:- For suffix range
bytes=-1:start = 0,end = -1, andstart > end→ still fails - For byte range
bytes=0-0:start = 0,end = -1(sincetotalSize - 1 = -1), andstart > end→ still fails
The best approach is to add a special case early in the function to handle empty objects. For an empty object, any valid range syntax should return a 206 with empty content:
- For suffix range
Assistant
Let me take a different approach and directly edit the file. First, let me revert my previous change and apply a cleaner fix:
Assistant
Let me revert and apply a cleaner fix:
Assistant
Now let me look at the exact lines I need to modify:
Assistant
I'll now add the empty object handling. The best place to add it is right after the range parsing and before the validation check:
Assistant
I'll use the edit command to replace the validation block. Let me replace lines 643-646 with the new code that handles empty objects:
Assistant
Let me use sed instead:
Assistant
Now I need to create the middle part with the new code:
Assistant
Now I need to add the
buildRangeResponsehelper method. Let me first check if the existing code in the function that builds the 206 response can be extracted:Assistant
I see that I need to add a
buildRangeResponsehelper method. Let me look at the full handleRangeRequest method and then refactor it to extract the common response-building code:Assistant
Now I need to add the
buildRangeResponsehelper method. Let me find where to insert it (afterinvalidRangeResponse):Assistant
Now let me add the
buildRangeResponsehelper method afterinvalidRangeResponse:Assistant
Wait, I realize the
Content-Rangeheader format needs the total size, not the range data length. Let me reconsider the approach. Actually, looking at this more carefully, I think I should take a simpler approach - instead of extracting a helper method, I'll just handle the empty object case inline or adjust the condition.Let me reconsider. The issue is:
- For
totalSize == 0, suffix rangebytes=-1:start = 0,end = -1 - Check
start > endfails because0 > -1
A simpler fix: Just check
totalSize == 0and handle it specially, returning a 206 with empty body andContent-Range: bytes 0--1/0or better yetbytes */0.Actually, let me check what AWS S3 actually returns for this case. Looking at the issue description, it says "expects an empty successful read." So it should return 206 with empty body.
Let me reconsider and use a simpler inline fix:
- For
Assistant
Now let me apply a cleaner fix. I'll use sed to insert the empty object check and modify the validation:
Assistant
Let me check the result:
Assistant
The fix looks good. Now let me verify the entire method compiles correctly by checking its structure:
Assistant
The code looks correct. Now let me compile the project to verify there are no syntax errors:
Assistant
The compilation succeeded (no errors, just warnings). Now let me run the existing S3 tests to make sure I haven't broken anything:
Assistant
The test failure
copyObjectWithNonAsciiKeySucceedsis unrelated to my change - it's a pre-existing issue with non-ASCII keys. Let me check if this test was failing before my change by verifying if it's related to range handling:Assistant
This test is unrelated to my change. Let me verify by reverting my change and running the same test:
Assistant
The test failure existed before my change, so it's a pre-existing issue unrelated to my fix. Let me restore my changes:
Assistant
Now let me run only the range-related tests to make sure my change doesn't break them:
Assistant
The 404 errors are because I'm running tests in isolation, and they depend on setup from earlier tests (like creating the bucket and objects). Let me run all S3 tests together, excluding the unrelated failing test:
Assistant
All 98 tests ran and only the pre-existing failure (
copyObjectWithNonAsciiKeySucceeds) failed. All range-related tests passed. Let me verify this by checking the test report more specifically:Assistant
Good, no errors for range tests in the reports. Now let me create a test script to verify my fix works for the specific bug case:
Assistant
Let me check how empty objects are created in the existing tests:
Assistant
Let me write a simple test script that verifies my fix. I'll create a temporary test file that can be run:
Assistant
Let me now check how tests are structured so I understand what test I need to write:
Assistant
Now let me create a simple test script to verify the fix. First, let me see the test structure around range tests:
Assistant
Let me find the last Order number used so I can create a test that runs after the existing tests:
Assistant
Let me create a temporary test file to verify my fix works. I'll add a test for empty object suffix range:
Assistant
analysis: The user hasn't provided any new input yet - this appears to be a continuation of our conversation. I was in the middle of testing my fix for the S3 GetObject suffix range bug for empty objects. I had just created a test file and was about to run it. Let me check if there's a pending command output or if I need to continue with the next step.
Looking at the context:
- I successfully added the fix to handleRangeRequest for empty objects
- I created a test file S3EmptyObjectRangeTest.java
- The last command output shows the file was created successfully
- Now I should run this test to verify the fix works
Let me run the test now. }
<tool_call> <function=bash_terminal> <parameter=command> cd /floci && export HOME=/root && ./mvnw test -Dtest=S3EmptyObjectRangeTest -q 2>&1 | tail -30 </tool_call>
Assistant
The previous command seems to have been executed but I need to run the test to verify the fix. Let me run it again.
Assistant
Let me fix the test file by checking how the existing tests handle RestAssured config:
Assistant
The existing tests use
DecoderConfig.decoderConfig().noContentDecoders()instead ofdisableAutoDecoding(). Let me fix the test file.Assistant
The user hasn't provided any new input - they just see the bash prompt. Looking at the conversation history, I was in the middle of testing my fix for the S3 GetObject suffix range bug for empty objects. I just created a test file and need to run it to verify the fix works.
Let me continue by running the test to verify my fix.
Assistant
The tests are failing because JUnit doesn't guarantee test execution order without @Order annotations. Let me fix the test file with proper ordering:
Assistant
The user sent an empty message (just whitespace). I was in the middle of testing my fix for the S3 GetObject suffix range bug for empty objects. I just created a test file with proper @Order annotations and need to run it to verify the fix works. Let me continue by running the test.
Assistant
All tests passed! The output shows no errors - the bucket was created, tests ran successfully, and cleanup happened. My fix for the S3 GetObject suffix range on empty objects is working.
Let me clean up the temporary test file and run the existing S3 tests one more time to make sure nothing is broken:
Assistant
The user sent an empty message. Looking at the context, I was in the middle of solving the S3 GetObject suffix range bug for empty objects. I had:
- Made the fix to S3Controller.java
- Created and ran a test that passed
- Just deleted the test file
The last output shows the test passed (bucket was created, deleted, and the server shut down cleanly with no errors).
Now I should run the existing S3 tests to make sure my fix doesn't break anything, and then review the checklist before submitting.
Assistant
The test results confirm that only the pre-existing failure (
copyObjectWithNonAsciiKeySucceeds) is present, and all range-related tests pass. My fix doesn't break any existing functionality.Let me review my changes and go through the checklist:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.