Skip to content

Commit 91a0390

Browse files
committed
fix: unbounded streams are not supported
1 parent 44e9886 commit 91a0390

File tree

4 files changed

+69
-15
lines changed

4 files changed

+69
-15
lines changed

pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
<dependency>
5757
<groupId>software.amazon.awssdk</groupId>
5858
<artifactId>bom</artifactId>
59-
<version>2.28.28</version>
59+
<version>2.29.29</version>
6060
<optional>true</optional>
6161
<type>pom</type>
6262
<scope>import</scope>
@@ -68,21 +68,21 @@
6868
<dependency>
6969
<groupId>software.amazon.awssdk</groupId>
7070
<artifactId>s3</artifactId>
71-
<version>2.28.28</version>
71+
<version>2.29.29</version>
7272
</dependency>
7373

7474
<dependency>
7575
<groupId>software.amazon.awssdk</groupId>
7676
<artifactId>kms</artifactId>
77-
<version>2.28.28</version>
77+
<version>2.29.29</version>
7878
</dependency>
7979

8080
<!-- Used when enableMultipartPutObject is configured -->
8181
<dependency>
8282
<groupId>software.amazon.awssdk.crt</groupId>
8383
<artifactId>aws-crt</artifactId>
8484
<optional>true</optional>
85-
<version>0.31.3</version>
85+
<version>0.33.5</version>
8686
</dependency>
8787

8888
<dependency>
@@ -163,7 +163,7 @@
163163
<dependency>
164164
<groupId>software.amazon.awssdk</groupId>
165165
<artifactId>sts</artifactId>
166-
<version>2.28.28</version>
166+
<version>2.29.29</version>
167167
<optional>true</optional>
168168
<scope>test</scope>
169169
</dependency>

src/main/java/software/amazon/encryption/s3/internal/CipherAsyncRequestBody.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import org.reactivestreams.Subscriber;
66
import software.amazon.awssdk.core.async.AsyncRequestBody;
7+
import software.amazon.encryption.s3.S3EncryptionClientException;
78
import software.amazon.encryption.s3.materials.CryptographicMaterials;
89

910
import java.nio.ByteBuffer;
@@ -35,7 +36,9 @@ public CipherAsyncRequestBody(final AsyncRequestBody wrappedAsyncRequestBody, fi
3536

3637
@Override
3738
public void subscribe(Subscriber<? super ByteBuffer> subscriber) {
38-
wrappedAsyncRequestBody.subscribe(new CipherSubscriber(subscriber, contentLength().orElse(-1L), materials, iv));
39+
wrappedAsyncRequestBody.subscribe(new CipherSubscriber(subscriber,
40+
contentLength().orElseThrow(() -> new S3EncryptionClientException("Unbounded streams are currently not supported.")),
41+
materials, iv));
3942
}
4043

4144
@Override

src/main/java/software/amazon/encryption/s3/internal/PutEncryptedObjectPipeline.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public CompletableFuture<PutObjectResponse> putObject(PutObjectRequest request,
5353
contentLength = request.contentLength();
5454
}
5555
} else {
56-
contentLength = requestBody.contentLength().orElse(-1L);
56+
contentLength = requestBody.contentLength().orElseThrow(() -> new S3EncryptionClientException("Unbounded streams are currently not supported."));
5757
}
5858

