Skip to content

Commit

Permalink
docker tarfile: report correct size of compressed layers
Browse files Browse the repository at this point in the history
Tools like umoci will always compress layers, and in order to work
around some *lovely* issues with DiffIDs, tarfile.GetBlob would always
decompress them. However the BlobInfo returned from tarfile.GetBlob
would incorrectly give the size of the *compressed* layer because the
size caching code didn't actually check the layer size, resulting in
"skopeo copy" failing whenever sourcing umoci images.

As an aside, for some reason the oci: transport doesn't report errors
when the size is wrong...

Signed-off-by: Aleksa Sarai <[email protected]>

(Updated primarily to handle closing the decompressed stream.)
Signed-off-by: Miloslav Trmač <[email protected]>
  • Loading branch information
cyphar authored and mtrmac committed Jul 17, 2018
1 parent 3181923 commit 6353fa5
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion docker/tarfile/src.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,25 @@ func (s *Source) prepareLayerData(tarManifest *ManifestItem, parsedConfig *manif
return nil, err
}
if li, ok := unknownLayerSizes[h.Name]; ok {
li.size = h.Size
// Since GetBlob will decompress layers that are compressed we need
// to do the decompression here as well, otherwise we will
// incorrectly report the size. Pretty critical, since tools like
// umoci always compress layer blobs. Obviously we only bother with
// the slower method of checking if it's compressed.
uncompressedStream, isCompressed, err := compression.AutoDecompress(t)
if err != nil {
return nil, errors.Wrapf(err, "Error auto-decompressing %s to determine its size", h.Name)
}
defer uncompressedStream.Close()

uncompressedSize := h.Size
if isCompressed {
uncompressedSize, err = io.Copy(ioutil.Discard, uncompressedStream)
if err != nil {
return nil, errors.Wrapf(err, "Error reading %s to find its size", h.Name)
}
}
li.size = uncompressedSize
delete(unknownLayerSizes, h.Name)
}
}
Expand Down

0 comments on commit 6353fa5

Please sign in to comment.