-
Notifications
You must be signed in to change notification settings - Fork 257
Remove failed decompressed files #564
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
base: main
Are you sure you want to change the base?
Conversation
When untarring a tarball, attempt to create files initially with the umask file permissions and delete the file if it fails to copy correctly. This prevents a paritally written file from remaining on disk with permissions that didn't include the umask. Adds a unit test and a invalid tarball (created by truncating a large file generated from /dev/urandom), which fails to decompress but errors partially written.
dbd8903 to
d1113d8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks for the PR 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm
|
Looks like the Windows unit test in the CI are not happy with the We should consider adding a case |
c0ef527
|
@CreatorHead @dduzgun-security I was able to get the tests to pass on windows by explicitly closing the file (whoops!). I'd like to avoid splitting the tests since we expect the same behavior regardless of the underlying OS. Ready for another look! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Minor comments about duplicate close calls to the file handler.
| _, err = io.Copy(dstF, src) | ||
| if err != nil { | ||
| // Close & remove the file in case of partial write | ||
| _ = dstF.Close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already call close in a deferred function on line 42, so do we need this? In any case, having a second call won't cause any errors as we are throwing away the returned error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The windows test case would fail here because the file was reported as being in use at the time of removal. Adding in the explicit file closed fixed it and allowed the file to be removed, so it seems like windows has a different requirement/handling that needs the file to be explicitly closed before removing it. I figured it's better to close the file an extra time as opposed to trying to check.
| count, err := Copy(ctx, dstF, srcF) | ||
| if err != nil { | ||
| // Close & remove the file in case of partial write | ||
| _ = dstF.Close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already call close in a deferred function on line 84, so do we need this? In any case, having a second call won't cause any errors as we are throwing away the returned error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same reasoning as above, keeping the way these are handled in sync.
|
@CreatorHead Can you |
When untarring a tarball, attempt to create files initially with the
umask file permissions and delete the file if it fails to copy
correctly. This prevents a partially written file from remaining on disk
with permissions that didn't include the umask.
Adds a unit test and a invalid tarball (created by truncating tarball containing a large
file generated from /dev/urandom), which fails to decompress but errors
partially written.
PCI review checklist
I have documented a clear reason for, and description of, the change I am making.
If applicable, I've documented a plan to revert these changes if they require more than reverting the pull request.
If applicable, I've documented the impact of any changes to security controls.
Examples of changes to security controls include using new access control methods, adding or removing logging pipelines, etc.