@@ -18,6 +18,9 @@ import (
1818var (
1919 GitCommitRegex = regexp .MustCompile (`^[0-9a-f]{1,64}$` )
2020 GitFetchRegex = regexp .MustCompile (`^refs/(heads|tags)/[^*?:]+$` )
21+
22+ // https://github.com/docker/distribution/blob/v2.7.1/reference/regexp.go#L37
23+ ValidTagRegex = regexp .MustCompile (`^\w[\w.-]{0,127}$` )
2124)
2225
2326type Manifest2822 struct {
@@ -395,6 +398,9 @@ func (manifest *Manifest2822) AddEntry(entry Manifest2822Entry) error {
395398 entry .DeduplicateSharedTags ()
396399 entry .CleanDirectoryValues ()
397400
401+ if invalidTags := entry .InvalidTags (); len (invalidTags ) > 0 {
402+ return fmt .Errorf ("Tags %q has invalid (Shared)Tags: %q" , entry .TagsString (), strings .Join (invalidTags , ", " ))
403+ }
398404 if invalidArchitectures := entry .InvalidArchitectures (); len (invalidArchitectures ) > 0 {
399405 return fmt .Errorf ("Tags %q has invalid Architectures: %q" , entry .TagsString (), strings .Join (invalidArchitectures , ", " ))
400406 }
@@ -458,6 +464,16 @@ func (entry Manifest2822Entry) InvalidMaintainers() []string {
458464 return invalid
459465}
460466
467+ func (entry Manifest2822Entry ) InvalidTags () []string {
468+ invalid := []string {}
469+ for _ , tag := range append (append ([]string {}, entry .Tags ... ), entry .SharedTags ... ) {
470+ if ! ValidTagRegex .MatchString (tag ) {
471+ invalid = append (invalid , tag )
472+ }
473+ }
474+ return invalid
475+ }
476+
461477func (entry Manifest2822Entry ) InvalidArchitectures () []string {
462478 invalid := []string {}
463479 for _ , arch := range entry .Architectures {
0 commit comments