summaryrefslogtreecommitdiff
path: root/deflate.c
diff options
context:
space:
mode:
authorMark Adler <madler@alumni.caltech.edu>2016-10-24 15:52:19 -0700
committerMark Adler <madler@alumni.caltech.edu>2016-10-24 15:52:19 -0700
commit049578f0a1849f502834167e233f4c1d52ddcbcc (patch)
treebdcea5ae22295e7865d9dc620f557e3f6ab8bdbf /deflate.c
parenta0bf0f31d30088333aacf0b886d606c81a54bf21 (diff)
downloadzlib-049578f0a1849f502834167e233f4c1d52ddcbcc.tar.gz
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.
Diffstat (limited to 'deflate.c')
-rw-r--r--deflate.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/deflate.c b/deflate.c
index cb130be..801c407 100644
--- a/deflate.c
+++ b/deflate.c
@@ -263,7 +263,7 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
#endif
if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
- strategy < 0 || strategy > Z_FIXED) {
+ strategy < 0 || strategy > Z_FIXED || (windowBits == 8 && wrap != 1)) {
return Z_STREAM_ERROR;
}
if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */