Skip to content

Commit 3ba4c51

Browse files
authored
Fix tar PAX format handling (#1414)
* fix tar PAX handling on Windows * always force PAX format
1 parent 5749ee6 commit 3ba4c51

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

pkg/v1/mutate/mutate.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ func extract(img v1.Image, w io.Writer) error {
244244
if err != nil {
245245
return fmt.Errorf("retrieving image layers: %w", err)
246246
}
247+
247248
// we iterate through the layers in reverse order because it makes handling
248249
// whiteout layers more efficient, since we can just keep track of the removed
249250
// files as we see .wh. layers and ignore those in previous layers.
@@ -267,6 +268,10 @@ func extract(img v1.Image, w io.Writer) error {
267268
// Some tools prepend everything with "./", so if we don't Clean the
268269
// name, we may have duplicate entries, which angers tar-split.
269270
header.Name = filepath.Clean(header.Name)
271+
// force PAX format to remove Name/Linkname length limit of 100 characters
272+
// required by USTAR and to not depend on internal tar package guess which
273+
// prefers USTAR over PAX
274+
header.Format = tar.FormatPAX
270275

271276
basename := filepath.Base(header.Name)
272277
dirname := filepath.Dir(header.Name)
@@ -297,7 +302,9 @@ func extract(img v1.Image, w io.Writer) error {
297302
// any entries with a matching (or child) name
298303
fileMap[name] = tombstone || !(header.Typeflag == tar.TypeDir)
299304
if !tombstone {
300-
tarWriter.WriteHeader(header)
305+
if err := tarWriter.WriteHeader(header); err != nil {
306+
return err
307+
}
301308
if header.Size > 0 {
302309
if _, err := io.CopyN(tarWriter, tarReader, header.Size); err != nil {
303310
return err

0 commit comments

Comments
 (0)