-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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: needs hardening and refactoring #12638
Comments
CL https://golang.org/cl/14624 mentions this issue. |
@dsymonds, what is the point of the At first, I thought that the function was used to ignore the rest of the current file and automatically fill it in with zeros. In fact, the for loop on L57 seems to indicate that this was the original purpose. However, the check on L51 prevents use of the method unless all file contents have been written already. Is the purpose of this method really just to flush out the final padding? If that's the case, why can't |
You're looking at some pretty ancient code. I wrote the original I managed to find an email from the code review where
In its original form it did indeed write out zeros to the end of the current file. It seems a little bogus now, but we can't drop it. The neutering on line 51 does indeed look silly. It was added in d75abb7 (early 2012), and @rsc noticed that it was silly after it was submitted (https://codereview.appspot.com/5777064). I can't remember why we didn't revise it back then. With the benefit of hindsight, I can't see the use case for writing the zeros automatically. The user of |
CL https://golang.org/cl/14723 mentions this issue. |
CL https://golang.org/cl/14823 mentions this issue. |
Sorry, I don't have time to review all these changes. I'll finish off the one I started, but you'll need to track down a different reviewer. |
Is there anyone you recommend for doing the reviews? |
@davecheney might be interested, or you can ask around on golang-dev. |
Convert splitUSTARPath to return a bool rather than an error since the caller never ever uses the error other than to check if it is nil. Thus, we can remove errNameTooLong as well. Also, fold the checking of the length <= fileNameSize and whether the string is ASCII into the split function itself. Lastly, remove logic to set the MAGIC since that's already done on L200. Thus, setting the magic is redundant. There is no overall logic change. Updates #12638 Change-Id: I26b6992578199abad723c2a2af7f4fc078af9c17 Reviewed-on: https://go-review.googlesource.com/14723 Reviewed-by: David Symonds <[email protected]> Run-TryBot: David Symonds <[email protected]>
@davecheney, would you be willing to do this? Otherwise, I will ask around. |
Please file separate, focused issues for bugs you find. One giant issue does not help anyone. It doesn't give a crisp statement of something to do, and it doesn't help when you see it in a CL description. |
I'm filing this issue as the "capture all" ticket for all currently known archive/tar issues. I've discovered quite a few issues and it's getting unwieldy filing an issue for them.
Over time, the tar library has become increasingly buggy, especially with the inclusion of support for PAX, GNU, and sparse files. There are many edge conditions where these various formats interact in unexpected ways leading to bugs. The fact that the fuzzer has detected a large of bugs in archive/tar goes to show its fragility. Also, most of the "fixes" done to resolve each issue were bandaids on a larger problem.
I have gone through the Reader implementation several times now and have read parts of the GNU, BSD, and STAR codebases to get a good understanding of how all the different utilities handle all the oddities when it comes to the TAR format.
Some of the major issues with the library are:
Example. Malicious tar files can cause arbitrary infinite loops. This occurs because the current data fragment is only popped when data has been read. However, if the reader experiences an io.EOF before the claimed end of the data fragment, then the EOF will be masked as nil and it will make no progress and readers will loop forever.Example. Malicious tar files can cause arbitrary panics. The position and offset and never verified to be non-negative. Thus, bytesLeft can be computed to be negative.Currently open tickets are:
The plan is to refactor the Reader code first to be as reliable as possible, and then to tackle various out-standing Writer issues.
I'll be filing no more archive/tar related issues after this. I promise :]
The text was updated successfully, but these errors were encountered: