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
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 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 understanding the issue:
-
When making a GetObject request with a suffix byte range (e.g.,
bytes=-1) on an empty S3 object, Floci returns416 InvalidRangeinstead of a successful empty response. -
The bug is in
S3Controller.handleRangeRequestwhere it computesstart = 0andend = -1for an empty object, then rejects the range.
Let me explore the repository structure first, then find the relevant code, understand the bug, and fix it.
-
Assistant
Let me find the S3Controller and the handleRangeRequest method.
Assistant
Let me look at the S3Controller.java file, specifically the handleRangeRequest method.
Assistant
Let me look at the handleRangeRequest method more
Assistant
Let me use the correct command format:
Assistant
Let me try the open command with the correct syntax:
Assistant
Now I can see the bug clearly. Let me analyze it:
For a suffix range
bytes=-1on an empty object (totalSize = 0):start = Math.max(0, 0 - 1) = 0end = 0 - 1 = -1- Validation fails because
start >= totalSize(0 >= 0) andstart > end(0 > -1)
Let me look for any existing tests related to range requests
Assistant
Let me look at the relevant S3 integration tests to understand the expected behavior better
Assistant
Now I have a clear picture. Let me create a reproduce script first, and then apply the fix.
Assistant
Now let me apply the fix. The issue is in the
handleRangeRequestmethod at lines 629-635 for suffix ranges on empty objects. I need to handle the case wheretotalSize == 0for suffix byte ranges:Assistant
Let me open the correct file first
Assistant
Now let me apply the fix. I'll modify the suffix range handling to return early for empty objects. First, let me add a helper method and then modify the suffix range handling:
Assistant
Let me try using the
replacecommandAssistant
Now I need to add the
emptyObjectRangeResponsehelper method. Let me add it afterinvalidRangeResponse:Assistant
Let me check what's at line 682
Assistant
Let me use
replaceto add the new method after theinvalidRangeResponseclosing braceAssistant
Let me verify the handleRangeRequest method is correct:
Assistant
Good. Now let me verify the code compiles and tests pass. Let me first run a quick compile
Assistant
Let me check the environment and try to set
Assistant
Good, compilation succeeded. Now let me run the specific S3 integration tests related to range requests
Assistant
The tests are failing because they depend on test ordering (setup). Let me look at the test class structure
Assistant
The tests depend on ordering. Let me run the full test class to ensure setup is done first
Assistant
Excellent! 98 tests ran with only 1 pre-existing failure (
copyObjectWithNonAsciiKeySucceeds- unrelated to my change). All range tests pass. Let me verify the range tests specifically passedAssistant
The isolated test failures are expected - they need the setup tests to run first (ordered tests). The full test class run showed only 1 pre-existing failure unrelated to ranges. Let me verify my changes look correct with a
Assistant
I want to reconsider the approach. The
Content-Range: bytes */0format is typically for 416 errors. For a 206 on an empty object, let me return a 200 instead (which is valid per RFC 7233 - servers may ignore Range and return 200). This avoids the Content-Range ambiguity entirely.Assistant
Let me compile to make sure the code is good
Assistant
Compilation succeeds. Now let me run the full S3 integration test suite
Assistant
All 98 tests run, only 1 pre-existing failure unrelated to my change. My fix is complete. Let me verify the final state of the
Assistant
Let me do a final review of the complete modified
Assistant
The fix looks clean and correct. Let me also run the other S3 tests to ensure nothing else breaks
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.