Skip to content

fix: record plaintext part sizes for replicated SSE-C multipart parts - #124

Merged
Vonng merged 1 commit into
mainfrom
fix/issue-119-ssec-part-actual-size
Sep 6, 2026
Merged

Vonng merged 1 commit into
mainfrom
fix/issue-119-ssec-part-actual-size

Conversation

@Vonng

@Vonng Vonng commented Sep 5, 2026

Copy link
Copy Markdown
Member

Contribution Licensing (no CLA, inbound=outbound, DCO required)

This project does not use a CLA; contributions are accepted inbound=outbound.
By submitting this pull request I represent that I have the right to contribute
the changes, which are licensed under this repository's
GNU Affero General Public License v3.0 or later
and remain my copyright. Every commit carries a DCO Signed-off-by trailer.

Description

Trusted SSE-C replication uploads multipart parts as raw ciphertext with the ciphertext length as Content-Length, and erasureObjects.PutObjectPart only derived the plaintext length when the caller passed a negative size, so every replicated SSE-C part persisted the ciphertext length as ActualSize. On the replica, partNumberToRangeSpec turned those lengths into a plaintext range, so GET/HEAD ?partNumber=N returned the wrong bytes with a shifted Content-Range, and a later decommission or rebalance re-uploaded the parts with the stale value and recomputed the object-level actual-size from their sum, after which a whole-object GET advertised a Content-Length larger than the body it wrote.

The fix derives the plaintext length of an encrypted, uncompressed part from the bytes actually written in PutObjectPart (the single point where a part is persisted, covering replication, decommission and rebalance), rejects a length that cannot be a valid encrypted stream before the part is committed, and derives part lengths from part.Size in partNumberToRangeSpec for encrypted, uncompressed objects so replicas already on disk read correctly without a resync. Compressed parts keep ActualSize.

Fixes #119. The issue body is the plan agreed with the Codex reviewer (2 rounds). Adversarial Codex review of this implementation: round 1 FAIL (three required test-coverage findings: protocol assertions only logged, no independent guard for the read-side repair, malformed-length paths untested), round 2 PASS with two optional suggestions (a compressed fixture that detects removal of the compression exclusion, a comment wording), both applied.

Motivation and Context

ObjectPart.Size and the part-number read contract are defined in terms of the uploaded plaintext; a replica must serve the same bytes for ?partNumber=N as its source. Inherited from upstream, which carries byte-identical code in partNumberToRangeSpec and in the replication send.

How to test this PR?

GOWORK=off go test -tags kqueue,dev ./cmd -count=1 -v -run '^(TestAPISSECReplicaPartNumberReads|TestSSECReplicaPartActualSizeDataMovement|TestPartNumberToRangeSpecEncryptedParts|TestAPISSECReplicaMalformedPartIsRejected)$'
  • TestAPISSECReplicaPartNumberReads: a three-part SSE-C object (5 MiB, 5 MiB, 1 MiB) is replayed through the trusted replication write path; the replica's part ActualSize values, and GET/HEAD ?partNumber=N status, Content-Length, Content-Range and bytes are asserted against independent prefix sums and the source for every part. Fails on main (parts record 5245440/5245440/1049088, ranges shifted by 2560/2560/5120 bytes), passes with the fix.
  • TestSSECReplicaPartActualSizeDataMovement: replays such a replica through the data-movement path (DataMovement: true, no ReplicationRequest) and asserts part and object-level sizes stay at plaintext values and the whole-object GET advertises exactly the bytes it writes. Fails on main (object actual-size 11539968 for an 11534336-byte body).
  • TestPartNumberToRangeSpecEncryptedParts: unit guard for the read-side repair with a stale-metadata fixture that bypasses the writer (parts recording the ciphertext length), the correct-metadata, plaintext and compressed cases, a malformed 31-byte part reported as errObjectTampered by partNumberToRangeSpec, NewGetObjectReader and setObjectHeaders, and a zero-length trailing part accepted. With the read-side derivation disabled the stale case fails.
  • TestAPISSECReplicaMalformedPartIsRejected: a trusted SSE-C replica part of 31 bytes is rejected with XMinioObjectTampered and nothing is committed; the real ciphertext still uploads on the same upload.

