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 start by understanding the issue. The problem is with S3 GetObject suffix range requests (like
bytes=-1) failing for empty objects. When an object is empty (0 bytes), a suffix range likebytes=-1should return the empty object successfully (since the last 1 byte of an empty object is... empty), but instead Floci returns a 416 InvalidRange error.Let me explore the repository structure first.
Assistant
Let me look at the S3Controller.java file to understand the handleRangeRequest method.
Assistant
Let me try the open command with the correct syntax.
Assistant
Let me search for the handleRangeRequest method.
Assistant
Let me look at the handleRangeRequest method and its
Assistant
Now I can see the issue. Let me look at the context around line 594 to understand the full flow:
Assistant
Now I have a clear understanding of the bug. Let me trace through the logic for
bytes=-1on an empty object:totalSize = 0rangeSpec = "-1"before = "",after = "1"- Since
before.isEmpty():start = Math.max(0, 0-1) = 0,end = 0-1 = -1 - Then:
start >= totalSize→0 >= 0→ true → returns 416 InvalidRange
The fix should handle the case where
totalSize == 0by returning a successful empty response. Let me first check if there are existing tests:Assistant
Let me look at the existing suffix range test and the test setup to understand the test pattern:
Assistant
Let me look at the test for suffix range to understand the test setup:
Assistant
Let me look at the suffix range test around line 481:
Assistant
Now I have a clear understanding. Let me implement the fix. For an empty object with a valid suffix range like
bytes=-1, the code computesstart=0, end=-1and then the checkstart >= totalSize(i.e.,0 >= 0) returns 416. The fix is to handletotalSize == 0as a special case before the validity check.Assistant
Wait, I see an issue. The
ifstatement at line 660 is now separated from its body. Let me check the current state:Assistant
I see the issue - the
ifstatement at line 660 is missing its body. I need to fix this. The replacement accidentally removed thereturn invalidRangeResponse(totalSize);line. Let me fix that:Assistant
Wait, I need to reconsider. My current fix is too broad - it would accept ANY range on an empty object (e.g.,
bytes=10-which should be 416). The issue is specifically about suffix ranges (bytes=-N) on empty objects. Let me refine the fix:Assistant
I see a duplicate issue - there are now two
ifstatements at lines 660 and 662. Let me remove the incomplete one at line 660:Assistant
The code looks correct now. Let me verify the complete method and then run the existing tests to ensure nothing is broken.
Assistant
The code looks correct. Now let me build the project and run the existing tests.
Assistant
The
beforevariable is scoped inside the try block. I need to restructure. Let me move thebeforeandafterdeclarations outside the try block:Assistant
Now let me compile to verify the fix:
Assistant
Compilation successful. Now let me run the S3 integration tests to make sure nothing is broken:
Assistant
The only test failure is
copyObjectWithNonAsciiKeySucceedswhich is unrelated to my change (it's about copying objects with non-ASCII keys). Let me verify that all the range-related tests passed:Assistant
The only failing test is the unrelated
copyObjectWithNonAsciiKeySucceeds. Let me specifically run the range-related tests to confirm they all pass:Assistant
Those tests likely depend on test ordering (they need objects created by earlier tests). Let me verify this by checking the full test output to confirm the range tests passed in the full run:
Assistant
Let me check the surefire report to confirm the range tests passed:
Assistant
Let me look at the test report directly:
Assistant
Let me re-run the full test suite and capture the summary properly:
Assistant
The full test suite shows 97 out of 98 tests pass, with the only failure being
copyObjectWithNonAsciiKeySucceedswhich is completely unrelated to my change. All range-related tests pass.Now let me verify the fix handles the exact scenario from the issue by tracing through it once more:
bytes=-1on empty object (totalSize=0):before = "",after = "1"suffix = 1, not <= 0 → validstart = max(0, 0-1) = 0,end = 0-1 = -1totalSize == 0 && before.isEmpty()→ true → returns 206 with empty body ✓
Let me also verify the complete method looks good:
Assistant
The code looks clean and correct. Let me verify the diff to confirm only the intended changes were made:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.