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
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 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, 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.
Assistant
Let me understand the bug more clearly. Let me also check the test code for the repository structure:
Assistant
Now let me look at the existing tests to understand the test patterns and find the empty object test:
Assistant
Let me look at the full S3Controller.java for the Range implementation:
Assistant
Let me now look at how this gets built and run a test:
Assistant
Now let me look at the existing tests for
Empty. First let's check what AWS SDK does in such scenarios. Let me check by reading the code carefully:Assistant
Let me look at the actual integration test file for S3 to understand the test structure better:
Assistant
Now, let me check what real AWS S3 actually does for empty objects with range requests. Let me look at the bug closely. According to the bug:
bytes=-1on empty object should NOT fail the read- Should be an empty successful read
Let me look at how AWS S3 actually behaves:
Assistant
Now let me look at the actual AWS behavior. I'll check the AWS S3 documentation referenced:
Assistant
Now I have a clear understanding of the issue. Let me look at the entire getObject method and how the test cases work:
Assistant
Now let me check S3Object.java to see the getSize() method:
Assistant
Now I have a clear understanding. Let me verify the issue by reproducing it:
Assistant
Let me look at the test setup to understand how I can run a test for the fix:
Assistant
Let me check the build configuration to ensure I can run tests:
Assistant
Let me first verify the issue by reproducing it. Let me look at the relevant code area I need to fix:
Assistant
Let me look at how the getObject service handles range queries (if at all):
Assistant
Now I have a clear understanding of the issue. Let me look at a few additional points to understand the existing test pattern for empty objects:
Assistant
Let me now write a quick reproduce script to verify the bug first:
Assistant
Now let me look at PreSignedUrlIntegrationTest for the range tests there too:
Assistant
Now I have a complete understanding. Let me apply the fix. The simplest and cleanest approach is to skip the range handling for empty objects, returning the standard 200 OK response with empty body. This matches Trino's expectation for
readTailon zero-byte objects:Assistant
Now I'll apply the fix. Looking at the issue, I need to handle the empty object case by returning a successful response. Let me think about which approach is best:
Approach 1: Skip range handling entirely for empty objects - The simplest, returning 200 OK with empty body.
Approach 2: Return 200 OK in
handleRangeRequestfor empty objects - More explicit but requires changes in the handler.I'll go with Approach 2 but I'll also handle it cleanly. The cleanest fix is to return a successful empty response within
handleRangeRequestfor empty objects, after the range parsing succeeds. This way:- Malformed ranges on empty objects still return 416 (consistent with non-empty).
- Valid ranges on empty objects return 200 OK with empty body.
Assistant
Now let me verify the fix compiles successfully:
Assistant
Compiles successfully. Now let me write a quick reproduction script to verify the fix actually works. Let me start by trying to run the existing tests to make sure I haven't broken anything:
Assistant
The single failure is
copyObjectWithNonAsciiKeySucceeds, which is unrelated to my change. Let me confirm by checking if this test fails without my change:Assistant
Confirmed -
copyObjectWithNonAsciiKeySucceedsfails even without my changes. Let me restore my fix:Assistant
Let me now run the Range-related tests to make sure my fix doesn't break any existing tests:
Assistant
Let me run all the S3IntegrationTest tests together:
Assistant
Only the unrelated pre-existing test failure. Let me also verify the fix works by writing a temporary script that simulates the issue:
Assistant
Let me write a temporary Java test to verify the fix works:
Assistant
Let me fix the test:
Assistant
The fix works. Now let me also test edge cases - what if I revert the fix temporarily to verify the test fails before the fix:
Assistant
Confirmed:
- Without my fix:
RangeTest.emptyObjectWithSuffixRangeSucceedsFAILS (returns 416) - With my fix:
RangeTest.emptyObjectWithSuffixRangeSucceedsPASSES (returns 200 with empty body)
Let me restore the fix:
- Without my fix:
Assistant
Now let me also test some edge cases to ensure the fix is robust:
Assistant
All 4 edge cases pass. Let me also verify the malformed range behavior is still preserved for empty objects:
Assistant
All edge cases work correctly:
- Empty +
bytes=-1: 200 OK with empty body ✓ - Empty +
bytes=-100: 200 OK with empty body ✓ - Empty without range: 200 OK with empty body ✓
- Empty +
bytes=-(malformed): 416 InvalidRange ✓
Now let me remove the temporary test file since I'm not supposed to add new tests to the repo:
- Empty +
Assistant
Now let me verify the existing tests still pass to confirm I haven't broken anything:
Assistant
Only the pre-existing failure. Let me also run the other S3 tests just to be thorough:
Assistant
Let me confirm this is a pre-existing failure unrelated to my change:
Assistant
Pre-existing failure unrelated to my fix. Let me verify my fix is still in place:
Assistant
Let me view the fix in context:
Assistant
The fix is in place. Let me now do a final summary and verification:
Assistant
Let me do a final review and verify my changes are clean:
Assistant
The fix is clean and minimal. Let me do one more sanity check by running the full S3 integration test to make sure nothing else broke:
Assistant
The only remaining test failure is a pre-existing one (
copyObjectWithNonAsciiKeySucceeds) that is completely unrelated to my fix - this test fails even without my changes due to non-ASCII key encoding (a locale-related issue with the test environment).Let me proceed with the submission and review my final implementation:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.