Skip to content

S3: CreateMultipartUpload drops Content-Encoding, so multipart objects lose it #406

Closed

Description

@scttfrdmn

Summary

CreateMultipartUpload accepts Content-Encoding but the emulator drops it: the header is not
stored on the S3MultipartUpload record, so CompleteMultipartUpload cannot put it on the
assembled S3Object, and both HeadObject and GetObject then report an empty
Content-Encoding for an object that was uploaded with one.

PutObject handles this correctly (emulator/s3_plugin.go:485), so the two upload paths disagree
about the same object property. UserMetadata is carried through
(createMultipartUpload → upload.UserMetadata → obj.UserMetadata), which makes the omission
look like an oversight rather than a deliberate subset.

Reproduction

Raw AWS SDK, no application code involved:

create, _ := c.CreateMultipartUpload(ctx, &s3.CreateMultipartUploadInput{
    Bucket:          aws.String(bucket),
    Key:             aws.String("probe/mpu"),
    ContentEncoding: aws.String("zstd"),
    Metadata:        map[string]string{"objectfs-original-size": "999"},
})
// ... upload two parts, complete ...

head, _ := c.HeadObject(ctx, &s3.HeadObjectInput{Bucket: ..., Key: aws.String("probe/mpu")})

Observed:

HEAD ContentEncoding="" Metadata=map[objectfs-original-size:999] size=5242884
GET  ContentEncoding="" Metadata=map[objectfs-original-size:999]

Expected ContentEncoding="zstd" on both, matching PutObject and matching real S3.

Why it matters

This is the failure mode where an emulator gap is worse than a missing feature: it makes a
correct application look broken, and — in the other direction — would let a genuinely broken
application pass.

ObjectFS compresses objects transparently and records the codec in Content-Encoding. Its read
path dispatches decompression on that header, and fails closed when an object claims an
uncompressed size it cannot produce. Against this emulator, a compressed object large enough to
cross the multipart threshold round-trips as a hard integrity error:

DATA_CORRUPTION: object is still encoded after decompression; refusing to return partial content

The application is correct here — it sets the header on CreateMultipartUpload
(internal/storage/s3/multipart_upload.go:66-68) and real S3 preserves it. Only the emulator
loses it. We hit this within an hour of adding multipart coverage, and had to rule out our own
write path first.

The symmetric risk is the one worth flagging: an application that forgot to set
Content-Encoding on the multipart path — which is a real and easy bug, since it is a separate
input struct from PutObjectInput — is indistinguishable from a correct one here. Any test
asserting "the encoding survives a multipart upload" passes vacuously.

Suggested fix

Three lines, mirroring the UserMetadata handling already present:

  1. Add ContentEncoding string to S3MultipartUpload.
  2. createMultipartUpload (emulator/s3_plugin.go:1139): set it from
    req.Headers["Content-Encoding"], alongside ContentType.
  3. completeMultipartUpload (emulator/s3_plugin.go:1322): copy upload.ContentEncoding onto
    the assembled S3Object, alongside ContentType.

The response side already works — getObject/headObject emit the header whenever
obj.ContentEncoding != "" (:1764-1765), so nothing downstream needs to change.

Worth checking the same question for the other headers CreateMultipartUpload accepts and
S3Object can hold: Cache-Control, Content-Disposition, Content-Language, and — once #398
lands — x-amz-storage-class, which has the same structure (stored on the upload, applied at
complete) and would otherwise silently default for every multipart object.

Environment

Activity

  1. added
    type: bug
    area: s3
    priority: medium
    on Jul 31, 2026
  2. added this to the v0.81.0 milestone on Aug 1, 2026
  3. scttfrdmn commented on Aug 1, 2026

    @scttfrdmn
    OwnerAuthor

    Fixed and closed by #424 (v0.81.0, unreleased): CreateMultipartUpload now records
    Content-Encoding on the upload record and CompleteMultipartUpload applies it to
    the assembled object, so GetObject/HeadObject report the codec for a multipart
    object exactly as they already did for PutObject.

    Complete accepts no object-metadata headers at all — per the AWS reference it
    takes only checksums, x-amz-mp-object-size, request-payer, SSE-C and conditional
    headers — so carrying the value from Create is the only place it can come from.

    Two notes on the follow-on suggestion in your last paragraph.

    The storage-class half is already done. #398 landed before this: createMultipartUpload
    calls resolveStorageClass and Complete copies the result onto the object. So the
    Content-Encoding fix was the only remaining piece and #406 closes on it.

    Cache-Control / Content-Disposition / Content-Language are a separate,
    larger change
    , so they're not folded in here. S3Object has no fields for these
    at all, so it isn't the same three-line parity fix — it needs new fields, emission in
    objectResponseHeaders, capture in putObject, COPY-vs-REPLACE handling in
    resolveCopyMetadata, and the multipart carry: 4 headers × 5 sites, with a real
    design question about x-amz-metadata-directive semantics for each. I've filed that
    separately so it can be reviewed on its own terms rather than riding along with a
    parity fix.

    Two things worth knowing if you're relying on Content-Encoding today:

    • The value is stored verbatim on both paths. putObject therefore persists
      Content-Encoding: aws-chunked for a chunked upload whose body substrate already
      dechunked — a transfer encoding recorded as a content encoding. That's a real
      defect, filed separately; the fix belongs in a shared helper applied to both write
      paths so they can't drift apart again, which is exactly the failure mode you hit
      here.
    • Header lookup in createMultipartUpload is now case-insensitive
      (headerValueFold), matching the rest of that function. Over the wire Go
      canonicalizes header casing so this changes nothing for an SDK caller; it matters
      for in-process callers that build AWSRequest literals directly.
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: s3priority: mediumtype: bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions