ExtractZip extracts the contents of a zip archive to destDir. Entries that would escape destDir lexically are skipped.
(zr *zip.Reader, destDir *safepaths.Root)
| 19 | // ExtractZip extracts the contents of a zip archive to destDir. |
| 20 | // Entries that would escape destDir lexically are skipped. |
| 21 | func ExtractZip(zr *zip.Reader, destDir *safepaths.Root) error { |
| 22 | for _, zf := range zr.File { |
| 23 | if err := extractZipFile(zf, destDir); err != nil { |
| 24 | if _, ok := errors.AsType[safepaths.PathTraversalError](err); ok { |
| 25 | continue |
| 26 | } |
| 27 | return fmt.Errorf("error extracting %q: %w", zf.Name, err) |
| 28 | } |
| 29 | } |
| 30 | return nil |
| 31 | } |
| 32 | |
| 33 | func extractZipFile(zf *zip.File, dest *safepaths.Root) (extractErr error) { |
| 34 | zm := zf.Mode() |