Skip to content

Commit

Permalink
Slightly better fix for #235
Browse files Browse the repository at this point in the history
  • Loading branch information
adamhathcock committed May 23, 2017
1 parent 7b81d18 commit 9d9d491
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 17 deletions.
10 changes: 1 addition & 9 deletions src/SharpCompress/Archives/Zip/ZipArchiveEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,7 @@ internal ZipArchiveEntry(ZipArchive archive, SeekableZipFilePart part)

public virtual Stream OpenEntryStream()
{
var filePart = Parts.Single() as ZipFilePart;
var compressionMethod = filePart.Header.CompressionMethod;
var stream = filePart.GetCompressedStream();
if (filePart.Header.CompressionMethod != compressionMethod)
{
filePart.Header.CompressionMethod = compressionMethod;
}

return stream;
return Parts.Single().GetCompressedStream();
}

#region IArchiveEntry Members
Expand Down
2 changes: 1 addition & 1 deletion src/SharpCompress/Common/Zip/StreamingZipFilePart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal override Stream GetCompressedStream()
{
return Stream.Null;
}
decompressionStream = CreateDecompressionStream(GetCryptoStream(CreateBaseStream()));
decompressionStream = CreateDecompressionStream(GetCryptoStream(CreateBaseStream()), Header.CompressionMethod);
if (LeaveStreamOpen)
{
return new NonDisposingStream(decompressionStream);
Expand Down
13 changes: 6 additions & 7 deletions src/SharpCompress/Common/Zip/ZipFilePart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ internal override Stream GetCompressedStream()
{
return Stream.Null;
}
Stream decompressionStream = CreateDecompressionStream(GetCryptoStream(CreateBaseStream()));
Stream decompressionStream = CreateDecompressionStream(GetCryptoStream(CreateBaseStream()), Header.CompressionMethod);
if (LeaveStreamOpen)
{
return new NonDisposingStream(decompressionStream);
Expand All @@ -53,9 +53,9 @@ internal override Stream GetRawStream()

protected bool LeaveStreamOpen => FlagUtility.HasFlag(Header.Flags, HeaderFlags.UsePostDataDescriptor) || Header.IsZip64;

protected Stream CreateDecompressionStream(Stream stream)
protected Stream CreateDecompressionStream(Stream stream, ZipCompressionMethod method)
{
switch (Header.CompressionMethod)
switch (method)
{
case ZipCompressionMethod.None:
{
Expand Down Expand Up @@ -102,9 +102,9 @@ protected Stream CreateDecompressionStream(Stream stream)
{
throw new InvalidFormatException("Winzip data length is not 7.");
}
ushort method = DataConverter.LittleEndian.GetUInt16(data.DataBytes, 0);
ushort compressedMethod = DataConverter.LittleEndian.GetUInt16(data.DataBytes, 0);

if (method != 0x01 && method != 0x02)
if (compressedMethod != 0x01 && compressedMethod != 0x02)
{
throw new InvalidFormatException("Unexpected vendor version number for WinZip AES metadata");
}
Expand All @@ -114,8 +114,7 @@ protected Stream CreateDecompressionStream(Stream stream)
{
throw new InvalidFormatException("Unexpected vendor ID for WinZip AES metadata");
}
Header.CompressionMethod = (ZipCompressionMethod)DataConverter.LittleEndian.GetUInt16(data.DataBytes, 5);
return CreateDecompressionStream(stream);
return CreateDecompressionStream(stream, (ZipCompressionMethod)DataConverter.LittleEndian.GetUInt16(data.DataBytes, 5));
}
default:
{
Expand Down

0 comments on commit 9d9d491

Please sign in to comment.