Repository navigation
Description
Summary
Every codec is compiled into the binary, but a mount can decode only the single algorithm its
configuration names. So changing write_buffer.compression.algorithm on a bucket that already holds
compressed objects makes all of them unreadable, even though the code to read them is right there.
Verified against the in-process substrate endpoint. One object written with algorithm: zstd, then read
by four backends differing only in that field:
| reader configuration | result |
|---|---|
algorithm: zstd |
22,000 bytes, correct |
algorithm: gzip |
DATA_CORRUPTION: object is still encoded after decompression |
algorithm: lz4 |
DATA_CORRUPTION: object is still encoded after decompression |
enabled: false |
DATA_CORRUPTION: object is still encoded after decompression |
Cause
Compressor holds one codec, and Decompress compares the object's stored encoding against that one
codec's token — internal/compression/s3_integration.go:97-107:
func (c *Compressor) Decompress(data []byte, contentEncoding string) ([]byte, error) {
if contentEncoding == "" || contentEncoding != c.codec.ContentEncoding() {
return data, nil
}
...
}A mismatch returns the data unchanged, which is audit finding C2. The read then fails closed at
checkFullyDecoded (backend.go:442) because the decoded length is short of the recorded
objectfs-original-size. Failing is correct and is the C2 fix working. But the guard is compensating for
a dispatch that could have succeeded: compression.New accepts all four algorithms and every codec is
linked into the binary.
The claim this contradicts
backend.go:417-420 says:
Decompress if the object was stored with transparent compression. The encoding comes from the
object's own header rather than the write config, so objects stay readable across a config change
Half right. The decision to attempt a decode comes from the object's header. The codec used comes
from the write config, so objects do not stay readable across a config change. The comment describes the
intended design; the Compressor shape prevents it. Worth correcting in the same commit as the fix —
that comment is why the compression guidance doc (#186) initially claimed config changes were
read-safe.
Fix
Give Compressor a decode path keyed on the stored encoding rather than on its write codec. It already
receives contentEncoding; what it lacks is a way to get a codec for it.
- Build a decoder per encoding token on demand (
compression.Newmaps the token to the codec; the
reverse map from"zstd"→AlgorithmZstdis what is missing) and cache it. Codecs are documented
safe for concurrent use, so one instance per algorithm suffices. - Keep
Compresson the single configured codec. Writes should use exactly what the operator asked for;
only reads need to be catholic. enabled: falseshould still decode. A mount with compression off can read a compressed object today
only by accident — it fails, per the table above — and refusing to read data already in the bucket
because you turned off writing compression is not defensible.
That last point is the most valuable part: it decouples the read capability from the write setting, which
is what makes turning compression off a reversible decision.
Acceptance criteria
- An object written with each of zstd, lz4, gzip reads correctly under a mount configured for each of
the other algorithms and underenabled: false -
Compressstill uses only the configured algorithm — a test asserting the stored
Content-Encodingmatches the configuration - An encoding no codec handles (say
br) still fails closed withDATA_CORRUPTION; the guard must
not become unreachable -
backend.go:417-420corrected to describe what the code does - Table-driven over every pair in
pkg/compression.SupportedAlgorithms, so a new codec is covered by
construction
Provenance
Found while writing #186. The doc needed to tell users whether changing algorithm was safe; the code
comment said yes, a probe said no.
Activity
docs: what transparent compression costs, measured rather than assert…
fix: compression is configured where the compression happens (#244)