Repository navigation
Description
Problem
Server-side replication uploads SSE-C multipart parts as raw ciphertext, and the receiving write
path stores the ciphertext length in each part's ActualSize, the field defined as the "original
size of the part without compression or encryption bytes". Two things follow. On the replica,
partNumberToRangeSpec turns those lengths into a plaintext byte range, so a GET ?partNumber=N
can return incorrect part content, and GET and HEAD both report incorrect part boundaries and
lengths. Second, a later decommission or rebalance of that replica re-uploads the parts with the
same stale value and completes without the replication flag, so CompleteMultipartUpload recomputes
the object-level actual-size from the sum of part sizes: after that, an ordinary whole-object GET
advertises a Content-Length larger than the body it writes, causing truncated-response errors in
clients that enforce the advertised length. Inherited from upstream, which carries byte-identical
code in partNumberToRangeSpec and in the replication send.
Reproduction and evidence
Two in-process tests, both run on ErasureSD and Erasure with identical results. Source object:
SSE-C multipart, parts of 5 MiB, 5 MiB and 1 MiB, plaintext total 11534336.
TestProbeSSECReplicaPartNumberBytes replays the source ciphertext through the trusted replication
write path over the same key, then repeats the reads it recorded against the source.
| Part | Source ActualSize |
Replica ActualSize |
Source Content-Range |
Replica Content-Range |
|---|---|---|---|---|
| 1 | 5242880 | 5245440 | bytes 0-5242879/11534336 |
bytes 0-5245439/11534336 |
| 2 | 5242880 | 5245440 | bytes 5242880-10485759/11534336 |
bytes 5245440-10490879/11534336 |
| 3 | 1048576 | 1049088 | bytes 10485760-11534335/11534336 |
bytes 10490880-11534335/11534336 |
Every part body differs from the source. The ranges stay contiguous, so a client that fetches all
parts in order and concatenates still reconstructs the object; a client that fetches one part, or
places parts at the offsets a correct HEAD ?partNumber=N would imply, gets wrong content. With a
short enough final part the shifted start can exceed the plaintext size and the read fails with
InvalidRange instead. Before data movement the whole-object GET, a Range read across the
part 1 / part 2 boundary, x-amz-mp-parts-count and the object-level size are all still correct.
TestProbeSSECStalePartActualSizeDataMovement then replays such a replica the way
decommissionObject does, handing PutObjectPart the stale ActualSize and completing with
DataMovement and no ReplicationRequest. Measured after that move: part ActualSize unchanged at
5245440 / 5245440 / 1049088, object actual-size rewritten from 11534336 to 11539968, and a plain
whole-object GET returning Content-Length: 11539968 with a body of 11534336 bytes.
Cause and minimal repair
On main f0bd164b9, cmd/bucket-replication.go:1708 sends partInfo.Size, the ciphertext length,
as the part Content-Length for an SSE-C source. cmd/object-multipart-handlers.go:849 takes it as
actualSize and :966 skips re-encryption because a trusted SSE-C replica already carries
ciphertext, so cmd/erasure-multipart.go:742 persists it. The compensating derivation at
cmd/erasure-multipart.go:713-729 runs only when actualSize < 0, which this path never produces,
and cmd/erasure-server-pool-decom.go:632 and cmd/erasure-server-pool-rebalance.go:880 feed the
stored value straight back in. cmd/object-api-utils.go:687 then accumulates those lengths into a
plaintext range, while every other encrypted read path derives the length from part.Size
(cmd/encryption-v1.go:754 and :891), which is why, before data movement, only part-number reads
are wrong.
Repair both ends. In erasureObjects.PutObjectPart, the single point where a part is persisted,
promote the existing sio.DecryptedSize derivation out of the actualSize < 0 guard so an
encrypted, uncompressed part always records the length derived from the bytes just written, and
return errObjectTampered when that length cannot be a valid stream, which happens before the part
is committed at cmd/erasure-multipart.go:772. This is a no-op for a healthy local upload and fixes
the replication write and every data-movement re-upload at once. Then in partNumberToRangeSpec,
derive each part's plaintext length the same way for an encrypted, uncompressed object, so replicas
already on disk read correctly with no resync; return an error rather than a nil range, propagated
through its two callers, which both already return errors. Out of scope: the compressed branch,
which must keep ActualSize because removing encryption overhead from compressed ciphertext yields
the compressed length, not the uploaded length; compressed SSE-C replication, which is #109;
GetObjectAttributes, which is #114; the HTTP 206 that ErrObjectTampered still maps to at
cmd/api-errors.go:1526-1530, which is #110; and any rewrite of stored metadata. Size: S, about 20
product lines across three files.
Recovery boundary. The read-side derivation repairs a replica whose part sizes are stale only while
its object-level actual-size is still correct. An object that an unfixed server already moved
carries a poisoned actual-size on disk, which cmd/object-api-utils.go:574 still trusts and
cmd/api-headers.go:209 still uses for response lengths, so those objects need a rewrite or resync.
The fix stops the amplification; it does not undo it.
Acceptance
- A part written through trusted SSE-C replication records the plaintext length in
ActualSize. - After replicating a three-part SSE-C multipart object,
GETandHEAD ?partNumber=Non the
replica return the source's bytes,Content-LengthandContent-Rangefor every N. - A replica whose parts already carry the ciphertext length serves correct
?partNumber=Nreads
with no metadata rewrite. - Replaying such a replica through the data-movement path leaves part
ActualSizeand the
object-levelactual-sizeat the plaintext values, and a whole-objectGETwrites exactly
the bytes itsContent-Lengthadvertises. - A part whose stored length cannot be a valid encrypted stream fails the read with
XMinioObjectTamperedinstead of silently reading as a whole-object range, and a write with
such a length is rejected before the part is committed. - Whole-object and boundary-crossing
Rangereads stay byte-identical; compressed multipart
part sizes are unchanged. -
TestAPIGetObjectWithPartNumberHandler(including itsenc-mp-*cases),
TestAPISSECMultipartReplicationTrustandTestAPIListObjectPartsHandlerstay green. Note
thatTestAPIGetObjectWithPartNumberHandlerderives its expected slice from the same helper it
exercises, so it cannot detect a wrong range on its own; the new regressions compute their
expected boundaries independently.
Related
Found while preparing the fix plan for #114, whose read-side repair to GetObjectAttributes
deliberately excluded this write-path defect and uses the same "derive from part.Size" rule; the
two touch different functions and can land in either order. #109 owns compressed SSE-C replication
and #110 owns the ErrObjectTampered status mapping, both kept out of scope here.
ObjectPart.Size semantics: https://docs.aws.amazon.com/AmazonS3/latest/API/API_ObjectPart.html.
Versions and verification
Found during the 2026-09-05 fix-plan triage of #114 on main f0bd164b9 (release
RELEASE.2026-09-03T13-18-01Z / 9b11dc946 for SILO). The reviewed code is unchanged between the
release and main. Verified by two in-process tests that fail on main and pass with the prototype on
both backends, plus a run with only the read-side half to confirm it repairs a replica already on
disk. Agreed with the Codex reviewer (gpt-6-astra) in two rounds; the storage-layer placement, the
error-returning range helper and the recovery-boundary caveat are its amendments, and the
data-movement consequence it derived from the code is reproduced above. Codex reviewed main and the
diff at source level and did not rerun the tests; all measurements here are mine.
Activity
Vonng commentedon Sep 5, 2026
Fix record (2026-09-05)
Status: implemented, reviewed, awaiting merge. Pull request: #124 (branch
fix/issue-119-ssec-part-actual-size, commit0c8d74205, based on mainf0bd164b9).Root cause, as fixed.
cmd/bucket-replication.go:1708ships an SSE-C part with the ciphertext length as Content-Length;cmd/object-multipart-handlers.go:849takes it asactualSizeand:966skips re-encryption for a trusted SSE-C replica;erasureObjects.PutObjectPart(cmd/erasure-multipart.go:713-729) only derived the plaintext length for a negative size, so the ciphertext length was persisted asActualSize.partNumberToRangeSpec(cmd/object-api-utils.go:687) built plaintext ranges from it, and decommission/rebalance fed the stale value back and recomputed the object-levelactual-size.Change (3 files, ~30 product lines).
PutObjectPartalways derives an encrypted, uncompressed part'sActualSizefrom the bytes written (sio.DecryptedSize), returningerrObjectTamperedbefore the part is committed when the length cannot be a valid stream; compressed parts keepActualSize; the default branch keeps the negative-size fallback.partNumberToRangeSpecderives each part length frompart.Sizefor encrypted, uncompressed objects (so replicas already on disk read correctly without a resync) and returns an error instead of a nil range; both callers (setObjectHeaders,NewGetObjectReader) propagate it; one existing test call site updated for the new signature.Tests.
TestAPISSECReplicaPartNumberReads(three-part SSE-C replica: partActualSize,GET/HEAD ?partNumber=Nstatus, Content-Length, Content-Range and bytes asserted against independent prefix sums and the source; red on main),TestSSECReplicaPartActualSizeDataMovement(data-movement replay; part and object sizes stay plaintext, whole-object GET advertises exactly its body; red on main),TestPartNumberToRangeSpecEncryptedParts(unit guard with a stale-metadata fixture that bypasses the writer, plus correct, plaintext and compressed cases, a malformed 31-byte part reported aserrObjectTamperedby both callers, and a zero-length trailing part accepted; fails when the read-side derivation is disabled),TestAPISSECReplicaMalformedPartIsRejected(31-byte trusted replica part rejected withXMinioObjectTampered, nothing committed, the real ciphertext still uploads). Eight neighbouring part-number, ListParts, attributes and replication-trust tests stay green; gofmt, go vet and golangci-lint clean.Adversarial Codex review (gpt-6-astra). Round 1: FAIL, three required findings on test coverage (framing assertions only logged; no committed guard for the read-side repair independent of the fixed writer; malformed-length paths untested). All three implemented. Round 2: PASS; two optional suggestions (make the compressed fixture detect removal of the compression exclusion, a comment wording) applied before opening the PR.
Recovery boundary (unchanged from the plan). Objects that an unfixed server already moved carry a poisoned object-level
actual-sizeand need a rewrite or resync; the fix stops the amplification. The HTTP status ofXMinioObjectTamperedfollows #110 (PR #121).Merge pull request #135 from pgsty/fix/attributes-encrypted-parts-tes…
Vonng commentedon Sep 6, 2026
Merged — record complete (2026-09-06)
Merged via #124 (merge commit
425bd7fff) intomain. Supersedes the "awaiting merge" status above: main is green — siloe7d0e62f1, Go CI (Test cmd/, Test internal/, Race + S3 Select, Format/Build/Vet, Lint/Generated Files, Cross Compile) and VulnCheck all pass.Post-merge note. This fix made
PutObjectPartalways derive an encrypted part's plaintext length viasio.DecryptedSizeand reject a part that cannot be a valid stream. That interacted with the #128 GetObjectAttributes test, which had built fixtures from plaintext parts under encrypted metadata; reconciled forward, test-only, via #135 (merged, main green). No product or contract change to this fix.Issue closed; fix record complete.
fix: record plaintext part sizes for replicated SSE-C multipart parts
test: reconcile encrypted-parts attributes test with pgsty#119 write …
test: reconcile #134 fixtures with #119 and refresh the rebrand baseline
test: reconcile #134 fixtures with #119 and refresh the rebrand baseline