Skip to content

Conversation

dansimau
Copy link
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
Copy link

@shivamdixit shivamdixit left a comment

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.

@jcorbin
Copy link

jcorbin commented Sep 17, 2019

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