From c44c9dfa79a44b3e185d954a18ab3bd36a2d84dd Mon Sep 17 00:00:00 2001 From: Cory Snider Date: Mon, 23 Oct 2023 14:29:27 -0400 Subject: [PATCH] pkg/tarsum: migrate to (tar.Header).PAXRecords Fix a silly bug in the implementation which had the effect of len(h.Xattrs) blank entries being inserted in the middle of orderedHeaders. Luckily this is not a load-bearing bug: empty headers are ignored as the tarsum digest is computed by concatenating header keys and values without any intervening delimiter. Signed-off-by: Cory Snider --- pkg/tarsum/versioning.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/pkg/tarsum/versioning.go b/pkg/tarsum/versioning.go index edc3ec8cfd..c475dd9fe0 100644 --- a/pkg/tarsum/versioning.go +++ b/pkg/tarsum/versioning.go @@ -115,15 +115,18 @@ func v0TarHeaderSelect(h *tar.Header) (orderedHeaders [][2]string) { func v1TarHeaderSelect(h *tar.Header) (orderedHeaders [][2]string) { // Get extended attributes. - xAttrKeys := make([]string, len(h.Xattrs)) - for k := range h.Xattrs { - xAttrKeys = append(xAttrKeys, k) + const paxSchilyXattr = "SCHILY.xattr." + var xattrs [][2]string + for k, v := range h.PAXRecords { + if xattr, ok := strings.CutPrefix(k, paxSchilyXattr); ok { + xattrs = append(xattrs, [2]string{xattr, v}) + } } - sort.Strings(xAttrKeys) + sort.Slice(xattrs, func(i, j int) bool { return xattrs[i][0] < xattrs[j][0] }) // Make the slice with enough capacity to hold the 11 basic headers // we want from the v0 selector plus however many xattrs we have. - orderedHeaders = make([][2]string, 0, 11+len(xAttrKeys)) + orderedHeaders = make([][2]string, 0, 11+len(xattrs)) // Copy all headers from v0 excluding the 'mtime' header (the 5th element). v0headers := v0TarHeaderSelect(h) @@ -131,9 +134,7 @@ func v1TarHeaderSelect(h *tar.Header) (orderedHeaders [][2]string) { orderedHeaders = append(orderedHeaders, v0headers[6:]...) // Finally, append the sorted xattrs. - for _, k := range xAttrKeys { - orderedHeaders = append(orderedHeaders, [2]string{k, h.Xattrs[k]}) - } + orderedHeaders = append(orderedHeaders, xattrs...) return }