Skip to content

Commit 8dadbe7

Browse files
authored
Work around docker v25 tarballs (#1872)
Previously, we'd only seen compressed layers have LayerSources. As of v25, docker puts all layers in here, uncompressed, which exposed a bug in how Descriptor interacts with partial's uncompressed layer handling. Signed-off-by: Jon Johnson <[email protected]>
1 parent a0658aa commit 8dadbe7

File tree

3 files changed

+32
-11
lines changed

3 files changed

+32
-11
lines changed

pkg/v1/tarball/image.go

+22-11
Original file line numberDiff line numberDiff line change
@@ -299,18 +299,29 @@ func (i *uncompressedImage) LayerByDiffID(h v1.Hash) (partial.UncompressedLayer,
299299
// v1.Layer doesn't force consumers to care about whether the layer is compressed
300300
// we should be fine returning the DockerLayer media type
301301
mt := types.DockerLayer
302-
if bd, ok := i.imgDescriptor.LayerSources[h]; ok {
303-
// Overwrite the mediaType for foreign layers.
304-
return &foreignUncompressedLayer{
305-
uncompressedLayerFromTarball: uncompressedLayerFromTarball{
306-
diffID: diffID,
307-
mediaType: bd.MediaType,
308-
opener: i.opener,
309-
filePath: i.imgDescriptor.Layers[idx],
310-
},
311-
desc: bd,
312-
}, nil
302+
bd, ok := i.imgDescriptor.LayerSources[h]
303+
if ok {
304+
// This is janky, but we don't want to implement Descriptor for
305+
// uncompressed layers because it breaks a bunch of assumptions in partial.
306+
// See https://github.com/google/go-containerregistry/issues/1870
307+
docker25workaround := bd.MediaType == types.DockerUncompressedLayer || bd.MediaType == types.OCIUncompressedLayer
308+
309+
if !docker25workaround {
310+
// Overwrite the mediaType for foreign layers.
311+
return &foreignUncompressedLayer{
312+
uncompressedLayerFromTarball: uncompressedLayerFromTarball{
313+
diffID: diffID,
314+
mediaType: bd.MediaType,
315+
opener: i.opener,
316+
filePath: i.imgDescriptor.Layers[idx],
317+
},
318+
desc: bd,
319+
}, nil
320+
}
321+
322+
// Intentional fall through.
313323
}
324+
314325
return &uncompressedLayerFromTarball{
315326
diffID: diffID,
316327
mediaType: mt,

pkg/v1/tarball/image_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,16 @@ func TestBundleSingle(t *testing.T) {
7070
}
7171
}
7272

73+
func TestDocker25(t *testing.T) {
74+
img, err := ImageFromPath("testdata/hello-world-v25.tar", nil)
75+
if err != nil {
76+
t.Fatal(err)
77+
}
78+
if err := validate.Image(img); err != nil {
79+
t.Fatal(err)
80+
}
81+
}
82+
7383
func TestBundleMultiple(t *testing.T) {
7484
for _, imgName := range []string{
7585
"test_image_1",
20 KB
Binary file not shown.

0 commit comments

Comments
 (0)