From a842fba2854de46a9ddc1968b510c41c6f8aa1de Mon Sep 17 00:00:00 2001 From: Aaron Lehmann Date: Fri, 1 Apr 2016 10:49:04 -0700 Subject: [PATCH] Fix build cache false positives when build context tar contains unnormalized paths If a build context tar has path names of the form 'x/./y', they will be stored in this unnormalized form internally by tarsum. When the builder walks the untarred directory tree and queries hashes for each relative path, it will query paths of the form 'x/y', and they will not be found. To correct this, have tarsum normalize path names by calling Clean. Add a test to detect this caching false positive. Fixes #21715 Signed-off-by: Aaron Lehmann --- tarsum/tarsum.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tarsum/tarsum.go b/tarsum/tarsum.go index 4dc89bd..154788d 100644 --- a/tarsum/tarsum.go +++ b/tarsum/tarsum.go @@ -28,6 +28,7 @@ import ( "fmt" "hash" "io" + "path" "strings" ) @@ -235,7 +236,7 @@ func (ts *tarSum) Read(buf []byte) (int, error) { } return n, err } - ts.currentFile = strings.TrimSuffix(strings.TrimPrefix(currentHeader.Name, "./"), "/") + ts.currentFile = path.Clean(currentHeader.Name) if err := ts.encodeHeader(currentHeader); err != nil { return 0, err }