From 04e6cc37fa14c9b3bf464ec04131c236dc0e98cb Mon Sep 17 00:00:00 2001 From: xiekeyang Date: Wed, 4 Mar 2015 16:02:50 +0800 Subject: [PATCH 1/2] func Validate in digest doesn't filter no-hex data --- digest/digest.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/digest/digest.go b/digest/digest.go index efbe49bd7..2eb5a0cc0 100644 --- a/digest/digest.go +++ b/digest/digest.go @@ -47,7 +47,7 @@ func NewDigestFromHex(alg, hex string) Digest { } // DigestRegexp matches valid digest types. -var DigestRegexp = regexp.MustCompile(`[a-zA-Z0-9-_+.]+:[a-zA-Z0-9-_+.=]+`) +var DigestRegexp = regexp.MustCompile(`[a-zA-Z0-9-_+.]+:[a-fA-F0-9-_+.=]+$`) var ( // ErrDigestInvalidFormat returned when digest format invalid. @@ -112,6 +112,10 @@ func (d Digest) Validate() error { // Continue on for general parser + if !DigestRegexp.MatchString(s) { + return ErrDigestInvalidFormat + } + i := strings.Index(s, ":") if i < 0 { return ErrDigestInvalidFormat From 8081a13cdff97bf0029eb2e7e0d15ced9954ce5a Mon Sep 17 00:00:00 2001 From: xiekeyang Date: Wed, 4 Mar 2015 16:02:50 +0800 Subject: [PATCH 2/2] :func Validate in digest doesn't filter no-hex data --- digest/digest.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/digest/digest.go b/digest/digest.go index efbe49bd7..06e9fad80 100644 --- a/digest/digest.go +++ b/digest/digest.go @@ -112,6 +112,10 @@ func (d Digest) Validate() error { // Continue on for general parser + if !DigestRegexp.MatchString(s) { + return ErrDigestInvalidFormat + } + i := strings.Index(s, ":") if i < 0 { return ErrDigestInvalidFormat @@ -129,8 +133,6 @@ func (d Digest) Validate() error { return ErrDigestUnsupported } - // TODO(stevvooe): Use DigestRegexp to validate digest here. - return nil }