Skip to content

Fix zip slip vulnerability - #47

Merged
dansimau merged 1 commit into
masterfrom
fix-zip-slip
Oct 2, 2019
Merged

dansimau merged 1 commit into
masterfrom
fix-zip-slip

Conversation

@dansimau

Copy link
Copy Markdown
Contributor

This fixes an issue where files within a zip file can break out of the target directory when being extracted.

Fixes #46.

@dansimau dansimau self-assigned this Sep 10, 2019

@shivamdixit shivamdixit left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM! Left a couple of small comments.

Comment thread astro/tvm/utils.go Resolved
@jcorbin

jcorbin commented Sep 17, 2019 •

Copy link
Copy Markdown

Fwiw, I have a need to implement similar zip extraction, here's the code I ended up with: https://gist.github.com/jcorbin/fd0716bd0bc4c49cd22d73e4aad23b38

  • extracts in GOMAXPROCS-parallel
  • slightly better reliability / error flow in the file extraction path
  • slightly better file permission restoration
  • more efficient for large archives, since it uses io.CopyBuffer internally with a re-used buffer, rather than io.Copy dynamically allocated a 32KB buffer for every extracted file (causing GC pressure scaling with size of archive)
  • oh and it supports context cancellation, in case that matters (e.g. timing out a large archive extraction, or otherwise)...
  • ...around this code, I'm running the extraction into a sibling temporary directory, and then either os.Rename-ing into place when done, or os.RemoveAll-ing it in case of (e.g. cancellation) error (similar to github.com/google/reanmio.PendingFile, but for directories

@dansimau
dansimau merged commit 2aec9b3 into master Oct 2, 2019
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.

Potential

3 participants