Skip to content

Commit

Permalink
Skip multiple CRLF if present.
Browse files Browse the repository at this point in the history
For unknown reasons, when using the async clients to upload chunked
data, the SDK sometimes inserts multiple CRLFs between chunks.
Skip if we need to.

Fixes #1840
Fixes #1842
  • Loading branch information
afranken committed May 12, 2024
1 parent f65b922 commit adb47e0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public AwsChunkedDecodingChecksumInputStream(InputStream source, long decodedLen
public int read() throws IOException {
if (chunkLength == 0L) {
//try to read chunk length
var hexLengthBytes = readUntil(DELIMITER);
var hexLengthBytes = readHexLength();
if (hexLengthBytes.length == 0) {
return -1;
}
Expand All @@ -88,4 +88,8 @@ public int read() throws IOException {

return source.read();
}

private byte[] readHexLength() throws IOException {
return readUntil(DELIMITER);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public AwsUnsignedChunkedDecodingChecksumInputStream(InputStream source, long de
public int read() throws IOException {
if (chunkLength == 0L) {
//try to read chunk length
var hexLengthBytes = readUntil(CRLF);
var hexLengthBytes = readHexlength();
if (hexLengthBytes.length == 0) {
return -1;
}
Expand All @@ -87,4 +87,12 @@ public int read() throws IOException {

return source.read();
}

private byte[] readHexlength() throws IOException {
var hexLengthBytes = readUntil(CRLF);
if (hexLengthBytes.length == 0) {
hexLengthBytes = readUntil(CRLF);
}
return hexLengthBytes;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2023 Adobe.
* Copyright 2017-2024 Adobe.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,7 +19,6 @@
import static com.adobe.testing.s3mock.util.TestUtil.getTestFile;
import static org.assertj.core.api.Assertions.assertThat;

import java.io.IOException;
import java.util.Arrays;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.ArrayUtils;
Expand All @@ -29,7 +28,7 @@
class DigestUtilTest {

@Test
void testHexDigestOfMultipleFiles(TestInfo testInfo) throws IOException {
void testHexDigestOfMultipleFiles(TestInfo testInfo) {
//yes, this is correct - AWS calculates a Multipart digest by calculating the digest of every
//file involved, and then calculates the digest on the result.
//a hyphen with the part count is added as a suffix.
Expand Down

0 comments on commit adb47e0

Please sign in to comment.