System.IO.IOException instead of Ionic.Zip.BadReadException on ZipFile.Read()

Mar 18, 2010 at 11:47 AM

ZipFile.Read(byte[] buffer) and ZipFile.Read(Stream zipStream) (if zipStream supports seeking) throw System.IO.IOException when zip file content has small amount of data but not empty. In large amount of data and empty data cases they throw Ionic.Zip.BadReadException.

There are some unit tests.

// this test fails
[TestMethod]
[ExpectedException(typeof(BadReadException))]
public void IncorrectZipContentTest1()
{
    byte[] incorrectZipContent = Encoding.UTF8.GetBytes("wrong zipfile content");
    ZipFile zipFile = ZipFile.Read(incorrectZipContent);
}

// this test succeeds
[TestMethod]
[ExpectedException(typeof(BadReadException))]
public void IncorrectZipContentTest2()
{
    ZipFile zipFile = ZipFile.Read(new byte[0]);
}

// this test succeeds too
[TestMethod]
[ExpectedException(typeof(BadReadException))]
public void IncorrectZipContentTest3()
{
    byte[] incorrectZipContent = new byte[8192];
    ZipFile zipFile = ZipFile.Read(incorrectZipContent);
}

I think, first code snippet should throw Ionic.Zip.BadReadException too.

Coordinator
Mar 18, 2010 at 12:24 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.