madler / zlib

A massively spiffy yet delicately unobtrusive compression library.
http://zlib.net/
Other
5.65k stars 2.44k forks source link

Fix possible signed integer overflow #951

Closed stoeckmann closed 6 months ago

stoeckmann commented 6 months ago

The block_get function could return -1 if end of block is reached.

Do not left shift a negative value to prevent undefined behavior due to signed integer overflow.

The issue has been introduced with 4a5e3e7d255f3f8eba9ecdb8bd8080db43bf0aeb which is not contained in any release.

stoeckmann commented 6 months ago

Adjusted to just check just high. Probably not that timing relevant, but:

madler commented 6 months ago

Thanks. Fixed. I changed the (long) to (unsigned long).