From b575a96a8e0d001c27dfa2af8a30db63ea56d110 Mon Sep 17 00:00:00 2001 From: "Steve G. Bjorg" Date: Sun, 17 Feb 2019 17:26:53 -0800 Subject: [PATCH 1/3] respect the VersionMadeBy property of ZipEntry --- src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs | 6 +++--- src/ICSharpCode.SharpZipLib/Zip/ZipOutputStream.cs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs b/src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs index 0db9cc7f0..48a8084d1 100644 --- a/src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs +++ b/src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs @@ -428,7 +428,7 @@ public ZipFile(string name) public ZipFile(FileStream file) : this(file, false) { - + } /// @@ -489,7 +489,7 @@ public ZipFile(FileStream file, bool leaveOpen) public ZipFile(Stream stream) : this(stream, false) { - + } /// @@ -2157,7 +2157,7 @@ private int WriteCentralDirectoryHeader(ZipEntry entry) WriteLEInt(ZipConstants.CentralHeaderSignature); // Version made by - WriteLEShort(ZipConstants.VersionMadeBy); + WriteLEShort(entry.VersionMadeBy); // Version required to extract WriteLEShort(entry.Version); diff --git a/src/ICSharpCode.SharpZipLib/Zip/ZipOutputStream.cs b/src/ICSharpCode.SharpZipLib/Zip/ZipOutputStream.cs index 88c810393..0228dca71 100644 --- a/src/ICSharpCode.SharpZipLib/Zip/ZipOutputStream.cs +++ b/src/ICSharpCode.SharpZipLib/Zip/ZipOutputStream.cs @@ -744,7 +744,7 @@ public override void Finish() foreach (ZipEntry entry in entries) { WriteLeInt(ZipConstants.CentralHeaderSignature); - WriteLeShort(ZipConstants.VersionMadeBy); + WriteLeShort(entry.VersionMadeBy); WriteLeShort(entry.Version); WriteLeShort(entry.Flags); WriteLeShort((short)entry.CompressionMethodForHeader); From 0482654f90e7c0bdd29f03192094a07611cc1474 Mon Sep 17 00:00:00 2001 From: "Steve G. Bjorg" Date: Sun, 17 Feb 2019 17:28:07 -0800 Subject: [PATCH 2/3] makde all constructor public so that VersionMadeBy can be set at creation time; don't mask VersionMadeBy --- src/ICSharpCode.SharpZipLib/Zip/ZipEntry.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ICSharpCode.SharpZipLib/Zip/ZipEntry.cs b/src/ICSharpCode.SharpZipLib/Zip/ZipEntry.cs index 572108f0f..9bdb70378 100644 --- a/src/ICSharpCode.SharpZipLib/Zip/ZipEntry.cs +++ b/src/ICSharpCode.SharpZipLib/Zip/ZipEntry.cs @@ -169,7 +169,7 @@ public ZipEntry(string name) /// /// The name passed is null /// - internal ZipEntry(string name, int versionRequiredToExtract) + public ZipEntry(string name, int versionRequiredToExtract) : this(name, versionRequiredToExtract, ZipConstants.VersionMadeBy, CompressionMethod.Deflated) { @@ -192,7 +192,7 @@ internal ZipEntry(string name, int versionRequiredToExtract) /// This constructor is used by the ZipFile class when reading from the central header /// It is not generally useful, use the constructor specifying the name only. /// - internal ZipEntry(string name, int versionRequiredToExtract, int madeByInfo, + public ZipEntry(string name, int versionRequiredToExtract, int madeByInfo, CompressionMethod method) { if (name == null) @@ -444,7 +444,7 @@ public int VersionMadeBy { get { - return (versionMadeBy & 0xff); + return versionMadeBy; } } @@ -526,7 +526,7 @@ public int HostSystem set { - versionMadeBy &= 0xff; + versionMadeBy &= 0xff00; versionMadeBy |= (ushort)((value & 0xff) << 8); } } From a6766fb20e157904ea7f4eb3ca18504910065aeb Mon Sep 17 00:00:00 2001 From: "Steve G. Bjorg" Date: Wed, 22 May 2019 10:41:50 -0700 Subject: [PATCH 3/3] simplified the HostSystem fix --- src/ICSharpCode.SharpZipLib/Zip/ZipEntry.cs | 8 ++++---- src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs | 2 +- src/ICSharpCode.SharpZipLib/Zip/ZipOutputStream.cs | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ICSharpCode.SharpZipLib/Zip/ZipEntry.cs b/src/ICSharpCode.SharpZipLib/Zip/ZipEntry.cs index 9bdb70378..6986c7ec3 100644 --- a/src/ICSharpCode.SharpZipLib/Zip/ZipEntry.cs +++ b/src/ICSharpCode.SharpZipLib/Zip/ZipEntry.cs @@ -169,7 +169,7 @@ public ZipEntry(string name) /// /// The name passed is null /// - public ZipEntry(string name, int versionRequiredToExtract) + internal ZipEntry(string name, int versionRequiredToExtract) : this(name, versionRequiredToExtract, ZipConstants.VersionMadeBy, CompressionMethod.Deflated) { @@ -192,7 +192,7 @@ public ZipEntry(string name, int versionRequiredToExtract) /// This constructor is used by the ZipFile class when reading from the central header /// It is not generally useful, use the constructor specifying the name only. /// - public ZipEntry(string name, int versionRequiredToExtract, int madeByInfo, + internal ZipEntry(string name, int versionRequiredToExtract, int madeByInfo, CompressionMethod method) { if (name == null) @@ -444,7 +444,7 @@ public int VersionMadeBy { get { - return versionMadeBy; + return (versionMadeBy & 0xff); } } @@ -526,7 +526,7 @@ public int HostSystem set { - versionMadeBy &= 0xff00; + versionMadeBy &= 0x00ff; versionMadeBy |= (ushort)((value & 0xff) << 8); } } diff --git a/src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs b/src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs index 48a8084d1..e82c6ce2f 100644 --- a/src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs +++ b/src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs @@ -2157,7 +2157,7 @@ private int WriteCentralDirectoryHeader(ZipEntry entry) WriteLEInt(ZipConstants.CentralHeaderSignature); // Version made by - WriteLEShort(entry.VersionMadeBy); + WriteLEShort((entry.HostSystem << 8) | entry.VersionMadeBy); // Version required to extract WriteLEShort(entry.Version); diff --git a/src/ICSharpCode.SharpZipLib/Zip/ZipOutputStream.cs b/src/ICSharpCode.SharpZipLib/Zip/ZipOutputStream.cs index 10f177c45..c3dd31af2 100644 --- a/src/ICSharpCode.SharpZipLib/Zip/ZipOutputStream.cs +++ b/src/ICSharpCode.SharpZipLib/Zip/ZipOutputStream.cs @@ -750,7 +750,7 @@ public override void Finish() foreach (ZipEntry entry in entries) { WriteLeInt(ZipConstants.CentralHeaderSignature); - WriteLeShort(entry.VersionMadeBy); + WriteLeShort((entry.HostSystem << 8) | entry.VersionMadeBy); WriteLeShort(entry.Version); WriteLeShort(entry.Flags); WriteLeShort((short)entry.CompressionMethodForHeader);