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 <dgl@dgl.cx>
Co-committed-by: David Leadbeater <dgl@dgl.cx>
This commit is contained in:
David Leadbeater
2025-12-09 06:16:30 +01:00
committed by Catherine
parent 62ef4a5366
commit 62917824fa

View File

@@ -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 {