From 34b844fcaf6fc004e9d8f545c4d1b01777b18203 Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Wed, 24 Jun 2020 22:22:12 +0900 Subject: [PATCH] Do not accept multipart sizes less than 5 MB Continue to enforce greater minimum blob sizes when storage backend requires it. Fixes #324. --- src/main/java/org/gaul/s3proxy/S3ProxyHandler.java | 5 +++-- src/test/java/org/gaul/s3proxy/AwsSdkTest.java | 13 ++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/gaul/s3proxy/S3ProxyHandler.java b/src/main/java/org/gaul/s3proxy/S3ProxyHandler.java index e9cecfb8..4bf9e976 100644 --- a/src/main/java/org/gaul/s3proxy/S3ProxyHandler.java +++ b/src/main/java/org/gaul/s3proxy/S3ProxyHandler.java @@ -2257,8 +2257,9 @@ blobName, uploadId, new MutableBlobMetadataImpl(), throw new S3Exception(S3ErrorCode.INVALID_PART); } long partSize = part.partSize(); - if (partSize < blobStore.getMinimumMultipartPartSize() && - partSize != -1 && it.hasNext()) { + if (it.hasNext() && partSize != -1 && + (partSize < 5 * 1024 * 1024 || partSize < + blobStore.getMinimumMultipartPartSize())) { throw new S3Exception(S3ErrorCode.ENTITY_TOO_SMALL); } if (part.partETag() != null && diff --git a/src/test/java/org/gaul/s3proxy/AwsSdkTest.java b/src/test/java/org/gaul/s3proxy/AwsSdkTest.java index ef3d2064..a5870bd5 100644 --- a/src/test/java/org/gaul/s3proxy/AwsSdkTest.java +++ b/src/test/java/org/gaul/s3proxy/AwsSdkTest.java @@ -118,6 +118,7 @@ public final class AwsSdkTest { private static final ByteSource BYTE_SOURCE = ByteSource.wrap(new byte[1]); private static final ClientConfiguration V2_SIGNER_CONFIG = new ClientConfiguration().withSignerOverride("S3SignerType"); + private static final long MINIMUM_MULTIPART_SIZE = 5 * 1024 * 1024; private URI s3Endpoint; private EndpointConfiguration s3EndpointConfig; @@ -471,7 +472,7 @@ public void testMultipartCopy() throws Exception { @Test public void testBigMultipartUpload() throws Exception { String key = "multipart-upload"; - long partSize = context.getBlobStore().getMinimumMultipartPartSize(); + long partSize = MINIMUM_MULTIPART_SIZE; long size = partSize + 1; ByteSource byteSource = TestUtils.randomByteSource().slice(0, size); @@ -1094,11 +1095,9 @@ public void testMultipartUpload() throws Exception { metadata)); ByteSource byteSource = TestUtils.randomByteSource().slice( - 0, context.getBlobStore().getMinimumMultipartPartSize() + 1); - ByteSource byteSource1 = byteSource.slice( - 0, context.getBlobStore().getMinimumMultipartPartSize()); - ByteSource byteSource2 = byteSource.slice( - context.getBlobStore().getMinimumMultipartPartSize(), 1); + 0, MINIMUM_MULTIPART_SIZE + 1); + ByteSource byteSource1 = byteSource.slice(0, MINIMUM_MULTIPART_SIZE); + ByteSource byteSource2 = byteSource.slice(MINIMUM_MULTIPART_SIZE, 1); UploadPartResult part1 = client.uploadPart(new UploadPartRequest() .withBucketName(containerName) .withKey(blobName) @@ -1195,7 +1194,7 @@ public void testMaximumMultipartUpload() throws Exception { public void testMultipartUploadAbort() throws Exception { String blobName = "multipart-upload-abort"; ByteSource byteSource = TestUtils.randomByteSource().slice( - 0, context.getBlobStore().getMinimumMultipartPartSize()); + 0, MINIMUM_MULTIPART_SIZE); InitiateMultipartUploadResult result = client.initiateMultipartUpload( new InitiateMultipartUploadRequest(containerName, blobName));