Skip to content

Commit 5af9b80

Browse files
committed
Fix SyncChecksumValidationInterceptor and AsyncChecksumValidationInterceptor to use long instead of int for contentLength
1 parent b9a2e77 commit 5af9b80

File tree

5 files changed

+20
-9
lines changed

5 files changed

+20
-9
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"category": "Amazon S3",
3+
"type": "bugfix",
4+
"description": "Fix `SyncChecksumValidationInterceptor` and `AsyncChecksumValidationInterceptor` to use `long` instead of `int` for contentLength`. See [#963](https://github.com/aws/aws-sdk-java-v2/issues/963)"
5+
}

services/s3/src/main/java/software/amazon/awssdk/services/s3/checksums/ChecksumValidatingInputStream.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class ChecksumValidatingInputStream extends InputStream implements Aborta
4343
* @param cksum the Checksum implementation
4444
* @param streamLength the total length of the expected stream (including the extra 4 bytes on the end).
4545
*/
46-
public ChecksumValidatingInputStream(final InputStream in, final SdkChecksum cksum, long streamLength) {
46+
public ChecksumValidatingInputStream(InputStream in, SdkChecksum cksum, long streamLength) {
4747
inputStream = in;
4848
checkSum = cksum;
4949
this.strippedLength = streamLength - CHECKSUM_SIZE;

services/s3/src/main/java/software/amazon/awssdk/services/s3/checksums/ChecksumValidatingPublisher.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@
2929
import software.amazon.awssdk.utils.BinaryUtils;
3030

3131
@SdkInternalApi
32-
public class ChecksumValidatingPublisher implements SdkPublisher<ByteBuffer> {
32+
public final class ChecksumValidatingPublisher implements SdkPublisher<ByteBuffer> {
3333

3434
private final Publisher<ByteBuffer> publisher;
3535
private final SdkChecksum sdkChecksum;
36-
private final int contentLength;
36+
private final long contentLength;
3737

3838
public ChecksumValidatingPublisher(Publisher<ByteBuffer> publisher,
3939
SdkChecksum sdkChecksum,
40-
int contentLength) {
40+
long contentLength) {
4141
this.publisher = publisher;
4242
this.sdkChecksum = sdkChecksum;
4343
this.contentLength = contentLength;
@@ -59,11 +59,9 @@ private static class ChecksumValidatingSubscriber implements Subscriber<ByteBuff
5959
private byte[] streamChecksum = new byte[CHECKSUM_SIZE];
6060
private long lengthRead = 0;
6161

62-
private Subscription subscription;
63-
6462
ChecksumValidatingSubscriber(Subscriber<? super ByteBuffer> wrapped,
6563
SdkChecksum sdkChecksum,
66-
int contentLength) {
64+
long contentLength) {
6765
this.wrapped = wrapped;
6866
this.sdkChecksum = sdkChecksum;
6967
this.strippedLength = contentLength - CHECKSUM_SIZE;

services/s3/src/main/java/software/amazon/awssdk/services/s3/internal/handlers/AsyncChecksumValidationInterceptor.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package software.amazon.awssdk.services.s3.internal.handlers;
1717

1818
import static software.amazon.awssdk.core.ClientType.ASYNC;
19+
import static software.amazon.awssdk.services.s3.checksums.ChecksumConstant.CONTENT_LENGTH_HEADER;
1920

2021
import java.nio.ByteBuffer;
2122
import java.util.Arrays;
@@ -71,7 +72,11 @@ public Optional<Publisher<ByteBuffer>> modifyAsyncHttpResponseContent(Context.Mo
7172
context.httpRequest().headers());
7273

7374
if (context.request() instanceof GetObjectRequest && checksumValidationEnabled) {
74-
int contentLength = Integer.parseInt(context.httpResponse().firstMatchingHeader("Content-Length").orElse("0"));
75+
long contentLength = context.httpResponse()
76+
.firstMatchingHeader(CONTENT_LENGTH_HEADER)
77+
.map(Long::parseLong)
78+
.orElse(0L);
79+
7580
SdkChecksum checksum = new Md5Checksum();
7681
executionAttributes.putAttribute(CHECKSUM, checksum);
7782
return Optional.of(new ChecksumValidatingPublisher(context.responsePublisher().get(), checksum, contentLength));

services/s3/src/main/java/software/amazon/awssdk/services/s3/internal/handlers/SyncChecksumValidationInterceptor.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@ public Optional<InputStream> modifyHttpResponseContent(Context.ModifyHttpRespons
8181
if (context.request() instanceof GetObjectRequest && checksumValidationEnabled) {
8282
SdkChecksum checksum = new Md5Checksum();
8383

84-
int contentLength = Integer.valueOf(context.httpResponse().firstMatchingHeader(CONTENT_LENGTH_HEADER).orElse("0"));
84+
long contentLength = context.httpResponse()
85+
.firstMatchingHeader(CONTENT_LENGTH_HEADER)
86+
.map(Long::parseLong)
87+
.orElse(0L);
8588

8689
if (contentLength > 0) {
8790
return Optional.of(new ChecksumValidatingInputStream(context.responseBody().get(), checksum, contentLength));

0 commit comments

Comments
 (0)