fix(tarball): normalize paths when matching files by bstoll · Pull Request #2334 · google/go-containerregistry (original) (raw)
If a container tarball has files with a ./ prefix (e.g., ./manifest.json), crane will fail to read the tarball:
$ tar -tf ~/container.tar
./
./oci-layout
./blobs/
./blobs/sha256/
./blobs/sha256/de1805b7dcf01c7289213f2d00b4fa83b5ebca05bfa89d039366d245bb7dedfd
./blobs/sha256/5e61b8d13deec901f273c1aa64003d0ce996f269f45e784de63108a37a255748
./blobs/sha256/9a6e2635fc8f2742435231c485565190972efda953a9c0d85b9d49c160a0d9ee
./index.json
./manifest.json
./repositories
$ ./crane validate --tarball ~/container.tar
Error: failed to read image /usr/local/google/home/bstoll/container.tar: file manifest.json not found in tar
This change uses path.Clean on both header name and target path to ensure they match correctly even if they have different formatting.