Skip to content
This repository has been archived by the owner on Nov 19, 2024. It is now read-only.

Commit

Permalink
zip: fix File.Open not working if called after zip.Extract completes (#…
Browse files Browse the repository at this point in the history
…367)

The zip.Extract method creates a closure for the File.Open function
pointer sent to the handler method.

Unfortunately it uses the same File for each call to the handler
function which means that if the caller stores the File objects and
uses them after Extract has returned then each File.Open function
pointer will open the same object.

This is easily fixed by making sure that each iteration of the Extract
loop uses a new File variable.
  • Loading branch information
ncw authored Feb 1, 2023
1 parent f1ef6eb commit 10a6421
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions zip.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ func (z Zip) Extract(ctx context.Context, sourceArchive io.Reader, pathsInArchiv
skipDirs := skipList{}

for i, f := range zr.File {
f := f // make a copy for the Open closure
if err := ctx.Err(); err != nil {
return err // honor context cancellation
}
Expand Down

0 comments on commit 10a6421

Please sign in to comment.