Repository navigation
Description
Summary
v0.10.0 added a content SHA-256: PutObject computes it over the uncompressed body and
stores it as objectfs-sha256, and HeadObject reads it back into ObjectInfo.Checksum.
Nothing ever compares it. The integrity feature is write-only and detects nothing.
Background
The value is written on both upload paths — internal/storage/s3/backend.go PutObject:
rawHash := sha256.Sum256(data)
checksumHex := hex.EncodeToString(rawHash[:])
// ...
Metadata: map[string]string{
"objectfs-sha256": checksumHex,
},and initiateMultipartUpload in internal/storage/s3/multipart_upload.go. It is read back
in HeadObject:
if v, ok := result.Metadata["objectfs-sha256"]; ok {
info.Checksum = v
}Grepping for .Checksum across the repo finds only two consumers, neither of which is a
read-path verification:
internal/cache/persistent.go— compares its own separately-computed cache checksuminternal/archive/index.go— falls back to ETag when the field is empty
So a corrupted or mis-encoded object round-trips silently. This is the mechanism that would
have caught the Content-Encoding corruption in the companion issue: the stored hash is over
uncompressed content, so an object returned still-compressed would fail verification
immediately.
Implementation
Verify in GetObject after the decompression step, comparing against the objectfs-sha256
value. Constraints:
- Full-object reads only. A range read cannot be checked against a whole-object hash;
skip verification whenoffset > 0 || size > 0. - Skip when the metadata key is absent, so objects written before this feature (and objects
written by other tools) still read. - Return a distinct integrity error on mismatch — not a generic read error — so callers and
logs can tell corruption from a transport failure. - Gate behind a config flag defaulting to on. Hashing every full read has a real cost and
operators moving large objects need an escape hatch.
Verification needs the metadata, which the GetObject response already carries — do not add
a HeadObject round-trip per read.
Acceptance Criteria
- A full-object round-trip verifies successfully, compressed and uncompressed
- An object whose stored bytes are corrupted out-of-band (direct
client.PutObjectwith a
mismatchedobjectfs-sha256) causesGetObjectto return an integrity error - A ranged read does not attempt verification
- An object with no
objectfs-sha256metadata reads without error - Verification can be disabled by config; default is enabled
- No additional S3 request is issued per read
-
go test -race ./internal/storage/s3/...passes -
AWS_PROFILE=aws AWS_REGION=us-west-2 go test -race -tags=integration ./internal/storage/s3/...passes
Dependencies
None, and intentionally not blocked on C0-1 — this is the detection mechanism for that class
of bug and is worth landing independently. Against today's code these tests fail for a
CargoShip-uploaded compressed object, which is the point.
Activity
scttfrdmn commentedon Aug 2, 2026
Fixed in v0.10.1 (
27d2324,34ad91d).GetObjectnow verifies theobjectfs-sha256metadata against the bytes it read and fails withErrCodeDataCorruption— a never-retryable code, since retrying a corrupt read fetches the same bad bytes. The check is gated on the response being the whole object (parsed fromContent-Range), because a ranged read cannot be checked against a whole-object digest. Covered by tests that corrupt objects behind the backend with a raw SDK client — bit flip, truncation, extension, and replacement at identical length — plusFuzzWholeObjectResponseover theContent-Rangeparse, which found two real looseness bugs on its first run.