-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
archive/tar: tar archives created with paths longer than 100 characters are not valid tar files #17630
Comments
@jonsyu1 helped with the investigation of this issue, and thinks this may be related to #12594. The symptoms also seem consistent with |
Although setting |
@dsnet, I'm marking this Go1.8Maybe in case it's easy, but feel free to punt to Go 1.9 if not. |
This is basically our issue: #9683 The linked duplicate bug is tagged for go1.9 and seemed like a large refactor of archive/tar. I feel like there is probably a smaller fix for this immediate bug. I quote @minux here:
Edit: ah read through #12594, seems like this is a pretty involved fix with writer header formatting :( @dsnet, do you have any recommendations on how to proceed before the writer fixes how it writes ustar/pax headers? |
Let me think about this. There may be an easy fix we can do in Go1.8 to at least disable the buggy behavior and do the full fix for Go1.9. |
Thanks for the extra info @jlz27 . Based on the details there, can confirm that this does seem to be fixed by always forcing usage of PAX headers in // NewWriter creates a new Writer writing to w.
func NewWriter(w io.Writer) *Writer {
return &Writer{w: w, preferPax: true}
} From looking around the However, since this does seem to work and be "safe", as a work-around on our end we may just vendor |
This may not be a viable work-around in core because it adds to the API surface, but we've worked around this creating a In our own Hope to see similar flexibility in the standard library at some point, but noting this work-around for now. |
As an alternative, you can consider using https://github.com/dsnet/tar. Please don't "go get" it, but just vendor the entire package. All of the fixes I have been making to the standard library are pretty much being copied from that repo. |
CL https://golang.org/cl/32234 mentions this issue. |
Change https://golang.org/cl/55574 mentions this issue: |
The logic for USTAR was disabled because a previous implementation of Writer had a wrong understanding of the differences between USTAR and GNU, causing the prefix field is incorrectly be populated in GNU files. Now that this issue has been fixed, we can re-enable the logic for USTAR path splitting, which allows Writer to use the USTAR for a wider range of possible inputs. Updates #9683 Updates #12594 Updates #17630 Change-Id: I9fe34e5df63f99c6dd56fee3a7e7e4d6ec3995c9 Reviewed-on: https://go-review.googlesource.com/55574 Run-TryBot: Joe Tsai <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
What version of Go are you using (
go version
)?go version go1.7.3 darwin/amd64
What did you do?
Used
tar.FileInfoHeader
andtarWriter.WriteHeader
to write an entry with a name (path in tar) longer than 100 characters.What did you expect to see?
The generated
tar
file should be valid, and it should be possible to use tools liketar
to expand the created archive.What did you see instead?
Expanding the archive using
tar -xf
on the host system failed --tar
reported an error, and the file in the archive which was supposed to be a file nested in many directories was written to the working directory of the expansion.Details, repro and possible fix
header.Uid
andheader.Gid
fields, as settingheader.Uid = 0
andheader.Gid = 0
before writing the header to thetar
file fixes the issueThe following test demonstrates the bug and the work-around. It requires
tar
to be present on the running system, as it usesexec.Command("tar", ...)
to perform the expansion (and thus cannot be run in the Go Playground).The text was updated successfully, but these errors were encountered: