Skip to content

S3: UploadPartCopy is routed to CopyObject, so multipart server-side copy silently produces a whole-object copy #532

Closed

Description

@scttfrdmn

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

  1. Routing — check uploadId + partNumber before x-amz-copy-source, and when both are
    present dispatch to a new UploadPartCopy handler rather than UploadPart.
  2. Handler — resolve the source as CopyObject does (including the x-amz-copy-source-if-*
    conditionals already implemented in s3_copy_metadata.go/s3_conditional.go), slice by
    x-amz-copy-source-range when present (whole object when absent), store the slice as part
    partNumber of uploadId exactly as uploadPart does, and respond with
    <CopyPartResult><ETag>…</ETag><LastModified>…</LastModified></CopyPartResult> — note the ETag
    lives in the body, not the ETag header, which is the one shape difference from UploadPart
    and the one a naive implementation gets wrong.
  3. Error fidelity worth having, in rough priority order:
    • 404 NoSuchUpload for an unknown uploadId (matching uploadPart);
    • 404 NoSuchKey for a missing copy source;
    • 400 InvalidRange for a x-amz-copy-source-range outside the source object;
    • 400 InvalidRequest when 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

  1. added
    type: bug
    area: s3
    priority: medium
    priority: high
    on Aug 3, 2026
  2. scttfrdmn commented on Aug 3, 2026

    @scttfrdmn
    OwnerAuthor

    Reproduced against v0.89.0, and the consequence is worse than the report states — the
    part copy does not merely fail to register a part, it overwrites the destination object:

    create-multipart-upload --bucket mpu-dst --key joined      → UploadId mpu-…
    upload-part-copy --bucket mpu-dst --key joined --part-number 1 \
                     --upload-id mpu-… --copy-source mpu-src/big
      → 200 {"CopyPartResult": {"ETag": "\"3349dc…\"", "LastModified": …}}
    
    head-object --bucket mpu-dst --key joined    → ContentLength 6291456   ← the whole object
    complete-multipart-upload …                  → InvalidPart
    

    So a caller doing a server-side multipart copy gets a 200 on every part, a real object
    sitting at the destination key mid-upload (which real S3 never exposes — the key stays
    absent until CompleteMultipartUpload), and then a hard InvalidPart. The
    CopyPartResult envelope is even shaped correctly, which is what makes it convincing.

    Confirmed at emulator/s3_plugin.go:327-340: in the object-level PUT arm the
    X-Amz-Copy-Source header check (:334) precedes the partNumber+uploadId check
    (:337), so a request carrying both is claimed by CopyObject. Ordering, exactly as the
    report 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:

    • ListParts is unrouted entirely — the object-level GET arm never checks uploadId,
      so GET /<bucket>/<key>?uploadId=… falls through to GetObject and returns
      404 NoSuchKey even for an upload with stored parts. There is no listParts handler in
      the 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
      InvalidPart above, so it is unavailable exactly when it is most needed.
    • The GET arm's asymmetry is the tell: PUT checks partNumber+uploadId, DELETE
      checks uploadId → AbortMultipartUpload, POST checks uploadId →
      CompleteMultipartUpload. GET is 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.

  3. added this to the v0.90.0 milestone on Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: s3fidelitypriority: highpriority: mediumtype: bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions