Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tar PAX format handling #1414

Merged
merged 2 commits into from Jul 22, 2022
Merged

Fix tar PAX format handling #1414

merged 2 commits into from Jul 22, 2022

Conversation

ondrej-smola
Copy link
Contributor

Fixes #1412

@google-cla
Copy link

google-cla bot commented Jul 21, 2022

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Comment on lines 274 to 280
// tar.Next() sometimes mistakenly guesses format as USTAR, which creates a problem:
// if the header.Name is > 100 characters long, WriteHeader() returns an error like
// "archive/tar: cannot encode header: Format specifies USTAR; and USTAR cannot encode Name=...".
// To fix, change format from USTAR to PAX on Windows
if isWin && header.Format == tar.FormatUSTAR {
header.Format = tar.FormatPAX
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh. This seems like the kind of thing I'd expect archive/tar to handle for us... :-/

Can you add a link to the issue in the comment, and maybe any other helpful issues you've found while debugging this? That will help remind me better why this is here when I rediscover it in six months, or if I have the same Windows-specific issue elsewhere and come back here to try to remember what the deal was.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is also viable path that linuxkit chose - to force PAX on output linuxkit/linuxkit#3141
Maybe force PAX and document it using reasoning in pull request above?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be okay with just always setting this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM 👍

Comment on lines 274 to 280
// tar.Next() sometimes mistakenly guesses format as USTAR, which creates a problem:
// if the header.Name is > 100 characters long, WriteHeader() returns an error like
// "archive/tar: cannot encode header: Format specifies USTAR; and USTAR cannot encode Name=...".
// To fix, change format from USTAR to PAX on Windows
if isWin && header.Format == tar.FormatUSTAR {
header.Format = tar.FormatPAX
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be okay with just always setting this.

@@ -297,7 +308,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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@codecov-commenter
Copy link

codecov-commenter commented Jul 22, 2022

Codecov Report

Merging #1414 (05c84da) into main (5749ee6) will decrease coverage by 0.01%.
The diff coverage is 57.14%.

@@            Coverage Diff             @@
##             main    #1414      +/-   ##
==========================================
- Coverage   73.38%   73.36%   -0.02%     
==========================================
  Files         115      115              
  Lines        8750     8756       +6     
==========================================
+ Hits         6421     6424       +3     
- Misses       1688     1690       +2     
- Partials      641      642       +1     
Impacted Files Coverage Δ
pkg/v1/mutate/mutate.go 72.06% <57.14%> (-0.47%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us.

@ondrej-smola ondrej-smola changed the title Fix tar PAX format handling on Windows Fix tar PAX format handling Jul 22, 2022
@jonjohnsonjr jonjohnsonjr merged commit 3ba4c51 into google:main Jul 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

archive/tar: write too long when calling crane export on mcr.microsoft.com/dotnet on windows
4 participants