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
I'll start by exploring the repository to understand the structure and locate the relevant code. Let's first get an overview.
- Assistant
It's a Go repository. Let's find the S3Controller and handleRangeRequest method.
- Assistant
Let me search more broadly.
- Assistant
Let me check the repo structure more carefully. The issue description mentions "S3Controller.handleRangeRequest" and "Floci", but this might be a Java/TypeScript/etc project. Let me check the file structure.
- Assistant
This looks like a Java/Maven project (has pom.xml, mvnw). Let me find the Java source files.
- Assistant
Now let me find the S3Controller and handleRangeRequest method.
- Assistant
Let me look at the S3Controller to find the handleRangeRequest method.
- Assistant
Let me examine the full handleRangeRequest method.
- Assistant
Now I understand the issue. Let me look at the full handleRangeRequest method more closely and then create a reproduction script:
- Assistant
Let me look at the S3 tests to understand the existing test structure:
- Assistant
Let me look at those test methods to understand the test structure better.
- Assistant
Now I understand the issue. Let me trace through the logic for an empty object (totalSize = 0) with suffix range
bytes=-1:totalSize = 0rangeSpec = "-1"dash = 0(index of '-')before = ""(empty string before dash)after = "1"(after dash)- Since
before.isEmpty(), we go into the suffix range branch suffix = 1(parsed from "1")suffix > 0is true, so we don't return invalidstart = Math.max(0, totalSize - suffix) = Math.max(0, 0 - 1) = Math.max(0, -1) = 0end = totalSize - 1 = 0 - 1 = -1
Now we hit the validation check:
javaif (start < 0 || start >= totalSize || start > end) { return invalidRangeResponse(totalSize); } - Assistant
Now I understand the issue clearly. For an empty object (totalSize = 0) with suffix range
bytes=-1:suffix = 1,start = Math.max(0, 0 - 1) = 0,end = 0 - 1 = -1- The validation check:
if (start < 0 || start >= totalSize || start > end)→start >= totalSizeis true (0 >= 0), so it returnsinvalidRangeResponse.
The fix should handle empty objects specially. When totalSize is 0 and a suffix range is requested, we should return a 200 response with empty body. Let me check the full S3Controller to understand the code structure:
- Assistant
Let me also look at the getObject method that calls handleRangeRequest to understand the full flow:
- Assistant
Let me also check if there are any existing tests for empty objects with range requests:
- Assistant
Now let me create a reproduction script to confirm the bug. First, let me check if there's a way to run the tests:
- Assistant
Now I understand the problem. The issue is in the
handleRangeRequestmethod. WhentotalSize = 0(empty object), a suffix range request likebytes=-1computesstart = 0andend = -1, then the validationstart >= totalSize(0 >= 0) triggers an InvalidRange error.The fix should handle empty objects specially. According to AWS behavior, for an empty object, a suffix range request like
bytes=-1should return HTTP 200 with an empty body.Let me now implement the fix. I'll edit the
handleRangeRequestmethod: - Assistant
Now I understand the full picture. Let me analyze what happens for an empty object (
totalSize = 0) with suffix rangebytes=-1:suffix = 1(passessuffix <= 0check)start = Math.max(0, 0 - 1) = 0end = totalSize - 1 = 0 - 1 = -1
Then the validation check:
start >= totalSize→0 >= 0→ true → returns InvalidRange.The same issue also affects other range types on empty objects. For
bytes=0-on empty object:start = 0,end = totalSize - 1 = -1start > end→0 > -1→ true → also returns InvalidRange.
According to AWS behavior, range requests on empty objects should return HTTP 200 with an empty body. Let me implement the fix:
- Assistant
Good. The fix is in place. Now let me run the existing S3 tests to verify the fix doesn't break anything:
- Assistant
Let me check how to run tests in this project.
- Assistant
Let me check how to run the Maven build properly.
- Assistant
Good - the only failure is
copyObjectWithNonAsciiKeySucceedswhich is unrelated to my change (it's a pre-existing issue). All 97 range-related tests passed. Let me verify this test was already failing before my change by checking: - Assistant
Good - the test failure is pre-existing. Let me restore my change:
- Assistant
Now let me run the specific range-related tests to verify my fix works correctly:
- Assistant
Those tests depend on test fixtures set up earlier in the test class. The full suite passed except for the pre-existing failure. Let me also verify the existing S3 tests pass (minus the pre-existing failure):
- Assistant
Let me verify my fix is correct by checking the diff:
- Assistant
Let me now run the full S3 test suite to verify all range-related tests pass:
- Assistant
All 97 other tests pass. The only failure is the pre-existing
copyObjectWithNonAsciiKeySucceedstest which was already failing before my change. All range-related tests pass.Now let me verify my fix handles the exact scenario from the bug report. Let me create a simple script to test the logic:
- Assistant
The test confirms the issue and the fix. Now let me verify the fix also handles other edge cases properly:
- Assistant
All edge cases look correct:
- Empty object with any valid range spec returns 200 OK with empty body
- Empty object with invalid range specs (
bytes=-0,bytes=-) still return 416 - Non-empty object behavior is unchanged
Now let me also check if there are other tests in the repo that might test range requests:
- Assistant
Let me check the S3 test files for range-related tests:
- Assistant
Let me also check the S3MultipartIntegrationTest for range tests:
- Assistant
Let me run all S3 tests to make sure nothing breaks:
- Assistant
All 145 S3 tests pass except for the pre-existing
copyObjectWithNonAsciiKeySucceedsfailure. Let me verify the final change once more: - Assistant
Let me clean up the temporary files:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.