Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Numpsy opened this issue Feb 18, 2019 · 2 comments

Comments

@Numpsy
Copy link
Contributor

Numpsy commented Feb 18, 2019

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
@Numpsy
Copy link
Contributor Author

Numpsy commented Feb 18, 2019

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.

@Numpsy
Copy link
Contributor Author

Numpsy commented Mar 11, 2019

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

@Numpsy Numpsy closed this as completed Mar 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant