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 structure to understand the codebase and locate the relevant code for S3 GetObject handling. Let's first check the current directory and look for files.
- Assistant
Let me search for S3-related files and specifically the S3Controller that handles range requests.
- Assistant
Let me examine the S3Controller.java file to understand the current implementation.
- Assistant
Let me look at the handleRangeRequest method to understand the current implementation.
- Assistant
- Assistant
Now I understand the issue clearly. For an empty object (
totalSize = 0) with a suffix range request likebytes=-1:beforeis empty,afteris "1"suffix = 1(passes thesuffix <= 0check)start = Math.max(0, 0 - 1) = 0end = 0 - 1 = -1- Validation:
start >= totalSize→0 >= 0→ true → returns 416
But according to AWS behavior, a suffix range request on an empty object should return a 206 with
Content-Range: bytes */0and an empty body. Let me first check if there are existing tests for this: - Assistant
Let me check the S3 integration tests to see if there are existing range tests.
- Assistant
Now I understand the issue clearly. Let me look at the exact range handling logic. For an empty object (
totalSize = 0) with suffix rangebytes=-1:suffix = 1(passessuffix <= 0check)start = Math.max(0, 0 - 1) = 0end = 0 - 1 = -1- Then
start > end(0 > -1) is true → returns 416 InvalidRange
According to AWS behavior, for a suffix range on an empty object, the response should be a 206 with
Content-Range: bytes */0. Let me fix this: - Assistant
Now I have a clear understanding of the issue. The problem is in
handleRangeRequestat lines 629-645. For an empty object (totalSize = 0) with suffix rangebytes=-1:suffix = 1(passessuffix <= 0check)start = Math.max(0, 0 - 1) = 0end = 0 - 1 = -1- Then
start > end(0 > -1) ANDstart >= totalSize(0 >= 0) → returns 416 InvalidRange
According to AWS behavior, a suffix range on an empty object should return 206 with
Content-Range: bytes */0and an empty body. Let me fix this: - Assistant
Now I'll fix the issue. The problem is in the suffix range handling for empty objects. When
totalSize == 0:suffixcan be any positive integer (e.g., 1 forbytes=-1)start = Math.max(0, 0 - suffix) = 0end = 0 - 1 = -1- Then
start > end(0 > -1) is true, so we returninvalidRangeResponse
According to AWS behavior, requesting
bytes=-1on an empty object should return a 206 response withContent-Range: bytes */0and empty body. Let me fix this: - Assistant
I see there's a syntax error - there's an extra
}at line 663. Let me fix that: - Assistant
I see there's an extra
}at line 663 that needs to be removed. Let me fix that: - Assistant
Good, the extra
}is removed. Let me verify the completehandleRangeRequestmethod: - Assistant
The fix looks good. Let me verify the logic:
-
For an empty object with
bytes=-1:suffix = 1(passessuffix <= 0check)totalSize == 0→ returns 206 withContent-Range: bytes */0and empty body ✓
-
For an empty object with
bytes=-0:suffix = 0→ failssuffix <= 0check → returns invalidRangeResponse ✓
-
For a non-empty object with suffix range:
totalSize > 0→ proceeds to normal suffix range handling ✓
-
For a non-empty object with normal range:
- Goes to
elsebranch ✓
- Goes to
Let me check the existing tests to make sure they still pass. First, let me look at the existing range tests:
-
- Assistant
Let me check the project structure and how to run the tests:
- Assistant
Let me check if there's a Maven wrapper available and run the existing S3 integration tests:
- Assistant
Let me try setting HOME and running the tests.
- Assistant
The test failure is in
copyObjectWithNonAsciiKeySucceedsat line 372, which is unrelated to my change (it's about non-ASCII keys, not about range requests on empty objects). The range-related tests should have passed. Let me run just the range-related tests to confirm they pass: - Assistant
The individual test method run is failing because the test depends on state from earlier test methods (bucket creation, object upload). Let me check the test structure to understand test ordering:
- Assistant
The tests are failing because they depend on previous test state. Let me run the full test suite and just check the range-related tests:
- Assistant
The only failure is
copyObjectWithNonAsciiKeySucceedswhich is a pre-existing issue unrelated to my change (it's about non-ASCII keys). All the range tests passed. Now let me also write a small reproduction test to verify my fix works correctly: - Assistant
Let me verify the
appendObjectHeadersmethod signature to make sure my call is correct: - Assistant
Let me check the method signature more carefully:
- Assistant
Good, the method signatures are correct. Now let me verify the changes look clean with a diff:
- Assistant
The diff looks clean. Now let me write a quick reproduction test to confirm the fix works. First, let me check if there's a way to test this directly:
- Assistant
Good - only 1 failure and it's the pre-existing
copyObjectWithNonAsciiKeySucceedstest, which is unrelated to range handling. Let me also run the S3ServiceTest: - Assistant
Let me check the test results.
- Assistant
Let me see what error occurred in S3ServiceTest.
- Assistant
Good. Both the
S3IntegrationTest.copyObjectWithNonAsciiKeySucceedsfailure and theS3ServiceTest.copyObjectWithNonASCIIKeyerror are pre-existing issues unrelated to our change (they're about non-ASCII characters in keys/paths).Now let me verify the final diff looks correct:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.