haf / DotNetZip.Semverd

Please use System.IO.Compression! A fork of the DotNetZip project without signing with a solution that compiles cleanly. This project aims to follow semver to avoid versioning conflicts. DotNetZip is a FAST, FREE class library and toolset for manipulating zip files. Use VB, C# or any .NET language to easily create, extract, or update zip files.
Other
545 stars 218 forks source link

DeflateManager.SetDictionary() contains a suspicious check #200

Closed Dmitry-Me closed 1 year ago

Dmitry-Me commented 4 years ago
DeflateManager.SetDictionary()

https://github.com/haf/DotNetZip.Semverd/blob/f7e1c3547540bf43bc6819dac489e6b107b1c07a/src/Zlib.Shared/Deflate.cs#L1668

starts like this:

 int length = dictionary.Length;
 int index = 0;

 if (dictionary == null || status != INIT_STATE)
       throw new ZlibException("Stream error.");

when dictionary==null it would yield a NullReferenceException when accessing dictionary.Length. So the check is useless when placed like this. Perhaps it should be moved closer to the start of the function.

This was found with static analysis.