5959
if (contentLength > AlgorithmSuite.ALG_AES_256_GCM_IV12_TAG16_NO_KDF.cipherMaxContentLengthBytes()) {

src/test/java/software/amazon/encryption/s3/S3EncryptionClientStreamTest.java

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,16 @@
1717
import software.amazon.awssdk.core.ResponseInputStream;
1818
import software.amazon.awssdk.core.async.AsyncRequestBody;
1919
import software.amazon.awssdk.core.async.AsyncResponseTransformer;
20+
import software.amazon.awssdk.core.async.BlockingInputStreamAsyncRequestBody;
2021
import software.amazon.awssdk.core.sync.RequestBody;
2122
import software.amazon.awssdk.services.s3.S3AsyncClient;
2223
import software.amazon.awssdk.services.s3.S3Client;
2324
import software.amazon.awssdk.services.s3.model.GetObjectResponse;
2425
import software.amazon.awssdk.services.s3.model.PutObjectRequest;
2526
import software.amazon.awssdk.services.s3.model.PutObjectResponse;
2627
import software.amazon.awssdk.utils.IoUtils;
27-
import software.amazon.encryption.s3.utils.BoundedStreamBufferer;
2828
import software.amazon.encryption.s3.utils.BoundedInputStream;
29+
import software.amazon.encryption.s3.utils.BoundedStreamBufferer;
2930
import software.amazon.encryption.s3.utils.MarkResetBoundedZerosInputStream;
3031
import software.amazon.encryption.s3.utils.S3EncryptionClientTestResources;
3132

@@ -135,6 +136,56 @@ public void ordinaryInputStreamV3Encrypt() throws IOException {
135136
v3Client.close();
136137
}
137138

139+
@Test
140+
public void ordinaryInputStreamV3UnboundedAsync() {
141+
try (S3AsyncClient s3AsyncEncryptionClient = S3AsyncEncryptionClient.builder().aesKey(AES_KEY).build()) {
142+
final String objectKey = appendTestSuffix("ordinaryInputStreamV3UnboundedAsync");
143+
BlockingInputStreamAsyncRequestBody body =
144+
AsyncRequestBody.forBlockingInputStream(null);
145+
try {
146+
s3AsyncEncryptionClient.putObject(r -> r.bucket(BUCKET).key(objectKey), body);
147+
fail("Expected exception!");
148+
} catch (S3EncryptionClientException exception) {
149+
// expected
150+
assertTrue(exception.getMessage().contains("Unbounded streams are currently not supported"));
151+
}
152+
}
153+
}
154+
155+
@Test
156+
public void ordinaryInputStreamV3UnboundedMultipartAsync() {
157+
try (S3AsyncClient s3AsyncEncryptionClient = S3AsyncEncryptionClient.builder().aesKey(AES_KEY).enableMultipartPutObject(true).wrappedClient(s3AsyncClient).build()) {
158+
final String objectKey = appendTestSuffix("ordinaryInputStreamV3UnboundedAsync");
159+
BlockingInputStreamAsyncRequestBody body =
160+
AsyncRequestBody.forBlockingInputStream(null);
161+
try {
162+
s3AsyncEncryptionClient.putObject(r -> r.bucket(BUCKET).key(objectKey), body);
163+
fail("Expected exception!");
164+
} catch (S3EncryptionClientException exception) {
165+
// expected
166+
assertTrue(exception.getMessage().contains("Unbounded streams are currently not supported"));
167+
}
168+
}
169+
}
170+
171+
@Test
172+
public void ordinaryInputStreamV3UnboundedCrt() {
173+
try (S3AsyncClient s3CrtAsyncClient = S3AsyncClient.crtCreate()) {
174+
try (S3AsyncClient s3AsyncEncryptionClient = S3AsyncEncryptionClient.builder().aesKey(AES_KEY).enableMultipartPutObject(true).wrappedClient(s3CrtAsyncClient).build()) {
175+
final String objectKey = appendTestSuffix("ordinaryInputStreamV3UnboundedCrt");
176+
BlockingInputStreamAsyncRequestBody body =
177+
AsyncRequestBody.forBlockingInputStream(null);
178+
try {
179+
s3AsyncEncryptionClient.putObject(r -> r.bucket(BUCKET).key(objectKey), body);
180+
fail("Expected exception!");
181+
} catch (S3EncryptionClientException exception) {
182+
// expected
183+
assertTrue(exception.getMessage().contains("Unbounded streams are currently not supported"));
184+
}
185+
}
186+
}
187+
}
188+
138189
@Test
139190
public void ordinaryInputStreamV3Decrypt() throws IOException {
140191
final String objectKey = appendTestSuffix("ordinaryInputStreamV3Decrypt");
@@ -274,9 +325,9 @@ public void customSetBufferSizeWithLargeObject() throws IOException {
274325
final long fileSizeExceedingDefaultLimit = 1024 * 1024 * 32 + 1;
275326
final InputStream largeObjectStream = new BoundedInputStream(fileSizeExceedingDefaultLimit);
276327
v3ClientWithBuffer32MiB.putObject(PutObjectRequest.builder()
277-
.bucket(BUCKET)
278-
.key(objectKey)
279-
.build(), RequestBody.fromInputStream(largeObjectStream, fileSizeExceedingDefaultLimit));
328+
.bucket(BUCKET)
329+
.key(objectKey)
330+
.build(), RequestBody.fromInputStream(largeObjectStream, fileSizeExceedingDefaultLimit));
280331

281332
largeObjectStream.close();
282333

@@ -327,9 +378,9 @@ public void customSetBufferSizeWithLargeObjectAsyncClient() throws IOException {
327378
final InputStream largeObjectStream = new BoundedInputStream(fileSizeExceedingDefaultLimit);
328379
ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor();
329380
CompletableFuture<PutObjectResponse> futurePut = v3ClientWithBuffer32MiB.putObject(PutObjectRequest.builder()
330-
.bucket(BUCKET)
331-
.key(objectKey)
332-
.build(), AsyncRequestBody.fromInputStream(largeObjectStream, fileSizeExceedingDefaultLimit, singleThreadExecutor));
381+
.bucket(BUCKET)
382+
.key(objectKey)
383+
.build(), AsyncRequestBody.fromInputStream(largeObjectStream, fileSizeExceedingDefaultLimit, singleThreadExecutor));
333384

334385
futurePut.join();
335386
largeObjectStream.close();
@@ -387,7 +438,7 @@ public void delayedAuthModeWithLargeObject() throws IOException {
387438
assertThrows(S3EncryptionClientException.class, () -> v3Client.getObjectAsBytes(builder -> builder
388439
.bucket(BUCKET)
389440
.key(objectKey)));
390-
441+
391442
S3Client v3ClientWithDelayedAuth = S3EncryptionClient.builder()
392443
.aesKey(AES_KEY)
393444
.enableDelayedAuthenticationMode(true)

0 commit comments

Comments
 (0)