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 the issue:
- The bug is about S3 GetObject with a suffix byte range (e.g.,
bytes=-1) failing for empty objects - The issue is in
S3Controller.handleRangeRequestwhich computesstart = 0andend = -1for an empty object, then rejects the range - Expected behavior: A suffix range request against an empty object should succeed with an empty response
Let me start by exploring the repository structure to understand the codebase.
- The bug is about S3 GetObject with a suffix byte range (e.g.,
Assistant
Let me find the S3 controller file:
Assistant
Now let me look at the S3Controller.java file to find the
handleRangeRequestmethod mentioned in the issue.Assistant
Let me search for the
handleRangeRequestmethod:Assistant
Now I can see the issue. In the
handleRangeRequestmethod, when the object is empty (totalSize = 0):-
For a suffix range like
bytes=-1:suffix = 1(which is > 0, so passes the check)start = Math.max(0, 0 - 1) = 0end = 0 - 1 = -1
-
Then the check
start > endevaluates to0 > -1which istrue, so it returns an invalid range response.
Let me also check what AWS behavior should be for empty objects with range requests. According to AWS S3 documentation, for an empty object, a range request should succeed and return an empty response (or potentially return the full object as a 200 OK, not a 416).
Let me look at how the get object handles this and check for existing tests:
-
Assistant
Let me look at the existing range tests more closely:
Assistant
Now I understand the issue clearly. The fix should handle the case when
totalSizeis 0 (empty object). For an empty object with any range request, we should return an empty response with 206 status (or handle it gracefully).Let me check what AWS actually does in this case. According to AWS documentation and behavior, when you request a range on an empty object, it should return a 200 OK with empty content (not a 206 Partial Content, since there's nothing to return).
Actually, let me think about this more carefully:
For an empty object (totalSize = 0):
bytes=-1means "last 1 byte"start = Math.max(0, 0 - 1) = 0end = 0 - 1 = -1- The condition
start > endis0 > -1which is true → returns 416
The issue is that for an empty object, we should return a 200 OK with empty content rather than a 416. According to AWS S3 behavior, when an object is empty, a range request should succeed and return an empty body (typically as 200 OK).
Let me verify this understanding by looking at the full getObject method:
Assistant
Now I have a clear understanding. Let me create a fix. The issue is:
- When
totalSize = 0(empty object), and a suffix range likebytes=-1is requested:start = Math.max(0, 0 - 1) = 0end = 0 - 1 = -1- The check
start > endfails and returns 416
The fix should handle empty objects specially. When the object is empty, we should either:
- Return the object as a full 200 OK response (not a range response)
- Or return an empty 206 Partial Content response
Looking at how AWS behaves - for empty objects, AWS returns a 200 OK with empty content, treating it as a full object response (since there's no meaningful range to satisfy). This makes sense because the range "bytes=-1" is asking for "the last 1 byte" but there are no bytes, so returning the full (empty) object is appropriate.
Let me implement the fix by adding an early check for empty objects in
handleRangeRequest:- When
Assistant
Now I understand the code structure. The fix should handle empty objects by returning a full 200 OK response (since there's nothing to range). Let me add the check early in the
handleRangeRequestmethod:Assistant
Now I can see the code clearly. The fix should add a check for empty objects at the beginning of
handleRangeRequest. For empty objects, we should return a 200 OK response with empty content (not a 416 error), since the requested range cannot be satisfied as a partial content, but returning the full (empty) object is valid.Let me apply the fix:
Assistant
I see there's a duplicate line now. Let me fix that:
Assistant
Good, the duplicate line is fixed. Now I need to add the
fullObjectResponsehelper method. Let me look at the existing code that builds a full object response to understand the pattern:Assistant
Now let me add the
fullObjectResponsehelper method after theinvalidRangeResponsemethod:Assistant
I notice the closing brace for
invalidRangeResponseis missing. Let me fix that:Assistant
The code looks correct now. Let me verify the changes by viewing the relevant section:
Assistant
The code looks correct. Now let me run the tests to verify the fix works. First, let me check the project structure and find how to run tests:
Assistant
Command me continuing
Assistant
Command continuing
Assistant
I need to set the HOME environment variable before running mvnw.
Assistant
Command continues
The test is failing with 404, which suggests the test setup (greeting.txt file) isn't being created. Let me run a broader test to make sure the test environment is set up correctly first:
Assistant
The test failure is unrelated to my change (it's about non-ASCII keys in copy object). The range-related tests seem to pass since only the
copyObjectWithNonAsciiKeySucceedstest failed. Let me run the specific range tests to confirm:Assistant
The 404 errors suggest the test data isn't being set up properly when running individual tests. This is because the test class uses
@BeforeAllsetup that might not run when individual tests are selected. Let me check the test setup:Assistant
I see - the tests are ordered and depend on previous tests (bucket and object creation) to run first. When I ran individual tests, the setup wasn't done. Let me run the full S3IntegrationTest suite but filter out the failing unrelated test:
Assistant
The full test suite passes except for an unrelated test. Now let me write a quick test to verify my fix works. First, let me look at how the S3IntegrationTest creates empty objects:
Assistant
Good, there's no test for empty objects with range requests. Let me create a temporary test script to verify my fix works:
Assistant
Let me check if the test passed or failed - the output was cut off. Let me run the test again and check the result more carefully.
Assistant
The test passed (exit code 0). Let me run it again with verbose output to confirm:
Assistant
Excellent! Both tests pass:
suffixRangeOnEmptyObjectShouldSucceed- Testsbytes=-1on an empty object returns 200fullRangeOnEmptyObjectShouldSucceed- Testsbytes=0-on an empty object returns 200
Now let me also verify the existing range tests still pass with my changes:
Assistant
Command continues
Now let me check the test results to confirm:
<tool_call> <function=bash_terminal> <parameter=command> export HOME=/root && cd /floci && ./mvnw test -Dtest="S3IntegrationTest" 2>&1 | grep -E "(Tests run|BUILD|FAILURE)" | head -10 </tool_call>
Assistant
Let me verify that the range-related tests pass by checking if the only failure is the unrelated one:
Assistant
The grep didn't find any matches. Let me check the test output file differently to see if the range tests passed.
Assistant
Let me check if the test results file exists and look at its content differently.
Assistant
The user's message appears to be empty or just whitespace. I should continue with my work. Let me check the test results to verify my fix is working correctly.
Assistant
The user hasn't sent a new message yet - the system is showing me an empty message with just shell information. Let me continue with my work. I was checking if the range tests passed. Let me verify the test results for the range-related tests.
Assistant
All the range-related tests pass (no failure tags on any of them). The only failure is
copyObjectWithNonAsciiKeySucceedswhich is unrelated to my change.Now let me clean up the temporary test file and verify my changes:
Assistant
Let me verify the final state of my changes:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.