Repository navigation
feat(s3): validate the parts list on CompleteMultipartUpload (#400) - #407
Merged
Merged
Conversation
CompleteMultipartUpload assembled whatever parts it was handed, so
EntityTooSmall was unreachable and a supplied ETag was parsed and then
ignored. A consumer that computes chunk sizes from a file size can land
under S3's 5 MB non-final-part minimum and have every upload in that band
fail at Complete on real AWS — after every part has been uploaded and paid
for — while substrate accepted it. The only thing holding such a consumer's
size floor correct was a unit test asserting its own arithmetic against
itself, which tracks a bug rather than catching it.
Complete now validates before assembling anything:
- a non-final part under 5,242,880 bytes is 400 EntityTooSmall, carrying
the offending <PartNumber>, its <ETag>, <ProposedSize> and
<MinSizeAllowed>
- a part never uploaded, or one whose supplied ETag does not match the
stored one, is 400 InvalidPart
- a body naming no parts is 400 MalformedXML, not InvalidPart
- an upload ID presented against a different bucket or key is 404
NoSuchUpload, matching the guard UploadPart and AbortMultipartUpload
already applied
The final part is exempt from the minimum and may be zero bytes; a
single-part upload is nothing but its own final part, so it is exempt too.
ETags compare ignoring surrounding quotes, hex case and whitespace, since
clients differ on whether they echo back the quotes S3 sends and a false
InvalidPart would send a consumer hunting a data bug that does not exist.
Equally important is what a rejected Complete does not do: it writes no
object and leaves the upload open, so ListMultipartUploads still reports it
until AbortMultipartUpload ends it. That makes "no orphan upload was left
behind after a failed Complete" a property a test can assert by observing
the emulator rather than by asserting the consumer called Abort — orphaned
parts bill indefinitely.
Error codes, messages and statuses are taken verbatim from the S3
CompleteMultipartUpload API reference, which also replaces the abbreviated
NoSuchUpload and MalformedXML paraphrases used across the plugin.
TestS3_MultipartUpload_Complete previously completed two 13-byte parts with
made-up ETags; it now uses a 5 MB first part and the ETags UploadPart
returned, as a real client would.
Closes #400
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #400.
completeMultipartUploadassembled whatever parts it was handed.EntityTooSmallappeared nowhere in the repo, and theETagin each<Part>was parsed into a struct field that was never read.What this changes
200400 EntityTooSmall400 InvalidPartETag≠ stored partETag200400 InvalidPart400 InvalidPartOrderPartelements400 InvalidPart400 MalformedXMLuploadIdvalid but wrong bucket/key200, object written under the wrong key404 NoSuchUploadThe last part is exempt from the minimum and may be zero bytes; a single-part upload is nothing but its own final part, so it is exempt too.
The
EntityTooSmallbody carries the offending<PartNumber>, its<ETag>,<ProposedSize>and<MinSizeAllowed>— the capability #396 added to the error builder, which is why this was sequenced after it.Why the failure path matters more than the validation
A consumer computing multipart chunk sizes from a file size can land under 5 MB and have every upload in that band fail at Complete on real S3 — after every part has been uploaded and paid for. Substrate accepted those uploads, so the only thing holding such a consumer’s size floor correct was a unit test asserting its own arithmetic against itself.
Just as important is what a rejected Complete does not do. It writes no object and leaves the upload open, so
ListMultipartUploadsstill reports it untilAbortMultipartUploadends it. That makes no orphan upload was left behind after a failed Complete a property a test can assert by observing the emulator, rather than by asserting the consumer called Abort. Orphaned parts bill indefinitely, and the issue reporter is fixing exactly that leak.Details worth a second look
InvalidPartover quoting would send a consumer hunting a data bug that does not exist. Covered by a 4-case table test.MalformedXML, notInvalidPart. Per the API reference: "If you do not supply a validPartwith your request, the service sends back an HTTP 400 response." The oldInvalidPartwas a 400 too, so this changes the code, not the status.NoSuchUpload/MalformedXMLparaphrases used across the plugin. No test asserted the old strings.validateCompletePartsreturns([]S3Part, *AWSResponse, error): the third value is an internal failure, the second is an S3 error to serve. It writes nothing.Test changes
TestS3_MultipartUpload_Completecompleted two 13-byte parts with the made-up ETagse1/e2; it now uses a 5 MB first part and the ETagsUploadPartactually returned, as a real client would.TestS3_MultipartUpload_UserMetadatalikewise dropped itse1.New
emulator/s3_multipart_test.gocovers the three acceptance criteria from the issue (1 KiB first part of two →EntityTooSmalland no object at the key; 1 KiB final part succeeds; the upload is still listed after the failed Complete and gone after Abort) plus theInvalidPart,InvalidPartOrder,MalformedXML, ETag-quoting, wrong-bucket/key, and complete-then-NoSuchUploadcases.Verification
make test(race),golangci-lint run ./...(0 issues),go vet ./...,test/e2e,make docs-reference-check— all green.docs/services.mdgains a Multipart upload validation section with the condition table and theEntityTooSmallbody.