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
Now I can see the
handleRangeRequestmethod. Let me understand the issue better:When a suffix range request (e.g.,
bytes=-1) is made against an empty object:totalSize = 0(since the object is empty)rangeSpec = "-1"dash = 0before = "",after = "1"- It goes into
if (before.isEmpty())branch suffix = 1, which is positivestart = Math.max(0, 0 - 1) = Math.max(0, -1) = 0end = totalSize - 1 = 0 - 1 = -1- Then the check
if (start < 0 || start >= totalSize || start > end)->start >= totalSizeis true (since 0 >= 0), so it returnsinvalidRangeResponse.
The fix should handle empty objects correctly. According to AWS spec, for a range request on an empty object, the response should still be 206 with content length 0 (per Trino's expectation), or possibly a 416.
Let me check how AWS actually handles this. Let me look at the invalidRangeResponse method first:
Assistant
Let me look at the existing tests for range request handling:
Assistant
Let me look at how the controller handles the case where there's no range for an empty object:
Assistant
Let me investigate the compatibility tests and look at any similar tests for empty objects:
Assistant
No range-related tests in the AWS CLI compatibility tests. Let me look at the Java SDK tests:
Assistant
Let me look at the test for the empty key:
Assistant
Let me look at how the test bucket is set up:
Assistant
Now let me look at the existing testing approach and figure out the simplest way to reproduce and test the issue:
Assistant
Let me first check if there's a way to run a quick test directly:
Assistant
Let me first try to compile and run the existing tests:
Assistant
Let me make a script to reproduce the issue:
Assistant
Now I need to set HOME for all subsequent commands. Let me run the build first:
Assistant
The tests are order-dependent. Let me run the full S3IntegrationTest:
Assistant
97 out of 98 tests pass - one unrelated test fails (non-ASCII key). Let me check the range tests specifically:
Assistant
Now let me re-examine the code and determine the cleanest fix:
Assistant
Let me check the existing codebase for similar patterns:
Assistant
Let me look at the git history for clues on this issue:
Assistant
Now let me create a reproducer to verify the issue. I'll write a unit test directly first to confirm:
Assistant
Let me look at all the existing range tests to make sure I don't break anything:
Assistant
Now I have a clear understanding. Let me check how the AWS SDK v2 accepts Content-Range for empty responses by looking at similar patterns in tests:
Assistant
Let me also check what AWS Java SDK v2 (used by Trino) does for an empty response. Let me look at the available SDK JAR files or code patterns:
Assistant
The AWS SDK is not in m2 cache. Let me look at the AWS Java SDK v2 source online to see how it handles the Content-Range header for empty responses. Actually, since we can't access the internet, let me look at the AWS documentation that's been downloaded:
Assistant
Now let me implement the fix. I'll modify the
handleRangeRequestmethod to handle the empty object + suffix range case correctly:Assistant
Now let me implement the fix:
Assistant
Let me look at the full new method:
Assistant
Let me run the existing tests to verify my fix doesn't break anything:
Assistant
All existing tests pass. Now let me write a temporary test to verify the fix works. Since I shouldn't modify the existing tests, let me create a temporary script:
Assistant
Let me create a standalone test class to verify the fix without polluting the test directory:
Assistant
Excellent! All my temporary tests pass. The fix works correctly. Now let me verify the fix doesn't break any existing tests by running the full S3IntegrationTest:
Assistant
97 out of 98 tests pass. The only failure is
copyObjectWithNonAsciiKeySucceedswhich is unrelated to our change. Let me confirm this is a pre-existing failure:Assistant
The test failure exists before our change too, so it's a pre-existing issue unrelated to my fix. Let me check edge cases:
Assistant
Let me test additional edge cases by adding more test cases to my temporary test file:
Assistant
All 14 of my temporary tests pass. The fix handles all the edge cases correctly. Let me also verify the complete diff:
Assistant
Let me simplify the diff to be more focused. I'll revert the unnecessary refactoring:
Assistant
Now let me verify the cleaner diff:
Assistant
Now let me run the temporary tests again to make sure everything still works:
Assistant
All 14 tests pass. Let me now run the full S3IntegrationTest to make sure I haven't broken anything:
Assistant
Same pre-existing failure. Let me also run a broader set of S3 tests:
Assistant
Only 2 failures out of 512 tests, both related to non-ASCII keys (pre-existing issue). Let me also remove the temporary test file and verify the fix works:
Assistant
Let me verify my fix handles the AWS CLI reproduction scenario by starting a server and testing it:
Assistant
Let me check the start scripts:
Assistant
Let me start the Floci server in dev mode and test the AWS CLI reproduction:
Assistant
Excellent! The fix works correctly. Let me test a few more cases to verify edge cases:
Assistant
All edge cases work correctly. Let me also test the regression cases for non-empty objects:
Assistant
All scenarios work correctly. Let me kill the dev server:
Assistant
Server is stopped. Let me run the S3IntegrationTest one more time to ensure everything is fine:
Assistant
All 13 existing range-related tests still pass. Let me see the final diff:
Assistant
Let me create my temporary test file once more for a final comprehensive check:
Assistant
All 14 tests pass! Let me remove the temporary test file:
Assistant
The only change is to the source file. Let me also do a final check to make sure my fix has no compile errors:
Assistant
Both compile successfully. Let me look at the final state of the modified code:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.