Skip to content

Attempting to use AES encryption with no password throws unhelpful exception #507

@piksel

Description

@piksel

I tried turning off the password in one of the zip output stream unit tests and got

Message: 
  System.ArgumentNullException : Buffer cannot be null.
  Parameter name: buffer
Stack Trace: 
  MemoryStream.Write(Byte[] buffer, Int32 offset, Int32 count)
  ZipOutputStream.CloseEntry() line 534
  ZipOutputStream.Finish() line 772
  DeflaterOutputStream.Dispose(Boolean disposing) line 404
  Stream.Close()
  ZipEncryptionHandling.WriteEncryptedZipToStream(Stream stream, String password, Int32 keySize, CompressionMethod compressionMethod) line 497
  ZipEncryptionHandling.CreateZipWithEncryptedEntries(String password, Int32 keySize, CompressionMethod compressionMethod) line 540

Because AESAuthCode is null.

Looks to be because some of the logic goes off entry.AESKeySize being set to a non-zero value (deciding whether to write the > AES extra data etc), but them some of it goes off Entry.IsCrypted being true, which is only done automatically if a password has already been specified when the entry is added, so some of the other crypto bits get skipped.

Gets itself in a bit of a mess basically.
Possibly PutNextEntry should throw if you try to add an entry with AESKeySize set, but no password set?

Originally posted by @Numpsy in #506 (comment)

Metadata

Metadata

Assignees

Labels

encryptionzipRelated to ZIP file format

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions