Skip to content

Commit b5413c2

Browse files
committed
Move the tar-split digest value into the TOC
... so that we can uniquely identify partially-pulled layers by the TOC digest. Signed-off-by: Miloslav Trmač <[email protected]>
1 parent dfb4b1f commit b5413c2

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

pkg/chunked/cache_linux.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,14 @@ func unmarshalToc(manifest []byte) (*internal.TOC, error) {
897897
toc.Entries = append(toc.Entries, m)
898898
}
899899

900+
case "tarsplitdigest": // strings.ToLower("tarSplitDigest")
901+
s := iter.ReadString()
902+
d, err := digest.Parse(s)
903+
if err != nil {
904+
return nil, fmt.Errorf("Invalid tarSplitDigest %q: %w", s, err)
905+
}
906+
toc.TarSplitDigest = d
907+
900908
default:
901909
iter.Skip()
902910
}

pkg/chunked/compression_linux.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,10 @@ func readZstdChunkedManifest(blobStream ImageSourceSeekable, tocDigest digest.Di
147147
// The tarSplit… values are valid if tarSplitChunk.Offset > 0
148148
var tarSplitChunk ImageSourceChunk
149149
var tarSplitLengthUncompressed uint64
150-
var tarSplitChecksum string
151150
if tarSplitInfoKeyAnnotation, found := annotations[internal.TarSplitInfoKey]; found {
152151
if _, err := fmt.Sscanf(tarSplitInfoKeyAnnotation, "%d:%d:%d", &tarSplitChunk.Offset, &tarSplitChunk.Length, &tarSplitLengthUncompressed); err != nil {
153152
return nil, nil, nil, 0, err
154153
}
155-
tarSplitChecksum = annotations[internal.TarSplitChecksumKey]
156154
}
157155

158156
if manifestType != internal.ManifestTypeCRFS {
@@ -217,7 +215,7 @@ func readZstdChunkedManifest(blobStream ImageSourceSeekable, tocDigest digest.Di
217215
return nil, nil, nil, 0, err
218216
}
219217

220-
decodedTarSplit, err = decodeAndValidateBlob(tarSplit, tarSplitLengthUncompressed, tarSplitChecksum)
218+
decodedTarSplit, err = decodeAndValidateBlob(tarSplit, tarSplitLengthUncompressed, toc.TarSplitDigest.String())
221219
if err != nil {
222220
return nil, nil, nil, 0, err
223221
}

pkg/chunked/internal/compression.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ import (
1818
)
1919

2020
type TOC struct {
21-
Version int `json:"version"`
22-
Entries []FileMetadata `json:"entries"`
21+
Version int `json:"version"`
22+
Entries []FileMetadata `json:"entries"`
23+
TarSplitDigest digest.Digest `json:"tarSplitDigest,omitempty"`
2324
}
2425

2526
type FileMetadata struct {
@@ -84,7 +85,7 @@ func GetType(t byte) (string, error) {
8485
const (
8586
ManifestChecksumKey = "io.github.containers.zstd-chunked.manifest-checksum"
8687
ManifestInfoKey = "io.github.containers.zstd-chunked.manifest-position"
87-
TarSplitChecksumKey = "io.github.containers.zstd-chunked.tarsplit-checksum"
88+
TarSplitChecksumKey = "io.github.containers.zstd-chunked.tarsplit-checksum" // Deprecated: Use the TOC.TarSplitDigest field instead, this one is not authenticated by ManifestChecksumKey.
8889
TarSplitInfoKey = "io.github.containers.zstd-chunked.tarsplit-position"
8990

9091
// ManifestTypeCRFS is a manifest file compatible with the CRFS TOC file.
@@ -133,8 +134,9 @@ func WriteZstdChunkedManifest(dest io.Writer, outMetadata map[string]string, off
133134
manifestOffset := offset + zstdSkippableFrameHeader
134135

135136
toc := TOC{
136-
Version: 1,
137-
Entries: metadata,
137+
Version: 1,
138+
Entries: metadata,
139+
TarSplitDigest: tarSplitData.Digest,
138140
}
139141

140142
json := jsoniter.ConfigCompatibleWithStandardLibrary

0 commit comments

Comments
 (0)