Repository navigation
fix(s3): a directory marker must not touch the object mirror (#534) - #541
Merged
Merged
Conversation
PUT dir/, PUT dir/a.txt, DELETE dir/, DELETE dir/a.txt returned HTTP 500 on the last call. S3 keys are opaque strings, but the afero filesystem the plugin mirrors object bodies into is hierarchical, and filepath.Clean normalizes /bucket/dir/ to /bucket/dir -- the directory node MkdirAll created to hold dir/a.txt. Removing the marker removed that node, orphaning its children, and the child's delete then panicked inside MemMapFs. DeleteObjects inherited it, delegating per key. The write path already guarded this: a marker's body is always empty and is never written to the mirror. The delete and copy paths did not. All six sites now share one s3ObjectHasBody predicate instead of four hand-copied HasSuffix checks -- the drift that produced the bug. Two adjacent cases fall out, neither in the reproduction: "dir" and "dir/" are distinct S3 keys colliding on one mirror path, so a marker operation truncated or deleted the body of the object one character away from it; and a marker's versioned path .versions/dir//<versionID> normalizes onto the directory holding the versions of a child key named dir/<versionID>, which is reachable because a client reads that version ID off the marker's own PUT. CopyObject over a marker now succeeds in both directions, yielding the empty object a marker is. Ten mutants applied across the predicate and all six guards; all caught.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #534.
PUT dir/,PUT dir/a.txt,DELETE dir/,DELETE dir/a.txt— the last callreturned HTTP 500, reproduced end to end against a binary built from
v0.88.0:Why
S3 keys are opaque strings, but the afero filesystem the plugin mirrors object
bodies into is hierarchical, and
filepath.Cleannormalizes/bucket/dir/to/bucket/dir— the same path as the directory nodeMkdirAllcreated to holddir/a.txt. Removing the marker removed that node, orphaning its children, and thechild's own delete then hit
log.PanicinunRegisterWithParent(
memmap.go:73), recovered as a 500.DeleteObjectsinherited it, since itdelegates per key.
I verified the mechanism against afero v1.15.0 using substrate's actual call
pattern rather than the issue's simplified one, which matters: the marker is
already never written to the mirror, so the node that gets destroyed is the one
created implicitly for the child, not the marker's own file.
The fix — option 1 from the issue, not option 2
The write path already had the right guard; the delete and copy paths did not. All
six sites now go through one predicate:
One function rather than a fourth hand-copied
strings.HasSuffix— the driftbetween three guarded sites and three unguarded ones is what produced this bug. No
new encoding is introduced, which is why option 2 (a distinct on-disk
representation for markers) is not needed: skipping the mirror restores the
invariant the write path already assumed.
Two adjacent cases the reproduction does not name
Both surfaced from mutation testing, and both are reachable:
diranddir/are distinct S3 keys that collide on a single mirror path.Before this change, putting, deleting, or copying onto the marker
dir/truncated or deleted the body of the ordinary object at
dir. This is thesharper test: it needs no children at all.
.versions/dir//<versionID>normalizes onto the directory holding the versions of a child key named
dir/<versionID>. That is not theoretical — a client reads the version ID offthe marker's own
PUTresponse, so the sequence is constructible.CopyObjectover a marker now succeeds in both directions, yielding the emptyobject a marker is; reading one as a source used to fail outright on
ReadFile.Source and destination are guarded independently so a marker→regular copy produces
an empty object rather than an error.
Tests
emulator/s3_directory_marker_test.go, all failing before the change:DeleteDoesNotStrandChildrenDeleteObjectsDoesNotStrandChildrenDeleteThenReadChilddir/deletes one zero-byte objectDeleteLeavesFilesystemIntactWritesNoFileToTheMirrorVersionedDeleteDoesNotStrandChildVersionsSiblingKeyIsNotClobberedCopyMutation testing
Ten mutants across the predicate and all six guard sites — inverted, always-true,
always-false, and each guard dropped in turn. All caught, no survivors.
Three survived initially and each was a genuine test-design gap rather than an
equivalence, so the tests were strengthened rather than the mutants excused:
dropping the
copyObjectdestination guard and theputObjectwrite guard wereboth invisible until
SiblingKeyIsNotClobberedexisted (the corruption only biteson a later
Remove, which no test performed), and dropping the versioned-deleteguard needed
VersionedDeleteDoesNotStrandChildVersionsasserting on the child'spermanent version delete — the call that actually reaches
fs.Remove.Verification
gofmt -l .,go build ./...,go vet ./...,golangci-lint run ./...→ 0issues,
make test(race),make docs-reference docs-reference-check docs-versions(no diff — no plugin added),npm --prefix docs run build,go vet -C test/e2e ./...,go test -C test/e2e ./.... Plus the end-to-endsequence above against
substrate server, which now returns a clean 204 and anempty bucket listing.
Compatibility
No state-format change, so existing snapshots and recorded event logs replay
identically. A caller that was receiving a 500 now receives the documented
response; nothing that previously succeeded changes behaviour.