fix(storage): bounds-check the file basename in PurgeUploads Walk callback#4860
Merged
milosgajdos merged 1 commit intoApr 22, 2026
Conversation
…lback PurgeUploads' Walk callback split the visited path with path.Split and indexed file[0] immediately. path.Split returns an empty basename for paths that end in a trailing slash - in practice this happens when an S3 driver surfaces a bare directory (common prefix) with an empty Key. Indexing a zero-length string then panics with 'index out of range [0] with length 0' and takes down the whole PurgeUploads goroutine (distribution#4713). Guard the length before touching file[0] so a trailing-slash / empty-basename entry is simply skipped as 'not a reserved directory', which matches what the branch was trying to do anyway. Runtime behaviour for every non-empty entry is unchanged. Closes distribution#4713 Signed-off-by: SAY-5 <SAY-5@users.noreply.github.com>
milosgajdos
approved these changes
Apr 21, 2026
squizzi
approved these changes
Apr 22, 2026
squizzi
left a comment
Collaborator
There was a problem hiding this comment.
Thanks for including a code comment describing the fix.
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.
What
Fixes #4713.
PurgeUploads'
Walkcallback split the visited path withpath.Splitand then indexedfile[0]immediately.path.Splitreturns an empty basename for paths that end in a trailing slash - in practice this happens when an S3 driver surfaces a bare directory (common prefix) with an empty Key. Indexing a zero-length string panics withindex out of range [0] with length 0and takes down the whole PurgeUploads goroutine, as seen in the report's trace (purgeuploads.go:73→s3.go:1023).Fix
Guard the length before touching
file[0]so a trailing-slash / empty-basename entry is skipped as 'not a reserved directory' - matching what the branch was trying to do anyway. Runtime behaviour for every non-empty entry is unchanged; only the zero-length edge case stops crashing.Verification
Locally on macOS, go 1.26.2:
gofmt -s -l registry/storage/purgeuploads.go: cleango vet ./registry/storage/...: cleango test -count=1 -run TestPurge ./registry/storage/: passCloses #4713