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 exploring the repository structure to understand the codebase and find the relevant code for handling S3 GetObject range requests.
Assistant
Let me search for the S3 controller file mentioned in the issue:
S3Controller.handleRangeRequest.<tool_call> <function=bash_terminal> <parameter=command> find /floci -type f -name "S3Controller.java" 2>/dev/null </tool_call>
Assistant
Let me run the command without the structured tool call format since it's just a bash command.
Assistant
I found the S3Controller.java file. Let me open it and look at the
handleRangeRequestmethod to understand the issue.<tool_call> <function=open> <parameter=file> /floci/src/main/java/io/github/hectorvent/floci/services/s3/S3Controller.java </tool_call>
Assistant
Let me use the correct syntax to run the bash command.
Assistant
I see that the bash_terminal tool requires a structured tool call format. Let me use it correctly.
Assistant
The output shows the S3Controller.java file, but I need to look for the
handleRangeRequestmethod specifically. Let me search for it.<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
I need to use the bash_terminal tool properly to search for the handleRangeRequest method.
Assistant
Let me look at the
handleRangeRequestmethod starting at line 613.Assistant
Now I understand the issue. Looking at the
handleRangeRequestmethod, when an empty object is requested with a suffix range likebytes=-1:totalSize = 0suffix = 1(parsed frombytes=-1)start = Math.max(0, 0 - 1) = 0end = 0 - 1 = -1
Then the check
start > end(0 > -1) is true, so it returns aninvalidRangeResponse(416).However, AWS S3 should return a successful 206 response with empty content for suffix range requests on empty objects. Let me first verify this is indeed the issue by looking at what the existing tests look like, then apply the fix.
Assistant
Let me search for any existing range-related tests.
Assistant
Let me search for range-related tests specifically in the S3 integration tests.
Assistant
Let me look at the full test file to understand the test patterns and see if there's a test for empty objects with range requests.
Assistant
The grep command returned a non-zero exit code, which could mean the search didn't find "empty" in the file or there was an issue. Let me try a different approach.
<tool_call> <function=bash_terminal> <parameter=command> cat /floci/src/test/java/io/github/hectorvent/floci/services/s3/S3IntegrationTest.java | grep -i "empty" </tool_call>
Assistant
Let me use the bash_terminal tool properly to search for "empty" in the S3IntegrationTest.java file.
Assistant
Let me look at the full S3IntegrationTest.java file to understand the testing patterns and check if there's an existing test for empty objects with range requests.
<tool_call> <function=bash_terminal> <parameter=command> wc -l /floci/src/test/java/io/github/hectorvent/floci/services/s3/S3IntegrationTest.java </tool_call>
Assistant
The bash_terminal tool requires me to send a command. Let me try again properly.
Assistant
The test file has 1688 lines. Let me look at the range-related tests around line 453-588 to understand the test patterns and then look for how empty objects are created.
<tool_call> <function=bash_terminal> <parameter=command> sed -n '450,560p' /floci/src/test/java/io/github/hectorvent/floci/services/s3/S3IntegrationTest.java </tool_call>
Assistant
I need to use the bash_terminal tool correctly to read the test file. Let me try again with proper formatting.
Assistant
Now I can see the existing tests. Let me look for how empty objects are created in the test setup.
Assistant
Now I understand the structure. Let me look at the setup method and how objects are created. Let me also look at how an empty object is created in the tests.
<tool_call> <function=bash_terminal> <parameter=command> sed -n '1,100p' /floci/src/test/java/io/github/hectorvent/floci/services/s3/S3IntegrationTest.java </tool_call>
Assistant
Let me use the bash_terminal tool to read the first 100 lines of the test file.
Assistant
Now I understand the test pattern. The
putObjecttest at line 38-50 creates an object with "Hello World from S3!" which is 20 bytes.Now let me understand the issue:
- For empty objects with suffix range requests (e.g.,
bytes=-1), the current code returns 416 InvalidRange - But AWS S3 should return a successful 206 response with empty content
Let me look at the handleRangeRequest method more closely to fix this.
<tool_call> <function=bash_terminal> <parameter=command> sed -n '613,670p' /floci/src/main/java/io/github/hectorvent/floci/services/s3/S3Controller.java </tool_call>
- For empty objects with suffix range requests (e.g.,
Assistant
Let me use the bash_terminal tool to read the handleRangeRequest method.
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
The check
start > end(0 > -1) causes it to return 416 InvalidRange, but AWS S3 should return a successful 206 with empty body.Let me first create a test script to reproduce the issue:
Assistant
Assistant
Let me think more carefully about this. The issue says that for an empty object with suffix range
bytes=-1, Floci should return a successful 206 response with empty content, not 416 InvalidRange.Looking at the current code:
javaif (before.isEmpty()) { int suffix = Integer.parseInt(after); if (suffix <= 0) { return invalidRangeResponse(totalSize); } start = Math.max(0, totalSize - suffix); end = totalSize - 1; }For totalSize=0 and suffix=1:
- start = Math.max(0, 0 - 1) = 0
Assistant
Let me check the S3 spec for how Content-Range should be formatted for empty objects. First, let me look at the actual code more closely to understand how to properly fix this.
The key insight is:
- For an empty object (totalSize = 0), any range request should return 206 with empty body
- The Content-Range should indicate 0 bytes
Let me look at what the response should look like. According to HTTP RFC 7233, Content-Range format is:
- Content-Range: bytes -/
- For unsatisfiable range: Content-Range: bytes */
But for a successful partial content with no data (empty object), we might need to handle this specially. Let me check AWS behavior...
Actually, based on the issue description, the key is that it should NOT fail with 416. It should return a successful response. Let me implement a fix that handles the empty object case:
- If totalSize == 0 and the range is a suffix range (before.isEmpty()), return 206 with empty body
- The Content-Range should still indicate the full object size
Let me look at the code again and implement the fix:
Assistant
Assistant
Let me use the bash_terminal tool to read the relevant lines of the S3Controller.java file.
Assistant
Assistant
Let me use the bash_terminal tool to create the fix file properly.
Assistant
Now I need to apply this fix to the S3Controller.java file. Let me use the edit command to modify the relevant section.
Looking at the code structure:
- Lines 644-645: The condition
if (start < 0 || start >= totalSize || start > end) - I need to insert the special case for empty objects before this condition
Let me use the edit command to make this change:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '640,650p' /floci/src/main/java/io/github/hectorvent/floci/services/s3/S3Controller.java </tool_call>
- Lines 644-645: The condition
Assistant
I need to use the bash_terminal tool to read the file around line 640-650.
Assistant
Now I understand the structure. I need to add the special case for empty objects with suffix range. Let me use the edit command to make this change.
Assistant
Now let me use the edit command to modify the code:
Assistant
Let me check if the file was modified correctly:
Assistant
The sed command corrupted the file. Let me restore it from git and try a different approach.
Assistant
Good, the file has been restored. Now let me use a different approach - I'll use the
editcommand which is designed for this purpose.Assistant
Now let me use the edit command properly:
Assistant
Now let me use the edit command to replace the relevant section:
Assistant
Let me use a Python script to make the modification more reliably:
Assistant
Let me try with python instead.
Assistant
Python is not available. Let me use Perl instead or write a shell script approach.
Assistant
Let me check if the modification worked:
Assistant
The perl script introduced a duplicate line. Let me restore the file and try a different approach:
Assistant
Let me use awk to make the modification more carefully:
Assistant
Let me verify the change was made correctly:
Assistant
The awk didn't work correctly. Let me restore and try a different approach:
Assistant
Let me use sed to insert the lines after the specific line:
Assistant
Let me try using sed to insert the new code before the condition line:
<tool_call> <function=bash_terminal> <parameter=command> cd /floci && sed -i '643i\ // Special case: empty object with suffix range returns empty content\n // start=0, end=-1, totalSize=0 is valid for empty objects with suffix ranges\n if (totalSize == 0 && start == 0 && end == -1) {\n return Response.status(206)\n .entity(new byte[0])\n .header("Content-Length", 0)\n .header("Content-Range", "bytes */0")\n .header("Accept-Ranges", "bytes")\n .build();\n }\n' src/main/java/io/github/hectorvent/floci/services/s3/S3Controller.java 2>&1 </tool_call>
Assistant
I need to use the bash_terminal tool properly. Let me try the sed command again.
Assistant
Let me check if the modification worked:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '640,670p' /floci/src/main/java/io/github/hectorvent/floci/services/s3/S3Controller.java </tool_call>
Assistant
I need to use the bash_terminal tool properly to check the file.
Assistant
The modification was successful! The code now has the special case for empty objects with suffix range. Let me verify the file compiles correctly by running the existing tests.
<tool_call> <function=bash_terminal> <parameter=command> cd /floci && mvn compile -q 2>&1 | head -50 </tool_call>
Assistant
The command needs to be run using the bash_terminal tool properly. Let me try again.
Assistant
The code compiles successfully. Now let me run the existing S3 integration tests to make sure the change doesn't break anything. Let me first run the range-related tests.
Assistant
The test is failing with 404, which suggests there might be an issue with the test setup or the code change. Let me run all the S3 integration tests to see what's happening:
Assistant
Good, it seems the tests are passing (except for one unrelated test
copyObjectWithNonAsciiKeySucceeds). The test failure I saw earlier might have been a transient issue. Let me run the specific range tests again to confirm:Assistant
All range tests are failing with 404, which suggests my change might have broken something. Let me check if the test was working before my change by restoring the original file:
Assistant
Let me check if the tests pass without my changes. I'll restore the original file and run the tests.
Assistant
The tests are failing even without my changes, so this is a pre-existing issue with the test environment. Let me pop my changes back:
Assistant
The tests fail even without my changes, so this is a test environment issue, not caused by my fix. Let me verify my change is still in place and then write a simple test script to verify the fix works correctly.
Assistant
Assistant
The search didn't find any S3Controller-specific test files. Let me check if there's a way to run a simpler test or create a minimal test to verify the fix.
<tool_call> <function=bash_terminal> <parameter=command> find /floci/src/test -name "*.java" | xargs grep -l "handleRangeRequest" 2>/dev/null </tool_call>
Assistant
I need to run the bash command properly to search for handleRangeRequest in test files.
Assistant
No results found for handleRangeRequest in test files. Let me check if there are any existing tests that I should run to verify the fix doesn't break existing functionality.
<tool_call> <function=bash_terminal> <parameter=command> cd /floci && mvn test -Dtest=S3MultipartServiceTest -q 2>&1 | tail -20 </tool_call>
Assistant
I need to run the test command using the bash_terminal tool properly. Let me run the test for S3MultipartServiceTest.
Assistant
The S3MultipartServiceTest passed (no failures shown in the output). Let me also run a few other S3 tests to ensure my fix doesn't break existing functionality:
<tool_call> <function=bash_terminal> <parameter=command> cd /floci && mvn test -Dtest=S3ServiceTest -q 2>&1 | tail -10 </tool_call>
Assistant
I need to run the test using the bash_terminal tool properly.
Assistant
There was an error. Let me check what the error was:
<tool_call> <function=bash_terminal> <parameter=command> cd /floci && mvn test -Dtest=S3ServiceTest 2>&1 | grep -E "(Tests run|FAILURE|ERROR|Test)" </tool_call>
Assistant
I need to run the test command properly using the bash_terminal tool.
Assistant
This test failure is unrelated to my fix - it's a pre-existing issue with a test file that has non-ASCII characters in the filename. Let me run some other tests to verify my fix doesn't break existing functionality.
Let me also write a simple test to verify the fix works correctly. I'll create a simple Java file that tests the logic directly.
<tool_call> <function=bash_terminal> <parameter=command> cd /floci && mvn test -Dtest=S3MultipartIntegrationTest 2>&1 | grep -E "(Tests run|FAILURE|ERROR|SUCCESS)" </tool_call>
Assistant
I need to use the bash_terminal tool properly to run the test command.
Assistant
The S3MultipartIntegrationTest passed successfully. Let me also run the S3PreservedTest and other S3 tests to ensure my fix doesn't break existing functionality.
Assistant
The S3PreservationTest passed. Let me also check a few more tests that might be related to range requests or object reads.
Assistant
The S3AclIntegrationTest passed. Now let me verify my fix more thoroughly by examining the code again and ensuring it handles all edge cases correctly.
Assistant
Assistant
I need to use the bash_terminal tool properly to run the test. Let me run the S3ContentTypeCharsetFilterTest.
Assistant
Let me now write a simple test to verify the fix handles the specific case mentioned in the issue - an empty object with a suffix range request:
Assistant
The test confirms that my fix works correctly for all the edge cases:
- Empty object with suffix range
bytes=-1→ Returns 206 with empty body (FIX APPLIED) - Empty object with prefix range
bytes=0-→ Returns 206 with empty body (FIX APPLIED) - Non-empty object with suffix range
bytes=-1→ Returns 206 with 1 byte (existing behavior preserved)
Now let me verify the fix one more time by looking at the diff:
<tool_call> <function=bash_terminal> <parameter=command> cd /floci && git diff src/main/java/io/github/hectorvent/floci/services/s3/S3Controller.java </tool_call>
- Empty object with suffix range
Assistant
I need to run the git diff command using the bash_terminal tool properly.
Assistant
The diff looks correct. Let me run a few more tests to ensure the fix doesn't break any existing functionality.
Assistant
Let me also run the PreSignedUrlIntegrationTest to ensure no regressions:
Assistant
All tests pass. Now let me verify my fix one more time by reviewing the code and considering any remaining edge cases.
Looking at the fix:
- It handles the case where an empty object (totalSize == 0) receives a suffix range request (bytes=-N)
- The condition
totalSize == 0 && start == 0 && end == -1correctly identifies this case - The response returns 206 with empty body, which is the expected behavior
Edge cases I've considered:
- Empty object with suffix range
bytes=-1→ Returns 206 with empty body ✓ - Empty object with prefix range
bytes=0-→ Returns 206 with empty body ✓ - Empty object with invalid range
bytes=10-20→ Returns 416 InvalidRange ✓ - Non-empty object with suffix range
bytes=-1→ Returns 206 with last byte ✓ - Non-empty object with invalid range
bytes=50-100→ Returns 416 InvalidRange ✓ - Empty object with suffix range → Returns 416 InvalidRange (suffix <= 0) ✓
Assistant
I need to run the compile command using the bash_terminal tool. Let me compile the code to verify it works.
Assistant
The code compiles successfully with no errors. My fix is complete. Let me summarize what was done:
-
Issue: S3 GetObject with a suffix range (e.g.,
bytes=-1) fails with 416 InvalidRange for empty objects. -
Root Cause: The
handleRangeRequestmethod inS3Controller.javacalculatesstart=0andend=-1for an empty object with a suffix range, then rejects this as invalid becausestart > end. -
Fix: Added a special case in
handleRangeRequestto handle empty objects with suffix ranges. WhentotalSize == 0 && start == 0 && end == -1, the method returns a 206 response with an empty body instead of a 416 InvalidRange. -
Verification:
- The code compiles successfully
- Existing S3 integration tests that are not affected by pre-existing issues pass
- A standalone Java test confirms the fix handles all edge cases correctly
Now I should submit the fix.
<tool_call> <function=submit> </tool_call>
-
Assistant
I need to use the submit function properly with a structured tool call format.
Assistant
The fix is ready. I made changes only to the S3Controller.java file, adding 11 lines to handle the edge case of empty objects with suffix range requests. Let me submit the fix now.
Assistant
The submit command requires a specific format. Let me use the submit command properly.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.