@@ -115,9 +115,10 @@ public class ZipOutputStream : DeflaterOutputStream
115
115
long crcPatchPos = - 1 ;
116
116
long sizePatchPos = - 1 ;
117
117
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 ;
121
122
#endregion
122
123
123
124
#region Constructors
@@ -188,7 +189,7 @@ public int GetLevel()
188
189
/// <summary>
189
190
/// Get / set a value indicating how Zip64 Extension usage is determined when adding entries.
190
191
/// </summary>
191
- UseZip64 UseZip64
192
+ public UseZip64 UseZip64
192
193
{
193
194
get { return useZip64_ ; }
194
195
set { useZip64_ = value ; }
@@ -340,6 +341,7 @@ public void PutNextEntry(ZipEntry entry)
340
341
entry . CompressionMethod = ( CompressionMethod ) method ;
341
342
342
343
curMethod = method ;
344
+ sizePatchPos = - 1 ;
343
345
344
346
if ( ( useZip64_ == UseZip64 . On ) || ( ( entry . Size < 0 ) && ( useZip64_ == UseZip64 . Dynamic ) ) ) {
345
347
entry . ForceZip64 ( ) ;
@@ -375,7 +377,7 @@ public void PutNextEntry(ZipEntry entry)
375
377
}
376
378
377
379
// For local header both sizes appear in Zip64 Extended Information
378
- if ( entry . LocalHeaderRequiresZip64 ) {
380
+ if ( entry . LocalHeaderRequiresZip64 && patchEntryHeader ) {
379
381
WriteLeInt ( - 1 ) ;
380
382
WriteLeInt ( - 1 ) ;
381
383
}
@@ -393,7 +395,7 @@ public void PutNextEntry(ZipEntry entry)
393
395
394
396
ZipExtraData ed = new ZipExtraData ( entry . ExtraData ) ;
395
397
396
- if ( entry . LocalHeaderRequiresZip64 ) {
398
+ if ( entry . LocalHeaderRequiresZip64 && ( headerInfoAvailable || patchEntryHeader ) ) {
397
399
ed . StartNewEntry ( ) ;
398
400
if ( headerInfoAvailable ) {
399
401
ed . AddLeLong ( entry . Size ) ;
@@ -474,7 +476,7 @@ public void CloseEntry()
474
476
base . Finish ( ) ;
475
477
}
476
478
477
- long csize = curMethod == CompressionMethod . Deflated ? def . TotalOut : size ;
479
+ long csize = ( curMethod == CompressionMethod . Deflated ) ? def . TotalOut : size ;
478
480
479
481
if ( curEntry . Size < 0 ) {
480
482
curEntry . Size = size ;
@@ -509,6 +511,11 @@ public void CloseEntry()
509
511
WriteLeInt ( ( int ) curEntry . Crc ) ;
510
512
511
513
if ( curEntry . LocalHeaderRequiresZip64 ) {
514
+
515
+ if ( sizePatchPos == - 1 ) {
516
+ throw new ZipException ( "Entry requires zip64 but this has been turned off" ) ;
517
+ }
518
+
512
519
baseOutputStream . Seek ( sizePatchPos , SeekOrigin . Begin ) ;
513
520
WriteLeLong ( curEntry . Size ) ;
514
521
WriteLeLong ( curEntry . CompressedSize ) ;
0 commit comments