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
I'll start by exploring the repository to understand its structure and locate relevant files. Let's first look at the current directory.
- Assistant
This is a Go repository. Let me explore the S3 controller to understand how range requests are handled.
- Assistant
Let me search for S3-related files more broadly.
- Assistant
Let me search for the S3 controller more broadly.
- Assistant
The issue is in
S3Controller.handleRangeRequest. The issue mentions it's a Java project (Maven with pom.xml). Let me look at the Java source files. - Assistant
Let me look at the S3Controller to find the handleRangeRequest method.
- Assistant
Let me look at the handleRangeRequest method.
- Assistant
Now I understand the issue. Let me look at the full context around the getObject method to understand the flow better.
- Assistant
Let me look at the S3 test file to understand existing tests for range requests.
- Assistant
Let me check the existing unit/integration tests:
- Assistant
Let me find the S3 test files and look for range-related tests.
- Assistant
Let me look at the complete handleRangeRequest method and understand the exact issue:
- Assistant
Now I understand the issue. For a suffix range request like
bytes=-1on an empty object (totalSize=0):suffix = 1start = Math.max(0, 0 - 1) = 0end = totalSize - 1 = -1
Then the validation
start >= totalSize(0 >= 0) is true, so it returns 416 InvalidRange.The fix should handle the case where the object is empty and a valid suffix range is requested. Let me implement the fix:
- Assistant
Now I have a clear understanding of the issue. For an empty object (0 bytes) with suffix range
bytes=-1:suffix = 1start = Math.max(0, 0 - 1) = 0end = totalSize - 1 = 0 - 1 = -1
Then the validation check at line 644:
start >= totalSize(0 >= 0) is true → returns 416 InvalidRange.The fix should handle the case where the object is empty (totalSize == 0) and a suffix range is requested. AWS S3 returns a 206 with an empty body for this case.
Let me implement the fix:
- Assistant
Now I need to create the
rangeResponsehelper method. Let me add it afterinvalidRangeResponse: - Assistant
Now let me also refactor the main
handleRangeRequestmethod to use the new helper for non-empty objects to avoid code duplication: - Assistant
Let me review the complete change to make sure everything looks correct:
- Assistant
The code looks good. Let me now look for existing tests related to range requests to make sure I haven't broken anything:
- Assistant
Let me search more specifically for S3 range tests:
- Assistant
Let me look at the existing range tests in S3IntegrationTest:
- Assistant
Let me see all the range-related tests and also check if there are valid range tests:
- Assistant
Let me look at the suffix range test:
- Assistant
Now let me run the existing tests to make sure my changes don't break anything:
- Assistant
The failing test
copyObjectWithNonAsciiKeySucceedsseems unrelated to our change. Let me verify by running only the range-related tests: - Assistant
The tests are returning 404, which means the test fixture data isn't being set up when running individual tests. These tests depend on test ordering and data created by earlier tests. Let me run the full suite:
- Assistant
Only 1 failure:
copyObjectWithNonAsciiKeySucceedswhich is unrelated to our change (it was likely already failing before). The range tests all passed. Let me verify this was pre-existing by checking git status: - Assistant
Let me verify that the pre-existing test failure exists on the original code too:
- Assistant
The test failure is pre-existing. Let me restore my changes:
- Assistant
Let me review the diff of my changes:
- Assistant
The change looks correct. Let me also verify the code compiles:
- Assistant
Let me run the full S3 test suite one more time to confirm only the pre-existing failure remains:
- Assistant
Only the pre-existing failure remains. All 97 other tests pass, including all the range-related tests.
Let me also check the AGENT.md for any coding conventions:
- Assistant
Let me review the final state of my changes one more time:
- Assistant
Now I'm ready to submit my changes. Let me review the complete diff one final time:
- Assistant
Now let me also verify that the edge case of
bytes=-1on an empty object is correctly handled by tracing through the code. Let me verify the fix handles all edge cases:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.