Must-stay-green, all passing: TestAPIGetObjectWithPartNumberHandler (including enc-mp-*), TestAPISSECMultipartReplicationTrust, TestAPIListObjectPartsHandler, TestAPIGetObjectAttributesAuthenticatesSSECKey, TestAPIGetObjectAttributesSSECReplicationAuthz, TestObjectAPIPutObjectPart, TestAPICompleteMultipartFullObjectVariants, TestAPIReplicationTrustProtectsSSECReads. go vet clean, gofmt -l cmd empty, golangci-lint 0 issues on ./cmd/....

Compatibility impact

No wire or API change. Healthy local uploads are unaffected: for an encrypted part the derived length equals the caller's value. Replicas already on disk with stale part sizes read correctly from the next request. Objects that an unfixed server already moved (decommission/rebalance) carry a poisoned object-level actual-size and still need a rewrite or resync; the fix stops the amplification but does not undo it. A malformed replicated part now fails the write with XMinioObjectTampered instead of being stored; its HTTP status follows #110.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Optimization (provides speedup with no functional changes)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • All commits are signed off (git commit -s) per the DCO
  • Fixes a regression (inherited from upstream, not a SILO regression)
  • Unit tests added/updated
  • make verifiers equivalent: gofmt clean, go vet clean, golangci-lint 0 issues on ./cmd/...
  • Relevant package tests pass
  • Compatibility and rollback impact documented
  • Internal documentation updated (code comments)
  • Public documentation update opened in pgsty/silo.pgsty.com (release fix note)

🤖 Generated with Claude Code

https://claude.ai/code/session_01L7qJqWwy8oFA6aCXWRzXQe

Trusted SSE-C replication uploads parts as raw ciphertext with the
ciphertext length as Content-Length, and erasureObjects.PutObjectPart only
derived the plaintext length when the caller passed a negative size, so
each replicated part persisted the ciphertext length as ActualSize (the
field defined as the uploaded size without encryption bytes). On the
replica, partNumberToRangeSpec turned those lengths into a plaintext range,
so GET/HEAD ?partNumber=N returned the wrong bytes and shifted
Content-Range (2560, 2560 and 5120 bytes for 5 MiB, 5 MiB and 1 MiB
parts), and a later decommission or rebalance re-uploaded the parts with
the stale value and recomputed the object-level actual-size from their sum,
after which a whole-object GET advertised a Content-Length larger than the
body it wrote.

Derive the plaintext length of an encrypted, uncompressed part from the
bytes actually written (sio.DecryptedSize) in PutObjectPart, the single
place a part is persisted, rejecting a length that cannot be a valid
stream before the part is committed; and derive part lengths from
part.Size in partNumberToRangeSpec for encrypted, uncompressed objects,
returning an error instead of a nil range, so replicas already on disk
read correctly without a resync. Compressed parts keep ActualSize.

Tests: TestAPISSECReplicaPartNumberReads (three-part SSE-C replica,
?partNumber=N bytes, Content-Length and Content-Range equal the source)
and TestSSECReplicaPartActualSizeDataMovement (replay through the data
movement path leaves part and object sizes at plaintext values) fail on
main and pass with the fix on ErasureSD and Erasure;
TestAPIGetObjectWithPartNumberHandler, TestAPISSECMultipartReplicationTrust
and TestAPIListObjectPartsHandler stay green. Compatibility: no wire or
API change; objects an unfixed server already moved carry a poisoned
object-level actual-size and need a rewrite or resync.

Fixes #119

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01L7qJqWwy8oFA6aCXWRzXQe
Signed-off-by: Feng Ruohang <[email protected]>
@Vonng
Vonng merged commit 425bd7f into main Sep 6, 2026
8 checks passed
@Vonng
Vonng deleted the fix/issue-119-ssec-part-actual-size branch September 9, 2026 11:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[P1] Replicated SSE-C multipart parts record the ciphertext length, corrupting part-number reads and later the object size

1 participant