Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

fix(s3): omit whole-object checksum headers on range responses (#1040)

Ahmed Soliman25d698895006
diff --git a/src/main/java/io/github/hectorvent/floci/services/s3/S3Controller.java b/src/main/java/io/github/hectorvent/floci/services/s3/S3Controller.java
index 4fe97c289c..16cc36423f 100644
--- a/src/main/java/io/github/hectorvent/floci/services/s3/S3Controller.java
+++ b/src/main/java/io/github/hectorvent/floci/services/s3/S3Controller.java
@@ -653,7 +653,8 @@ public class S3Controller {
if (obj.getVersionId() != null) {
resp.header("x-amz-version-id", obj.getVersionId());
}
- appendObjectHeaders(resp, obj, overrides);
+ // includeChecksum=false: the stored checksum covers the whole object, not this range.
+ appendObjectHeaders(resp, obj, overrides, false);
return resp.build();
}
@@ -1547,6 +1548,14 @@ public class S3Controller {
}
private void appendObjectHeaders(Response.ResponseBuilder resp, S3Object obj, ResponseHeaderOverrides overrides) {
+ appendObjectHeaders(resp, obj, overrides, true);
+ }
+
+ // includeChecksum must be false for partial (206) responses: obj.getChecksum() is the
+ // whole-object checksum, which does not match the range bytes returned. SDKs that
+ // validate it against the received body fail. Real S3 omits it on ranged responses.
+ private void appendObjectHeaders(Response.ResponseBuilder resp, S3Object obj, ResponseHeaderOverrides overrides,
+ boolean includeChecksum) {
if (obj.getStorageClass() != null) {
resp.header("x-amz-storage-class", obj.getStorageClass());
}
@@ -1576,7 +1585,9 @@ public class S3Controller {
resp.header("x-amz-meta-" + entry.getKey(), entry.getValue());
}
}
- appendChecksumHeaders(resp, obj.getChecksum());
+ if (includeChecksum) {
+ appendChecksumHeaders(resp, obj.getChecksum());
+ }
appendLockHeaders(resp, obj);
}
diff --git a/src/test/java/io/github/hectorvent/floci/services/s3/S3IntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/s3/S3IntegrationTest.java
index ac1c66795a..35e7615cb9 100644
--- a/src/test/java/io/github/hectorvent/floci/services/s3/S3IntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/s3/S3IntegrationTest.java
@@ -572,6 +572,24 @@ class S3IntegrationTest {
.header("Accept-Ranges", equalTo("bytes"));
}
+ @Test
+ @Order(40)
+ void getObjectRangeOmitsWholeObjectChecksum() {
+ // greeting.txt has a stored whole-object CRC64NVME checksum (see getObject).
+ // A 206 partial response must NOT carry that checksum: it is computed over the
+ // full object, so SDKs that validate it against the received range bytes fail.
+ // Real S3 omits whole-object checksum headers on ranged responses.
+ given()
+ .header("Range", "bytes=4-7")
+ .when()
+ .get("/test-bucket/greeting.txt")
+ .then()
+ .statusCode(206)
+ .header("Content-Range", equalTo("bytes 4-7/20"))
+ .body(equalTo("o Wo"))
+ .header("x-amz-checksum-crc64nvme", nullValue());
+ }
+
@Test
@Order(50)
void getObjectIfNoneMatchReturns304() {