Skip to content

C0-10: Verify the objectfs-sha256 checksum on read #155

Closed

Description

@scttfrdmn

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 checksum
  • internal/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 when offset > 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.PutObject with a
    mismatched objectfs-sha256) causes GetObject to return an integrity error
  • A ranged read does not attempt verification
  • An object with no objectfs-sha256 metadata 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

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

    @scttfrdmn
    OwnerAuthor

    Fixed in v0.10.1 (27d2324, 34ad91d). GetObject now verifies the objectfs-sha256 metadata against the bytes it read and fails with ErrCodeDataCorruption — 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 from Content-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 — plus FuzzWholeObjectResponse over the Content-Range parse, which found two real looseness bugs on its first run.

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: hightype: bug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions