Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3408,6 +3408,7 @@ private void ReadEntries()
}

bool isZip64 = false;
bool requireZip64 = false;

// Check if zip64 header information is required.
if ((thisDiskNumber == 0xffff) ||
Expand All @@ -3417,13 +3418,22 @@ private void ReadEntries()
(centralDirSize == 0xffffffff) ||
(offsetOfCentralDir == 0xffffffff))
{
isZip64 = true;
requireZip64 = true;
}

long offset = LocateBlockWithSignature(ZipConstants.Zip64CentralDirLocatorSignature, locatedEndOfCentralDir, 0, 0x1000);
if (offset < 0)
// #357 - always check for the existance of the Zip64 central directory.
long locatedZip64EndOfCentralDir = LocateBlockWithSignature(ZipConstants.Zip64CentralDirLocatorSignature, locatedEndOfCentralDir, 0, 0x1000);
if (locatedZip64EndOfCentralDir < 0)
{
if (requireZip64)
{
// This is only an error in cases where the Zip64 directory is required.
throw new ZipException("Cannot find Zip64 locator");
}
}
else
{
isZip64 = true;

// number of the disk with the start of the zip64 end of central directory 4 bytes
// relative offset of the zip64 end of central directory record 8 bytes
Expand Down
24 changes: 19 additions & 5 deletions test/ICSharpCode.SharpZipLib.Tests/Zip/ZipCorruptionHandling.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using ICSharpCode.SharpZipLib;
using ICSharpCode.SharpZipLib.Zip;
using NUnit.Framework;

namespace ICSharpCode.SharpZipLib.Tests.Zip
{
public class ZipCorruptionHandling
public class ZipCorruptionHandling
{

const string TestFileZeroCodeLength = "UEsDBBQA+AAIANwyZ0U5T8HwjQAAAL8AAAAIABUAbGltZXJpY2t" +
Expand Down Expand Up @@ -52,6 +49,23 @@ public void ZeroCodeLengthZipFile()
});
}

}
const string TestFileBadCDGoodCD64 = @"UEsDBC0AAAAIANhy+k4cj+r8//////////8IABQAdGVzdGZpbGUBABAAAAA
AAAAAAAAUAAAAAAAAACtJLS5Jy8xJVUjOzytJzSsp5gIAUEsBAjMALQAAAAgA2HL6ThyP6vz//////////wgAFAAAAAAAA
AAAAAAAAAAAAHRlc3RmaWxlAQAQABIAAAAAAAAAFAAAAAAAAABQSwUGAAAAAAEAAQBKAAAATgAAAAAA";

[Test]
[Category("Zip")]
public void CorruptCentralDirWithCorrectZip64CD()
{
var fileBytes = Convert.FromBase64String(TestFileBadCDGoodCD64);
using (var ms = new MemoryStream(fileBytes))
using (var zip = new ZipFile(ms))
{
Assert.AreEqual(1, zip.Count);
Assert.AreNotEqual(0, zip[0].Size, "Uncompressed file size read from corrupt CentralDir instead of CD64");
}
}

}

}