Skip to content

Commit

Permalink
Fix tar PAX format handling (#1414)
Browse files Browse the repository at this point in the history
* fix tar PAX handling on Windows

* always force PAX format
  • Loading branch information
ondrej-smola committed Jul 22, 2022
1 parent 5749ee6 commit 3ba4c51
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/v1/mutate/mutate.go
Expand Up @@ -244,6 +244,7 @@ func extract(img v1.Image, w io.Writer) error {
if err != nil {
return fmt.Errorf("retrieving image layers: %w", err)
}

// we iterate through the layers in reverse order because it makes handling
// whiteout layers more efficient, since we can just keep track of the removed
// files as we see .wh. layers and ignore those in previous layers.
Expand All @@ -267,6 +268,10 @@ func extract(img v1.Image, w io.Writer) error {
// Some tools prepend everything with "./", so if we don't Clean the
// name, we may have duplicate entries, which angers tar-split.
header.Name = filepath.Clean(header.Name)
// force PAX format to remove Name/Linkname length limit of 100 characters
// required by USTAR and to not depend on internal tar package guess which
// prefers USTAR over PAX
header.Format = tar.FormatPAX

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

0 comments on commit 3ba4c51

Please sign in to comment.