From 62917824fadb438753babf81706e212f66dd4fc7 Mon Sep 17 00:00:00 2001 From: David Leadbeater Date: Tue, 9 Dec 2025 06:16:30 +0100 Subject: [PATCH] Support zstd inside zip files. Given this is already depending on zstd I don't see a reason not to. Can be tested with libarchive via: `bsdtar -a --options zip:compression=zstd -cf file.zip files...` Reviewed-on: https://codeberg.org/git-pages/git-pages/pulls/91 Co-authored-by: David Leadbeater Co-committed-by: David Leadbeater --- src/extract.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/extract.go b/src/extract.go index 1326cd2..d404578 100644 --- a/src/extract.go +++ b/src/extract.go @@ -153,6 +153,9 @@ func ExtractTar(ctx context.Context, reader io.Reader, oldManifest *Manifest) (* return manifest, nil } +// Used for zstd decompression inside zip files, it is recommended to share this. +var zstdDecomp = zstd.ZipDecompressor() + func ExtractZip(ctx context.Context, reader io.Reader, oldManifest *Manifest) (*Manifest, error) { data, err := io.ReadAll(reader) if err != nil { @@ -164,6 +167,10 @@ func ExtractZip(ctx context.Context, reader io.Reader, oldManifest *Manifest) (* return nil, err } + // Support zstd compression inside zip files. + archive.RegisterDecompressor(zstd.ZipMethodWinZip, zstdDecomp) + archive.RegisterDecompressor(zstd.ZipMethodPKWare, zstdDecomp) + // Detect and defuse zipbombs. var totalSize uint64 for _, file := range archive.File {