2

Closed

Any error causes ZipException, not just invalid file formats

description

There's an inconsistency between the documentation and implementation. Currently any exception when creating a new ZipFile object will cause a ZipException to occur. However, this is documented as happening if there's an invalid file format. For example, this test demonstrates a valid file causing this exception.
 
    [Test]
    public void FileNotAvailableFails()
    {
        const string tempFile = @"c:\testFile.zip";
        using (var zipfile = new ZipFile(tempFile)) { zipfile.Save(); }
        try
        {
            using (new FileStream(tempFile, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None))
            {
                Assert.Throws(typeof(IOException), () => { using (new ZipFile(tempFile)) { } });
            }
        }
        finally
        {
            File.Delete(tempFile);
        }
    }
 
At a minimum, the documentation should be changed to indicate the inner exception indicates the real cause of the problem and the invalid file format description removed.
Ideally, any exception that is not due to an invalid file format should not be trapped and only things related to a bad file should be wrapped with the ZipException.
Closed Jun 14, 2011 at 4:22 AM by Cheeso
fixed in changeset 79081. First binary with this change: v1.9.1.6

comments

Cheeso wrote Jun 14, 2011 at 4:21 AM

Good bug. The exception message now reads "Could not read {0} as a zip file" and the inner exception provides additional information.