Skip to content

Commit 090fee6

Browse files
committed
Zip64 fixes for ZipOutputStream. UseZip64 property now public in ZipOutputStream.cs Tests updated.
1 parent 886d477 commit 090fee6

File tree

12 files changed

+200
-337
lines changed

12 files changed

+200
-337
lines changed

samples/cs/CreateZipFile/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
[assembly: AssemblyTrademark("")]
1111
[assembly: AssemblyCulture("")]
1212

13-
[assembly: AssemblyVersion("0.85.2.324")]
13+
[assembly: AssemblyVersion("0.85.2.329")]
1414

1515
[assembly: AssemblyDelaySign(false)]
1616
[assembly: AssemblyKeyFile("")]

samples/cs/FastZip/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
// You can specify all values by your own or you can build default build and revision
2424
// numbers with the '*' character (the default):
2525

26-
[assembly: AssemblyVersion("0.85.2.324")]
26+
[assembly: AssemblyVersion("0.85.2.329")]
2727

2828
// The following attributes specify the key for the sign of your assembly. See the
2929
// .NET Framework documentation for more information about signing.

samples/cs/minibzip2/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
[assembly: AssemblyTrademark("")]
1111
[assembly: AssemblyCulture("")]
1212

13-
[assembly: AssemblyVersion("0.85.2.324")]
13+
[assembly: AssemblyVersion("0.85.2.329")]
1414

1515
[assembly: AssemblyDelaySign(false)]
1616
[assembly: AssemblyKeyFile("")]

samples/cs/minigzip/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
[assembly: AssemblyTrademark("")]
1111
[assembly: AssemblyCulture("")]
1212

13-
[assembly: AssemblyVersion("0.85.2.324")]
13+
[assembly: AssemblyVersion("0.85.2.329")]
1414

1515
[assembly: AssemblyDelaySign(false)]
1616
[assembly: AssemblyKeyFile("")]

samples/cs/sz/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
// You can specify all values by your own or you can build default build and revision
2424
// numbers with the '*' character (the default):
2525

26-
[assembly: AssemblyVersion("0.85.2.324")]
26+
[assembly: AssemblyVersion("0.85.2.329")]
2727

2828
// The following attributes specify the key for the sign of your assembly. See the
2929
// .NET Framework documentation for more information about signing.

samples/cs/tar/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
// You can specify all values by your own or you can build default build and revision
2424
// numbers with the '*' character (the default):
2525

26-
[assembly: AssemblyVersion("0.85.2.324")]
26+
[assembly: AssemblyVersion("0.85.2.329")]
2727

2828
// The following attributes specify the key for the sign of your assembly. See the
2929
// .NET Framework documentation for more information about signing.

samples/cs/zf/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
// You can specify all the values or you can default the Revision and Build Numbers
2727
// by using the '*' as shown below:
2828

29-
[assembly: AssemblyVersion("0.85.2.324")]
29+
[assembly: AssemblyVersion("0.85.2.329")]
3030

3131
//
3232
// In order to sign your assembly you must specify a key to use. Refer to the

src/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
[assembly: AssemblyCopyright("Copyright 2001-2007 Mike Krueger, John Reilly")]
7474
[assembly: AssemblyTrademark("Copyright 2001-2007 Mike Krueger, John Reilly")]
7575

76-
[assembly: AssemblyVersion("0.85.2.324")]
76+
[assembly: AssemblyVersion("0.85.2.329")]
7777
[assembly: AssemblyInformationalVersionAttribute("0.85.2")]
7878

7979

src/Zip/ZipFile.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,6 +1105,7 @@ long TestLocalHeader(ZipEntry entry, HeaderTest tests)
11051105
}
11061106

11071107
// Crc valid for empty entry.
1108+
// This will also apply to streamed entries where size isnt known and the header cant be patched
11081109
if ( (size == 0) && (compressedSize == 0) ) {
11091110
if ( crcValue != 0 ) {
11101111
throw new ZipException("Invalid CRC for empty entry");

src/Zip/ZipOutputStream.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,10 @@ public class ZipOutputStream : DeflaterOutputStream
115115
long crcPatchPos = -1;
116116
long sizePatchPos = -1;
117117

118-
// Default of off is backwards compatible and doesnt dump on
119-
// XP's built in compression which cnat handle it
120-
UseZip64 useZip64_ = UseZip64.Off;
118+
// Default is dynamic which is not backwards compatible and can cause problems
119+
// with XP's built in compression which cant read Zip64 archives.
120+
// However it does avoid the situation were a large file is added and cannot be completed correctly.
121+
UseZip64 useZip64_ = UseZip64.Dynamic;
121122
#endregion
122123

123124
#region Constructors
@@ -188,7 +189,7 @@ public int GetLevel()
188189
/// <summary>
189190
/// Get / set a value indicating how Zip64 Extension usage is determined when adding entries.
190191
/// </summary>
191-
UseZip64 UseZip64
192+
public UseZip64 UseZip64
192193
{
193194
get { return useZip64_; }
194195
set { useZip64_ = value; }
@@ -340,6 +341,7 @@ public void PutNextEntry(ZipEntry entry)
340341
entry.CompressionMethod = (CompressionMethod)method;
341342

342343
curMethod = method;
344+
sizePatchPos = -1;
343345

344346
if ( (useZip64_ == UseZip64.On) || ((entry.Size < 0) && (useZip64_ == UseZip64.Dynamic)) ) {
345347
entry.ForceZip64();
@@ -375,7 +377,7 @@ public void PutNextEntry(ZipEntry entry)
375377
}
376378

377379
// For local header both sizes appear in Zip64 Extended Information
378-
if ( entry.LocalHeaderRequiresZip64 ) {
380+
if ( entry.LocalHeaderRequiresZip64 && patchEntryHeader ) {
379381
WriteLeInt(-1);
380382
WriteLeInt(-1);
381383
}
@@ -393,7 +395,7 @@ public void PutNextEntry(ZipEntry entry)
393395

394396
ZipExtraData ed = new ZipExtraData(entry.ExtraData);
395397

396-
if ( entry.LocalHeaderRequiresZip64 ) {
398+
if (entry.LocalHeaderRequiresZip64 && (headerInfoAvailable || patchEntryHeader)) {
397399
ed.StartNewEntry();
398400
if (headerInfoAvailable) {
399401
ed.AddLeLong(entry.Size);
@@ -474,7 +476,7 @@ public void CloseEntry()
474476
base.Finish();
475477
}
476478

477-
long csize = curMethod == CompressionMethod.Deflated ? def.TotalOut : size;
479+
long csize = (curMethod == CompressionMethod.Deflated) ? def.TotalOut : size;
478480

479481
if (curEntry.Size < 0) {
480482
curEntry.Size = size;
@@ -509,6 +511,11 @@ public void CloseEntry()
509511
WriteLeInt((int)curEntry.Crc);
510512

511513
if ( curEntry.LocalHeaderRequiresZip64 ) {
514+
515+
if ( sizePatchPos == -1 ) {
516+
throw new ZipException("Entry requires zip64 but this has been turned off");
517+
}
518+
512519
baseOutputStream.Seek(sizePatchPos, SeekOrigin.Begin);
513520
WriteLeLong(curEntry.Size);
514521
WriteLeLong(curEntry.CompressedSize);

0 commit comments

Comments
 (0)