diff --git a/x/build/blob/ref.go b/x/build/blob/ref.go index c824391a..32fddb08 100644 --- a/x/build/blob/ref.go +++ b/x/build/blob/ref.go @@ -11,7 +11,8 @@ type PartKind int // Levels of concreteness const ( - Domain PartKind = iota + Invalid PartKind = iota + Domain Namespace Name Tag @@ -140,11 +141,11 @@ func (r Ref) Less(o Ref) bool { // The length of the returned slice is always 5. func (r Ref) Parts() []string { return []string{ - Domain: r.domain, - Namespace: r.namespace, - Name: r.name, - Tag: r.tag, - Build: r.build, + r.domain, + r.namespace, + r.name, + r.tag, + r.build, } } @@ -190,6 +191,8 @@ func ParseRef(s string) Ref { r = r.WithTag(part) case Build: r = r.WithBuild(part) + case Invalid: + return Ref{} } } if !r.Valid() { @@ -215,6 +218,9 @@ func Parts(s string) iter.Seq2[PartKind, string] { if len(s) > 255 || len(s) == 0 { return } + if !isValidPart(string(s[0])) { + return + } yieldValid := func(kind PartKind, value string) bool { if !isValidPart(value) { @@ -259,6 +265,7 @@ func Parts(s string) iter.Seq2[PartKind, string] { } state, j = Domain, i default: + yield(Invalid, "") return } } @@ -269,7 +276,6 @@ func Parts(s string) iter.Seq2[PartKind, string] { case Domain: yieldValid(Domain, s[:j]) case Namespace: - println("namespace", s[:j]) yieldValid(Namespace, s[:j]) default: yieldValid(Name, s[:j]) diff --git a/x/build/blob/testdata/fuzz/FuzzParseRef/3e3b70dba384074d b/x/build/blob/testdata/fuzz/FuzzParseRef/3e3b70dba384074d new file mode 100644 index 00000000..880ce7a3 --- /dev/null +++ b/x/build/blob/testdata/fuzz/FuzzParseRef/3e3b70dba384074d @@ -0,0 +1,2 @@ +go test fuzz v1 +string("0 /0")