Repository navigation
Description
Summary
UploadPartCopy (PUT /<bucket>/<key>?partNumber=N&uploadId=ID with x-amz-copy-source) is
misrouted to CopyObject, so a server-side multipart copy cannot be emulated at all. It does not
fail — which is the problem. Each UploadPartCopy silently writes the whole source object to the
destination key as a complete object, returns a CopyPartResult the SDK accepts, records no part,
and the subsequent CompleteMultipartUpload then fails with InvalidPart.
Cause
emulator/s3_plugin.go:295-310 — in the object-level PUT switch, the copy-source check comes
before the multipart check:
case "PUT":
...
if req.Headers["X-Amz-Copy-Source"] != "" {
return bucket, key, "CopyObject" // matches first
}
if req.Params["partNumber"] != "" && req.Params["uploadId"] != "" {
return bucket, key, "UploadPart" // never reached for a part copy
}An UploadPartCopy request carries both x-amz-copy-source and the two query parameters, so it
always takes the first arm. Real S3 distinguishes them the other way round: the presence of
uploadId + partNumber makes it a part operation, and x-amz-copy-source then selects the copy
variant of that part operation.
Reproduction
Against emulator.StartTestServer, with a 100-byte object at big.bin:
created, _ := c.CreateMultipartUpload(ctx, &s3.CreateMultipartUploadInput{
Bucket: aws.String(bucket), Key: aws.String("dst.bin"),
})
var parts []types.CompletedPart
for i, rng := range []string{"bytes=0-49", "bytes=50-99"} {
out, err := c.UploadPartCopy(ctx, &s3.UploadPartCopyInput{
Bucket: aws.String(bucket), Key: aws.String("dst.bin"),
UploadId: created.UploadId, PartNumber: aws.Int32(int32(i + 1)),
CopySource: aws.String(bucket + "%2F" + "big.bin"),
CopySourceRange: aws.String(rng),
})
// err == nil for both
parts = append(parts, types.CompletedPart{ETag: out.CopyPartResult.ETag, PartNumber: aws.Int32(int32(i + 1))})
}
_, err := c.CompleteMultipartUpload(ctx, &s3.CompleteMultipartUploadInput{ ... })Observed:
part 1 etag="\"aed563ecafb4bcc5654c597a421547b2\"" lastmod=...
part 2 etag="\"aed563ecafb4bcc5654c597a421547b2\"" lastmod=...
complete: api error InvalidPart: One or more of the specified parts could not be found...
Both parts report the same ETag — the MD5 of the whole 100-byte object — because each request was
handled as a full CopyObject, ignoring CopySourceRange. That identical-ETag pair is the tell: a
consumer whose test asserted only "no error from UploadPartCopy" would see a green test while
nothing resembling a part copy had happened, and a consumer that checked the final object would find
dst.bin present with the wrong contents rather than absent.
What ObjectFS needs it for
Server-side copy above S3's 5 GiB single-part CopyObject limit — the path rename(2) takes for a
large file. Without it that branch is untestable without a real >5 GiB object in real S3, which is
~$0.12 of storage per run plus the hours to write it, so in practice it stays untested. It is also
the branch where getting it wrong is most expensive: parts of an incomplete multipart upload are
billed and invisible to ListObjects.
Suggested behavior
- Routing — check
uploadId+partNumberbeforex-amz-copy-source, and when both are
present dispatch to a newUploadPartCopyhandler rather thanUploadPart. - Handler — resolve the source as
CopyObjectdoes (including thex-amz-copy-source-if-*
conditionals already implemented ins3_copy_metadata.go/s3_conditional.go), slice by
x-amz-copy-source-rangewhen present (whole object when absent), store the slice as part
partNumberofuploadIdexactly asuploadPartdoes, and respond with
<CopyPartResult><ETag>…</ETag><LastModified>…</LastModified></CopyPartResult>— note the ETag
lives in the body, not theETagheader, which is the one shape difference fromUploadPart
and the one a naive implementation gets wrong. - Error fidelity worth having, in rough priority order:
404 NoSuchUploadfor an unknownuploadId(matchinguploadPart);404 NoSuchKeyfor a missing copy source;400 InvalidRangefor ax-amz-copy-source-rangeoutside the source object;400 InvalidRequestwhen the source range exceeds 5 GiB (S3's per-part copy limit) — this is
the check a consumer sizing its parts by bandwidth rather than by count would trip, so having
it reachable is worth more than it looks.
The existing uploadPart handler already does the part-storage half; this is largely the source
resolution from copyObject feeding the part write from uploadPart.
Docs
docs/services.md lists multipart support; worth noting whether UploadPartCopy is in or out once
this lands, since it is currently neither documented as missing nor working.
Version
github.com/scttfrdmn/substrate v0.85.0, emulator.StartTestServer, aws-sdk-go-v2.
Activity
scttfrdmn commentedon Aug 3, 2026
Reproduced against
v0.89.0, and the consequence is worse than the report states — thepart copy does not merely fail to register a part, it overwrites the destination object:
So a caller doing a server-side multipart copy gets a
200on every part, a real objectsitting at the destination key mid-upload (which real S3 never exposes — the key stays
absent until
CompleteMultipartUpload), and then a hardInvalidPart. TheCopyPartResultenvelope is even shaped correctly, which is what makes it convincing.Confirmed at
emulator/s3_plugin.go:327-340: in the object-levelPUTarm theX-Amz-Copy-Sourceheader check (:334) precedes thepartNumber+uploadIdcheck(
:337), so a request carrying both is claimed byCopyObject. Ordering, exactly as thereport says.
While reproducing this I found two more defects in the same function, both from the same
pattern — a multipart check missing or ordered behind a more general one:
ListPartsis unrouted entirely — the object-levelGETarm never checksuploadId,so
GET /<bucket>/<key>?uploadId=…falls through toGetObjectand returns404 NoSuchKeyeven for an upload with stored parts. There is nolistPartshandler inthe plugin at all. Filed as S3: ListParts is unrouted, so GET ?uploadId falls through to GetObject and returns 404 NoSuchKey #551; it is the natural way a caller would diagnose the
InvalidPartabove, so it is unavailable exactly when it is most needed.GETarm's asymmetry is the tell:PUTcheckspartNumber+uploadId,DELETEchecks
uploadId→AbortMultipartUpload,POSTchecksuploadId→CompleteMultipartUpload.GETis the only multipart verb without its check.Fixing #532 and #551 together is the right unit of work — one router function, one review of
the whole precedence order rather than two separate reorderings. Milestoned v0.90.0,
priority: high.feat(s3): route UploadPartCopy and ListParts (#532, #551) (#552)