mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(s3): reject undersized multipart upload parts (#5718)
* fix(s3): reject undersized multipart upload parts Signed-off-by: boulea7 <zln1905391059@163.com> * fix(s3): reuse multipart size error helper Signed-off-by: boulea7 <zln1905391059@163.com> --------- Signed-off-by: boulea7 <zln1905391059@163.com>
This commit is contained in:
1 parent
b4c012fba4
commit
ea45f81a81
12 files changed
+311
-50
No files matched your search
@@ -3554,12 +3554,13 @@ public class S3Controller {
|
||||
}
|
||||
// S3 InvalidArgument responses carry ArgumentName and ArgumentValue so the SDK can
|
||||
// surface which input was rejected, and EntityTooSmall and EntityTooLarge the proposed and
|
||||
// allowed sizes. They travel through AwsException.extendedData.
|
||||
// allowed sizes. Multipart size errors also identify the rejected part.
|
||||
// They travel through AwsException.extendedData.
|
||||
if (e.getExtendedData() != null) {
|
||||
for (String sizeField : List.of("ProposedSize", "MinSizeAllowed", "MaxSizeAllowed")) {
|
||||
Object size = e.getExtendedData().get(sizeField);
|
||||
if (size != null) {
|
||||
xmlBuilder.elem(sizeField, size.toString());
|
||||
for (String field : List.of("ProposedSize", "MinSizeAllowed", "MaxSizeAllowed", "PartNumber", "ETag")) {
|
||||
Object value = e.getExtendedData().get(field);
|
||||
if (value != null) {
|
||||
xmlBuilder.elem(field, value.toString());
|
||||
}
|
||||
}
|
||||
Object resource = e.getExtendedData().get("Resource");
|
||||
|
||||
@@ -2310,6 +2310,7 @@ public class S3Service implements Resettable, ResourceProvider {
|
||||
|
||||
// The most one part of a multipart upload can hold, per S3's multipart upload limits.
|
||||
static final long MAX_PART_SIZE = 5L * 1024 * 1024 * 1024;
|
||||
static final long MIN_PART_SIZE = 5L * 1024 * 1024;
|
||||
|
||||
// The User Guide's "up to 5 GB" in one PutObject, read as 5 GiB like CopyObject's 5 GB limit;
|
||||
// a larger object is uploaded in parts.
|
||||
@@ -2345,6 +2346,13 @@ public class S3Service implements Resettable, ResourceProvider {
|
||||
Map.of("ProposedSize", proposedSize, "MinSizeAllowed", minSizeAllowed));
|
||||
}
|
||||
|
||||
/** The same error for an undersized multipart part, identifying its number and ETag. */
|
||||
static AwsException entityTooSmall(long proposedSize, long minSizeAllowed, int partNumber, String eTag) {
|
||||
return new AwsException("EntityTooSmall", ENTITY_TOO_SMALL_MESSAGE, 400,
|
||||
Map.of("ProposedSize", proposedSize, "MinSizeAllowed", minSizeAllowed,
|
||||
"PartNumber", partNumber, "ETag", eTag));
|
||||
}
|
||||
|
||||
static void requireCopyableSize(S3Object source) {
|
||||
if (source.getSize() > MAX_COPY_OBJECT_SOURCE_SIZE) {
|
||||
throw new AwsException("InvalidRequest",
|
||||
@@ -4267,6 +4275,14 @@ public class S3Service implements Resettable, ResourceProvider {
|
||||
validateExpectedChecksum(checksum, expectedChecksum);
|
||||
}
|
||||
|
||||
for (int index = 0; index < parts.size() - 1; index++) {
|
||||
Part part = parts.get(index);
|
||||
if (part.getSize() < MIN_PART_SIZE) {
|
||||
throw entityTooSmall(part.getSize(), MIN_PART_SIZE, part.getPartNumber(),
|
||||
stripSurroundingQuotes(part.getETag()));
|
||||
}
|
||||
}
|
||||
|
||||
ObjectBody body = inMemory
|
||||
? new BytesBody(concatenateParts(uploadId, parts))
|
||||
: assembleParts(uploadId, parts);
|
||||
|
||||
Reference in new issue
Block a user