Repository navigation
Description
Summary
When transparent compression is active, HeadObject reports the compressed byte count as the object size. That value reaches the kernel through Getattr, so the kernel stops every read at the compressed length and every compressed file reads back silently truncated. Compression is enabled by default on the mount path, so this affects default deployments.
This outranks #153 in severity: #153 requires EnableCargoShipOptimization to be reachable (it is not, on the mount path today), whereas this defect is live right now on any default mount.
Background
The full chain, verified end to end:
-
Nothing records the original size.
PutObject(internal/storage/s3/backend.go) setsContentLength: aws.Int64(int64(len(uploadData)))—uploadDatais post-compression. The metadata map it writes contains onlyobjectfs-sha256. Grep fororiginal-size/originalSize/objectfs-sizeacrossinternal/storage/s3/returns zero hits. The uncompressed length is computed and then discarded. -
HeadObjectreads the compressed length back. It assignsSize: aws.ToInt64(result.ContentLength), which for a compressed object is the stored (compressed) size. -
That size reaches the kernel.
DirectoryNode.Lookup(internal/fuse/filesystem.go:202) callsHeadObject, caches the result viacacheInfo, and builds the child node from it.FileNode.Getattr(filesystem.go:410) then does:out.Size = safeInt64ToUint64(f.info.Size) // compressed size
-
The kernel truncates the read.
statandls -lreport the compressed size, and the kernel issues no read beyond it.GetObjectcorrectly decompresses to the full original length, but the caller never asks for those bytes. The user receives a correctly-decompressed prefix, silently short.
Compression is on by default for real mounts. buildS3Config (internal/adapter/adapter.go) maps a.config.WriteBuffer.Compression into s3.CompressionConfig, and those defaults (internal/config/config.go:359-364) are Enabled: true, gzip, level 6, MinSize: "1KB". A 1 KB threshold means nearly every file of consequence is compressed. (s3.NewDefaultConfig independently defaults to Enabled: true with zstd/3/4KB — see #157 for that mismatch.)
Why the existing tests miss it. The compression round-trip tests call GetObject(ctx, key, 0, 0) directly and assert on the returned bytes, which is the one path that works. No test calls HeadObject on a compressed object, and no test exercises the FUSE layer. The bug lives entirely in the gap between them.
Implementation
Persist the uncompressed length at write time and prefer it at read time.
-
In
PutObject, when compression was applied, add the original length to the metadata map alongside the existing checksum:metadata := map[string]string{"objectfs-sha256": checksumHex} if wasCompressed { metadata["objectfs-original-size"] = strconv.FormatInt(int64(len(data)), 10) }
Apply the same in
initiateMultipartUpload(internal/storage/s3/multipart_upload.go:50), which builds its own metadata map. -
In
HeadObject, whenobjectfs-original-sizeis present and parses, use it forinfo.Size; otherwise fall back toContentLength. Objects written before this change have no such key and remain compressed-size — call that out inCHANGELOG.mdas a known limitation for pre-0.10.1 compressed objects. -
Audit the other
ObjectInfo.Sizeproducer,ListObjects, which reportsSizefrom the list response and has no metadata available at all.ListObjectscannot recover the original size without a per-objectHeadObject. Decide explicitly: either accept compressed sizes inReaddir(directory listings show wrong sizes but reads still work, becauseLookup->HeadObjectsupplies the size the kernel actually uses for I/O), or document the divergence. Do not add a HeadObject-per-entry fan-out inReaddirwithout measuring it. -
Also fix the
ContentLengthon the standardPutObjectpath only if S3 requires the wire length — it does, so leaveContentLengthas the compressed length. This issue is aboutObjectInfo.Size, not the HTTP header.
Acceptance Criteria
-
Unit test:
PutObjectof a compressible payload aboveMinSizewritesobjectfs-original-sizematchinglen(data); a payload belowMinSizedoes not write the key. -
Unit test:
HeadObjectreturns the uncompressed size when the key is present, and falls back toContentLengthwhen it is absent. -
Integration test asserting the defect is gone — with compression enabled, write a highly compressible payload, then
HeadObjectand assertinfo.Size == len(original), not the stored length:AWS_PROFILE=aws AWS_REGION=us-west-2 go test -race -tags=integration ./internal/storage/s3/... -
FUSE-level test:
Getattron a compressed object reports the uncompressed size. This is the assertion that would have caught the bug. -
Live mount check — the decisive end-to-end gate:
# with compression enabled, on a mount dd if=/dev/zero of=/mnt/objectfs/test/f bs=1M count=10 stat -f %z /mnt/objectfs/test/f # must report 10485760, not the compressed size wc -c < /mnt/objectfs/test/f # must report 10485760
-
go test -race ./internal/storage/s3/... ./internal/fuse/...passes; package coverage stays at or above 80%.
Dependencies
None — independent of #153, #154, and #155, and should land in the same release. Interacts with #157 (which changes which codec runs on the mount path but not whether compression is on) and #156 (the parallel-read path is disabled whenever compression is active, so these two features are mutually exclusive by design today).
Activity
scttfrdmn commentedon Jul 30, 2026
Landed
Fixed on
main(uncommitted at time of writing; will reference the commit once pushed).The size bug.
PutObjectnow writesobjectfs-original-size(uncompressed byte length) into S3 user metadata whenever compression actually shrank the object, andHeadObjectreports it via a neworiginalSize()helper. Objects written before this change have no such key and fall back toContentLength, so the change is backward compatible.A second bug found while fixing the first.
putObjectMultipartwas callingsha256.Sum256(data)on its own — but by that pointdataheld the compressed bytes, whereas the single-part path hashes the uncompressed content. The two upload paths were writing hashes of different byte streams under the sameobjectfs-sha256key. Any read-side verification (#155) would have failed on every compressed multipart object. Fixed by threading the single-part path's metadata map down throughputObjectMultipart→initiateMultipartUploadinstead of recomputing; the multipart helper now carries a comment explaining why it must not hash locally.Verified against real S3 (
objectfs-test-scttfrdmn, us-west-2), both paths:TestCompressedObjectSizeReporting/single-part— 64 KB compressible objectTestCompressedObjectSizeReporting/multipart— 40 MB object, aboveMultipartThresholdEach asserts uncompressed
info.Size, a checksum over the uncompressed content, byte-identical round-trip, and that a read of exactlyinfo.Sizebytes returns the whole object.TestZSTDCompressiongained the size assertion it was missing, plus raw-client checks that the storedContentLengthis smaller than the logical size andContentEncodingiszstd— that distinction matters, sinceoriginalSizecorrectly reports the logical size through the ObjectFS API regardless of what is on the wire.Confirmed the tests detect the bug. With the fix temporarily neutralized, the 40 MB file reported 4,556 bytes and the 64 KB file 87 bytes.
Deliberately not fixed here
ListObjectsstill reports compressed sizes: the S3 list response carries no user metadata, so recovering the logical size would need aHeadObjectfan-out per key — an N-fold request amplification on everyreaddir. It does not affect correctness of reads, because the kernel takes file size fromLookup→HeadObject, not fromreaddir. Noted in a code comment at the call site.scttfrdmn commentedon Aug 2, 2026
Fixed in v0.10.1 (
27d2324). The uncompressed size is stored asobjectfs-original-sizeandHeadObjectreports it, so a compressed object no longer advertises its compressed length. Measured before the fix: a 32 KB object reported 4,556 bytes and a 64 KB object reported 87 bytes, making over 99.99% of the data unreachable through a mount. Objects written before this change fall back toContentLengthas before.