Skip to content

Commit 049578f

Browse files
committed
Reject a window size of 256 bytes if not using the zlib wrapper.
There is a bug in deflate for windowBits == 8 (256-byte window). As a result, zlib silently changes a request for 8 to a request for 9 (512-byte window), and sets the zlib header accordingly so that the decompressor knows to use a 512-byte window. However if deflateInit2() is used for raw deflate or gzip streams, then there is no indication that the request was not honored, and the application might assume that it can use a 256-byte window when decompressing. This commit returns an error if the user requests a 256-byte window when using raw deflate or gzip encoding.
1 parent a0bf0f3 commit 049578f

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

deflate.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
263263
#endif
264264
if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
265265
windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
266-
strategy < 0 || strategy > Z_FIXED) {
266+
strategy < 0 || strategy > Z_FIXED || (windowBits == 8 && wrap != 1)) {
267267
return Z_STREAM_ERROR;
268268
}
269269
if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */

0 commit comments

Comments
 (0)