-
Notifications
You must be signed in to change notification settings - Fork 484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open branch, to fix multiple crashes on repeated zip archives reading… #200
Changes from 1 commit
f39d2bf
7b035be
e181fa8
031286c
2959b4d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,44 @@ | ||
| ||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 14 | ||
VisualStudioVersion = 14.0.24720.0 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{F18F1765-4A02-42FD-9BEF-F0E2FCBD9D17}" | ||
ProjectSection(SolutionItems) = preProject | ||
global.json = global.json | ||
EndProjectSection | ||
EndProject | ||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "SharpCompress", "src\SharpCompress\SharpCompress.xproj", "{FD19DDD8-72B2-4024-8665-0D1F7A2AA998}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{3C5BE746-03E5-4895-9988-0B57F162F86C}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{0F0901FF-E8D9-426A-B5A2-17C7F47C1529}" | ||
EndProject | ||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "SharpCompress.Test", "test\SharpCompress.Test\SharpCompress.Test.xproj", "{3B80E585-A2F3-4666-8F69-C7FFDA0DD7E5}" | ||
ProjectSection(ProjectDependencies) = postProject | ||
{FD19DDD8-72B2-4024-8665-0D1F7A2AA998} = {FD19DDD8-72B2-4024-8665-0D1F7A2AA998} | ||
EndProjectSection | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{FD19DDD8-72B2-4024-8665-0D1F7A2AA998}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{FD19DDD8-72B2-4024-8665-0D1F7A2AA998}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{FD19DDD8-72B2-4024-8665-0D1F7A2AA998}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{FD19DDD8-72B2-4024-8665-0D1F7A2AA998}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{3B80E585-A2F3-4666-8F69-C7FFDA0DD7E5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{3B80E585-A2F3-4666-8F69-C7FFDA0DD7E5}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{3B80E585-A2F3-4666-8F69-C7FFDA0DD7E5}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{3B80E585-A2F3-4666-8F69-C7FFDA0DD7E5}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(NestedProjects) = preSolution | ||
{FD19DDD8-72B2-4024-8665-0D1F7A2AA998} = {3C5BE746-03E5-4895-9988-0B57F162F86C} | ||
{3B80E585-A2F3-4666-8F69-C7FFDA0DD7E5} = {0F0901FF-E8D9-426A-B5A2-17C7F47C1529} | ||
EndGlobalSection | ||
EndGlobal | ||
| ||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 14 | ||
VisualStudioVersion = 14.0.24720.0 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{F18F1765-4A02-42FD-9BEF-F0E2FCBD9D17}" | ||
ProjectSection(SolutionItems) = preProject | ||
global.json = global.json | ||
EndProjectSection | ||
EndProject | ||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "SharpCompress", "src\SharpCompress\SharpCompress.xproj", "{FD19DDD8-72B2-4024-8665-0D1F7A2AA998}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{3C5BE746-03E5-4895-9988-0B57F162F86C}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{0F0901FF-E8D9-426A-B5A2-17C7F47C1529}" | ||
EndProject | ||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "SharpCompress.Test", "test\SharpCompress.Test\SharpCompress.Test.xproj", "{3B80E585-A2F3-4666-8F69-C7FFDA0DD7E5}" | ||
ProjectSection(ProjectDependencies) = postProject | ||
{FD19DDD8-72B2-4024-8665-0D1F7A2AA998} = {FD19DDD8-72B2-4024-8665-0D1F7A2AA998} | ||
EndProjectSection | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{FD19DDD8-72B2-4024-8665-0D1F7A2AA998}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{FD19DDD8-72B2-4024-8665-0D1F7A2AA998}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{FD19DDD8-72B2-4024-8665-0D1F7A2AA998}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{FD19DDD8-72B2-4024-8665-0D1F7A2AA998}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{3B80E585-A2F3-4666-8F69-C7FFDA0DD7E5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{3B80E585-A2F3-4666-8F69-C7FFDA0DD7E5}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{3B80E585-A2F3-4666-8F69-C7FFDA0DD7E5}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{3B80E585-A2F3-4666-8F69-C7FFDA0DD7E5}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(NestedProjects) = preSolution | ||
{FD19DDD8-72B2-4024-8665-0D1F7A2AA998} = {3C5BE746-03E5-4895-9988-0B57F162F86C} | ||
{3B80E585-A2F3-4666-8F69-C7FFDA0DD7E5} = {0F0901FF-E8D9-426A-B5A2-17C7F47C1529} | ||
EndGlobalSection | ||
EndGlobal |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,9 +65,28 @@ protected byte[] EncodeString(string str) | |
|
||
internal List<ExtraData> Extra { get; set; } | ||
|
||
internal PkwareTraditionalEncryptionData PkwareTraditionalEncryptionData { get; set; } | ||
//internal PkwareTraditionalEncryptionData PkwareTraditionalEncryptionData { get; set; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't leave commented out code, please. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
|
||
public string Password { get; set; } | ||
|
||
internal PkwareTraditionalEncryptionData ComposeEncryptionData(Stream archiveStream) | ||
{ | ||
if (archiveStream == null) | ||
{ | ||
throw new ArgumentNullException(nameof(archiveStream)); | ||
} | ||
|
||
var buffer = new byte[12]; | ||
archiveStream.Read(buffer, 0, 12); | ||
|
||
PkwareTraditionalEncryptionData encryptionData = PkwareTraditionalEncryptionData.ForRead(Password, this, buffer); | ||
//CompressedSize -= 12; | ||
|
||
return encryptionData; | ||
} | ||
|
||
#if !NO_CRYPTO | ||
internal WinzipAesEncryptionData WinzipAesEncryptionData { get; set; } | ||
internal WinzipAesEncryptionData WinzipAesEncryptionData { get; set; } | ||
#endif | ||
|
||
internal ushort LastModifiedDate { get; set; } | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,40 +124,46 @@ protected Stream CreateDecompressionStream(Stream stream) | |
} | ||
} | ||
|
||
protected Stream GetCryptoStream(Stream plainStream) | ||
{ | ||
if ((Header.CompressedSize == 0) | ||
#if !NO_CRYPTO | ||
&& ((Header.PkwareTraditionalEncryptionData != null) | ||
|| (Header.WinzipAesEncryptionData != null))) | ||
#else | ||
&& (Header.PkwareTraditionalEncryptionData != null)) | ||
#endif | ||
{ | ||
throw new NotSupportedException("Cannot encrypt file with unknown size at start."); | ||
} | ||
if ((Header.CompressedSize == 0) | ||
&& FlagUtility.HasFlag(Header.Flags, HeaderFlags.UsePostDataDescriptor)) | ||
{ | ||
plainStream = new NonDisposingStream(plainStream); //make sure AES doesn't close | ||
} | ||
else | ||
{ | ||
plainStream = new ReadOnlySubStream(plainStream, Header.CompressedSize); //make sure AES doesn't close | ||
} | ||
if (Header.PkwareTraditionalEncryptionData != null) | ||
{ | ||
return new PkwareTraditionalCryptoStream(plainStream, Header.PkwareTraditionalEncryptionData, | ||
CryptoMode.Decrypt); | ||
} | ||
protected Stream GetCryptoStream(Stream plainStream) | ||
{ | ||
if ((Header.CompressedSize == 0) && !string.IsNullOrEmpty(Header.Password)) | ||
{ | ||
throw new NotSupportedException("Cannot encrypt file with unknown size at start."); | ||
} | ||
|
||
if ((Header.CompressedSize == 0) | ||
&& FlagUtility.HasFlag(Header.Flags, HeaderFlags.UsePostDataDescriptor)) | ||
{ | ||
plainStream = new NonDisposingStream(plainStream); //make sure AES doesn't close | ||
} | ||
else | ||
{ | ||
plainStream = new ReadOnlySubStream(plainStream, Header.CompressedSize); //make sure AES doesn't close | ||
} | ||
|
||
if (FlagUtility.HasFlag(Header.Flags, HeaderFlags.Encrypted)) | ||
{ | ||
switch (Header.CompressionMethod) | ||
{ | ||
case ZipCompressionMethod.None: | ||
case ZipCompressionMethod.Deflate: | ||
case ZipCompressionMethod.Deflate64: | ||
case ZipCompressionMethod.BZip2: | ||
case ZipCompressionMethod.LZMA: | ||
case ZipCompressionMethod.PPMd: | ||
return new PkwareTraditionalCryptoStream(plainStream, Header.ComposeEncryptionData(plainStream), CryptoMode.Decrypt); | ||
|
||
case ZipCompressionMethod.WinzipAes: | ||
#if !NO_FILE | ||
if (Header.WinzipAesEncryptionData != null) | ||
{ | ||
//only read 10 less because the last ten are auth bytes | ||
return new WinzipAesCryptoStream(plainStream, Header.WinzipAesEncryptionData, Header.CompressedSize - 10); | ||
} | ||
return Header.WinzipAesEncryptionData != null ? new WinzipAesCryptoStream(plainStream, Header.WinzipAesEncryptionData, Header.CompressedSize - 10) : plainStream; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do this? I hate the tertiary operator. It's not readable on a single line here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
#endif | ||
return plainStream; | ||
} | ||
} | ||
|
||
default: | ||
throw new ArgumentOutOfRangeException(); | ||
} | ||
} | ||
|
||
return plainStream; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,81 +107,74 @@ internal static bool IsHeader(uint headerBytes) | |
} | ||
} | ||
|
||
private void LoadHeader(ZipFileEntry entryHeader, Stream stream) | ||
{ | ||
if (FlagUtility.HasFlag(entryHeader.Flags, HeaderFlags.Encrypted)) | ||
{ | ||
if (!entryHeader.IsDirectory && | ||
entryHeader.CompressedSize == 0 && | ||
FlagUtility.HasFlag(entryHeader.Flags, HeaderFlags.UsePostDataDescriptor)) | ||
{ | ||
throw new NotSupportedException( | ||
"SharpCompress cannot currently read non-seekable Zip Streams with encrypted data that has been written in a non-seekable manner."); | ||
} | ||
if (password == null) | ||
{ | ||
throw new CryptographicException("No password supplied for encrypted zip."); | ||
} | ||
if (entryHeader.CompressionMethod != ZipCompressionMethod.WinzipAes) | ||
{ | ||
byte[] buffer = new byte[12]; | ||
stream.Read(buffer, 0, 12); | ||
entryHeader.PkwareTraditionalEncryptionData = PkwareTraditionalEncryptionData.ForRead(password, | ||
entryHeader, | ||
buffer); | ||
entryHeader.CompressedSize -= 12; | ||
} | ||
else | ||
{ | ||
private void LoadHeader(ZipFileEntry entryHeader, Stream stream) | ||
{ | ||
if (FlagUtility.HasFlag(entryHeader.Flags, HeaderFlags.Encrypted)) | ||
{ | ||
if (!entryHeader.IsDirectory && entryHeader.CompressedSize == 0 && | ||
FlagUtility.HasFlag(entryHeader.Flags, HeaderFlags.UsePostDataDescriptor)) | ||
{ | ||
throw new NotSupportedException("SharpCompress cannot currently read non-seekable Zip Streams with encrypted data that has been written in a non-seekable manner."); | ||
} | ||
|
||
if (password == null) | ||
{ | ||
throw new CryptographicException("No password supplied for encrypted zip."); | ||
} | ||
|
||
entryHeader.Password = password; | ||
|
||
if (entryHeader.CompressionMethod == ZipCompressionMethod.WinzipAes) | ||
{ | ||
#if NO_CRYPTO | ||
throw new NotSupportedException("Cannot decrypt Winzip AES with Silverlight or WP7."); | ||
#else | ||
|
||
var data = entryHeader.Extra.SingleOrDefault(x => x.Type == ExtraDataType.WinZipAes); | ||
WinzipAesKeySize keySize = (WinzipAesKeySize) data.DataBytes[4]; | ||
ExtraData data = entryHeader.Extra.SingleOrDefault(x => x.Type == ExtraDataType.WinZipAes); | ||
if (data != null) | ||
{ | ||
var keySize = (WinzipAesKeySize)data.DataBytes[4]; | ||
|
||
byte[] salt = new byte[WinzipAesEncryptionData.KeyLengthInBytes(keySize)/2]; | ||
byte[] passwordVerifyValue = new byte[2]; | ||
stream.Read(salt, 0, salt.Length); | ||
stream.Read(passwordVerifyValue, 0, 2); | ||
entryHeader.WinzipAesEncryptionData = new WinzipAesEncryptionData(keySize, salt, passwordVerifyValue, | ||
password); | ||
entryHeader.CompressedSize -= (uint) (salt.Length + 2); | ||
var salt = new byte[WinzipAesEncryptionData.KeyLengthInBytes(keySize) / 2]; | ||
var passwordVerifyValue = new byte[2]; | ||
stream.Read(salt, 0, salt.Length); | ||
stream.Read(passwordVerifyValue, 0, 2); | ||
entryHeader.WinzipAesEncryptionData = | ||
new WinzipAesEncryptionData(keySize, salt, passwordVerifyValue, password); | ||
|
||
entryHeader.CompressedSize -= (uint)(salt.Length + 2); | ||
} | ||
#endif | ||
} | ||
} | ||
if (entryHeader.IsDirectory) | ||
{ | ||
return; | ||
} | ||
} | ||
} | ||
|
||
//if (FlagUtility.HasFlag(entryHeader.Flags, HeaderFlags.UsePostDataDescriptor)) | ||
//{ | ||
// entryHeader.PackedStream = new ReadOnlySubStream(stream); | ||
//} | ||
//else | ||
//{ | ||
switch (mode) | ||
{ | ||
case StreamingMode.Seekable: | ||
{ | ||
entryHeader.DataStartPosition = stream.Position; | ||
stream.Position += entryHeader.CompressedSize; | ||
} | ||
break; | ||
case StreamingMode.Streaming: | ||
{ | ||
entryHeader.PackedStream = stream; | ||
} | ||
break; | ||
default: | ||
{ | ||
throw new InvalidFormatException("Invalid StreamingMode"); | ||
} | ||
} | ||
if (entryHeader.IsDirectory) | ||
{ | ||
return; | ||
} | ||
|
||
//} | ||
} | ||
} | ||
//if (FlagUtility.HasFlag(entryHeader.Flags, HeaderFlags.UsePostDataDescriptor)) | ||
//{ | ||
// entryHeader.PackedStream = new ReadOnlySubStream(stream); | ||
//} | ||
//else | ||
//{ | ||
switch (mode) | ||
{ | ||
case StreamingMode.Seekable: | ||
entryHeader.DataStartPosition = stream.Position; | ||
stream.Position += entryHeader.CompressedSize; | ||
break; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't remove braces please. They're there for a reason. |
||
case StreamingMode.Streaming: | ||
entryHeader.PackedStream = stream; | ||
break; | ||
|
||
default: | ||
throw new InvalidFormatException("Invalid StreamingMode"); | ||
} | ||
|
||
//} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line endings changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please clarify, what newline character do you use?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it's still left over from before I tried to normalize endings but I have gitattributes set to auto.
Question is: why is this file changing at all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The solution file was regenerated by Visual Studio. I don't see any real changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So revert it then please. Whitespace changes make a lot of noise for reviewing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry i can't revert this file because my Git didn't see any changes.