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,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /floci, current file: none) bash-$
- Floci version / image tag:
Assistant
Let me start by exploring the repository structure to understand the codebase.
Assistant
Let me explore the repository structure further.
Assistant
Let me search for the relevant
handleRangeRequestmethod.Assistant
Let me also look at the calling code and the context where the range header is parsed.
Assistant
Let me look at the structure of the project and understand how to set up/build it.
Assistant
Let me look at the tests in more detail to understand the existing testing infrastructure.
Assistant
Let me look at the broader context of the S3 controller, particularly the
getObjecthandler.Assistant
Let me look at how the test is set up to understand the testing infrastructure better.
Assistant
Let me check if I can build and test the project first.
Assistant
Let me try the tests first to check we have everything we need.
Assistant
Let me check what
S3Objectlooks like to understand how empty objects are stored.Assistant
Let me see the
appendObjectHeadersmethod to understand the response building pattern.Assistant
Let me first reproduce the issue by running the existing tests to see the current state.
Assistant
Let me check if there are existing tests on empty objects with Range.
Assistant
Let me first build the project to make sure everything compiles before making changes.
Assistant
The build succeeded. Let me try running a single S3 test to verify the test infrastructure works.
Assistant
The test failed because it depends on previous tests. Let me run all the tests to set up properly.
Assistant
Now I have a working test infrastructure. Let me create a small Java program to reproduce the bug first.
Assistant
Let me check if I can create a temporary test that reproduces the bug without affecting the existing tests.
Assistant
Let me write a temporary test file to reproduce the bug first.
Assistant
I successfully reproduced the bug. The test fails with
Expected status code <200> but was <416>. Now let me apply the fix.Assistant
Let me look at what helpers already exist for response building.
Assistant
Let me look at the current code in getObject and handleRangeRequest carefully to design a clean refactor.
Assistant
Let me search for any existing tests on empty objects that might be impacted.
Assistant
Now let me make the fix. I'll refactor to extract a helper method, then add the early-return guard for empty objects.
Assistant
Let me check how S3Object.size and S3Object.data are set.
Assistant
Let me look at the S3Object constructor to see how size is set.
Assistant
Let me trace through how
getObjectretrieves objects.Assistant
Now I have a complete understanding of the code. Let me apply the fix by refactoring
handleRangeRequestand thegetObjectmethod to share response-building logic, and add the early-return guard for empty objects.Assistant
Let me apply the fix by extracting a helper method and adding the empty object handling.
Assistant
Let me make the precise changes to the controller. First, let me check the exact context around the getObject response builder.
Assistant
Let me make the change using the
replacecommand to be safe.Assistant
Let me use perl for the replacement.
Assistant
Let me verify the changes look correct.
Assistant
Let me build and test the change.
Assistant
The fix works! Let me extend the test to cover more edge cases.
Assistant
All 4 edge case tests pass. Now let me run the existing S3 integration tests to make sure I haven't broken anything.
Assistant
Only one test fails (
copyObjectWithNonAsciiKeySucceeds), which was failing before my changes too. Let me verify by checking git diff.Assistant
Let me check that the
copyObjectWithNonAsciiKeySucceedswas already failing before my changes.Assistant
Now let me run additional S3 tests to ensure I haven't broken anything.
Assistant
The tests need to run in order (they depend on prior setup). Let me run the full S3IntegrationTest class.
Assistant
Let me confirm this was a pre-existing failure by running with the original code.
Assistant
Confirmed -
copyObjectWithNonAsciiKeySucceedsfails before my changes too. Let me see the Range-related test results specifically.Assistant
All Range-related tests pass. Let me run a few more S3 tests to verify everything is fine.
Assistant
All S3 tests pass except the pre-existing failure. Let me do a comprehensive review of my changes one more time.
Assistant
Let me check if any other code references the changed methods.
Assistant
I should clean up the temporary test file I created, since I was instructed not to add new tests.
Assistant
Let me run the full set of S3 tests one more time to verify everything is fine.
Assistant
Let me check the new error in S3ServiceTest.
Assistant
This is also pre-existing - related to file path encoding and the locale of the JVM. It's NOT related to my fix.
Let me verify this is pre-existing too.
Assistant
Confirmed - both pre-existing failures are unrelated to my fix. Let me verify the final state of my changes.
Assistant
Let me verify that
readFilereturns an empty byte array (not null) for empty objects.Assistant
Let me also check
readVersionedFile:Assistant
Let me check
getObjectMetadatato understand how a missing key is handled.Assistant
Let me think carefully about my changes once more. The removal of
start >= totalSizefrom the validation check could potentially be safer to keep (even if redundant) for minimal change risk. Let me restore it to be safer.Assistant
Let me do a final review of the diff and make sure everything is good.
Assistant
Let me do one final verification by running all S3 integration tests one more time.
Assistant
Let me also temporarily re-create the reproduction test one more time to confirm the fix is still working.
Assistant
All edge cases pass. Now let me clean up by removing the temporary test file.
Assistant
Let me run a final sanity check and ensure nothing else is broken.
Assistant
Let me run one more S3 test to confirm.
Assistant
Let me do a final review of my changes by looking at the relevant sections.
Assistant
Let me run the final compilation to verify everything is correct.
Assistant
Let me do a final compilation check to confirm everything is good.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →