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 usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /floci, current file: none) bash-$
- Floci version / image tag:
- Assistant
I'll start by exploring the repository structure to understand the codebase and locate relevant files. Let's first check what's in the root directory.
- Assistant
Let me look at the S3 controller file to find the range handling logic.
- Assistant
Let me look at the S3Controller to find the handleRangeRequest method.
- Assistant
Let me open the S3Controller.java file and look at the handleRangeRequest method.
- Assistant
Let me scroll to the handleRangeRequest method to see the implementation.
- Assistant
Now I understand the issue. Let me trace through the logic for an empty object (totalSize = 0) with
bytes=-1:suffix= 1start= Math.max(0, 0 - 1) = 0end= 0 - 1 = -1- Then
start >= totalSize(0 >= 0) is true → returns 416
But AWS returns a 200 with an empty body for this case. Let me also check what tests exist for range handling.
- Assistant
Let me check the S3IntegrationTest to see if there are any range-related tests.
- Assistant
Let me look at the test setup to understand how they create test objects.
- Assistant
Let me look at the specific range test to understand what kind of objects they're testing with.
- Assistant
Now I understand the issue completely. For an empty object (0 bytes) with a suffix range like
bytes=-1:start = Math.max(0, 0 - 1) = 0end = 0 - 1 = -1- The check
start > end(0 > -1) is true → returns 416
According to AWS S3 behavior, when you request a suffix range and the object is smaller than the suffix length, the entire object should be returned with a 200 OK. For an empty object, that means returning an empty body with 200.
Let me also check how the getObject method handles the Range header to understand the full flow:
- Assistant
Now I have a clear understanding of the issue. Let me implement the fix. The fix should handle the case where
totalSize == 0for a suffix range request - in that case, we should return the entire empty object with a 200 OK response. - Assistant
Let me use the edit command instead.
- Assistant
Now I understand the issue. Let me trace through the logic for
bytes=-1on an empty object:totalSize = 0,suffix = 1start = Math.max(0, 0 - 1) = 0end = 0 - 1 = -1- Then at line 644:
start >= totalSize(0 >= 0) is true → returns 416
According to AWS S3 behavior, when you request a suffix range like
bytes=-Nand the object is smaller than N bytes, the entire object is returned. For an empty object, this means returning a 200 OK with an empty body.Let me fix this by adding a check for empty objects in the suffix range handling:
- Assistant
Now I need to add the
buildFullObjectResponsehelper method. Let me add it after theinvalidRangeResponsemethod: - Assistant
I see the closing brace of
invalidRangeResponsewas removed. Let me fix that: - Assistant
I see there's a duplicate method declaration. Let me fix that:
- Assistant
Good. Let me add a blank line before the
@HEADannotation for readability: - Assistant
Good. Let me verify the final state of the modified section:
- Assistant
Now let me check if the build tool is available and run the existing tests to make sure nothing is broken:
- Assistant
Let me run the S3 integration tests to make sure existing tests pass:
- Assistant
The HOME parameter is not set. Let me try with HOME set.
- Assistant
Let me check if HOME is set.
- Assistant
HOME is not set. Let me set it manually.
- Assistant
The only failure is
copyObjectWithNonAsciiKeySucceedswhich is a pre-existing issue unrelated to my change. Let me run just the range-related tests to verify: - Assistant
The tests use
@Orderannotations and depend on setup from earlier tests. ThegetObjectWithFullRangetest failed because it got 404 (bucket/object not set up). Let me run the full test class: - Assistant
Good - only 1 failure out of 98 tests, and it's the pre-existing
copyObjectWithNonAsciiKeySucceedstest that's unrelated to my change. All range tests passed.Let me verify the diff of my changes:
- Assistant
The diff looks clean. Let me also check if there are any tests specifically for empty object range requests:
- Assistant
Good. Let me verify the
appendObjectHeadersmethod signature to make sure my helper method is correct: - Assistant
Good - the
appendObjectHeaders(resp, obj, overrides)call uses the 3-parameter overload which delegates to the 4-parameter version withincludeChecksum=true. This is correct for a full object response.Let me also check if there are any unit tests for the S3Service that might test range handling:
- Assistant
Now let me also verify there's no issue with the existing
appendObjectHeadersoverloads. Let me look at the method signature: - Assistant
Everything looks good. Let me run the S3ServiceTest to make sure I haven't broken anything:
- Assistant
Let me check which test failed.
- Assistant
The only failure in S3ServiceTest is
copyObjectWithNonASCIIKey- a pre-existing unrelated issue (locale/charset problem). Not related to my change.Let me verify the complete diff one final time:
- Assistant
Now let me review the complete diff one final time 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.
Identical first prompt
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →