From b9792ca491e900ec3f90b0e9f2fa3a79f7d74f35 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Wed, 7 Jan 2026 14:54:32 +0000 Subject: [PATCH] fix async zip decompression --- src/SharpCompress/Common/Zip/ZipFilePart.cs | 26 ++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/SharpCompress/Common/Zip/ZipFilePart.cs b/src/SharpCompress/Common/Zip/ZipFilePart.cs index ca3881ae..b800d77c 100644 --- a/src/SharpCompress/Common/Zip/ZipFilePart.cs +++ b/src/SharpCompress/Common/Zip/ZipFilePart.cs @@ -470,11 +470,35 @@ internal abstract class ZipFilePart : FilePart { throw new InvalidFormatException("No Winzip AES extra data found."); } + if (data.Length != 7) { throw new InvalidFormatException("Winzip data length is not 7."); } - throw new NotSupportedException("WinzipAes isn't supported for streaming"); + + var compressedMethod = BinaryPrimitives.ReadUInt16LittleEndian(data.DataBytes); + + if (compressedMethod != 0x01 && compressedMethod != 0x02) + { + throw new InvalidFormatException( + "Unexpected vendor version number for WinZip AES metadata" + ); + } + + var vendorId = BinaryPrimitives.ReadUInt16LittleEndian(data.DataBytes.AsSpan(2)); + if (vendorId != 0x4541) + { + throw new InvalidFormatException( + "Unexpected vendor ID for WinZip AES metadata" + ); + } + + return await CreateDecompressionStreamAsync( + stream, + (ZipCompressionMethod) + BinaryPrimitives.ReadUInt16LittleEndian(data.DataBytes.AsSpan(5)), + cancellationToken + ); } default: {