Skip to content

System.ArgumentNullException thrown from ZipOutputStream when writing AES encrypted/Stored entries #322

Closed

Description

@Numpsy

Steps to reproduce

Try to use ZipOutputStream to create an AES encrypted entry whose compressionMethod is set to Stored.
e.g.

using (var memoryStream = new MemoryStream())
{
	using (var zipStream = new ZipOutputStream(memoryStream))
	{
		zipStream.IsStreamOwner = false;
		zipStream.Password = "password";  // optional. Null is the same as not setting. Required if using AES.

		ZipEntry zipEntry = new ZipEntry("stored");
		zipEntry.AESKeySize = 256;
		zipEntry.DateTime = DateTime.Now;
		zipEntry.CompressionMethod = CompressionMethod.Stored;

		zipStream.PutNextEntry(zipEntry);

		byte[] dummyData = Encoding.UTF8.GetBytes(DummyDataString);

		using (var dummyStream = new MemoryStream(dummyData))
		{
			dummyStream.CopyTo(zipStream);
		}

		zipStream.CloseEntry();
	}
}	

Expected behavior

The entry should be added

Actual behavior

The call to CloseEntry() throws an ArgumentNullException.

Version of SharpZipLib

Obtained from (only keep the relevant lines)

  • Compiled from source, commit: 25ee644

Activity

  1. Numpsy commented on Feb 18, 2019

    @Numpsy
    ContributorAuthor

    Problem seems to be that the AESAuthCode property of the output stream isn't set up in this case, so the attempt to use it @

    baseOutputStream_.Write(AESAuthCode, 0, 10);
    throws.

    See referenced PR for a possible fix.

  2. Numpsy commented on Mar 11, 2019

    @Numpsy
    ContributorAuthor

    Should be fixed by #323, so i'll close this now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions