From: Nathan Moinvaziri Date: Fri, 11 Mar 2022 23:45:06 +0000 (-0800) Subject: Throw an error when input is raw deflate stream but window_bits is not supplied. X-Git-Tag: 2.0.7~54 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2fe47c75b3310474a3a5066a2e5563451cd29ac4;p=thirdparty%2Fzlib-ng.git Throw an error when input is raw deflate stream but window_bits is not supplied. --- diff --git a/test/minideflate.c b/test/minideflate.c index 0c452635..2c93098d 100644 --- a/test/minideflate.c +++ b/test/minideflate.c @@ -20,8 +20,13 @@ #if defined(_WIN32) || defined(__CYGWIN__) # include # include +# include # define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY) +# ifdef _MSC_VER +# define strcasecmp _stricmp +# endif #else +# include # define SET_BINARY_MODE(file) #endif @@ -287,13 +292,6 @@ int main(int argc, char **argv) { SET_BINARY_MODE(stdin); SET_BINARY_MODE(stdout); - if (window_bits == INT32_MAX) { - window_bits = MAX_WBITS; - /* Auto-detect wrapper for inflateInit */ - if (uncompr) - window_bits += 32; - } - if (i != argc) { fin = fopen(argv[i], "rb+"); if (fin == NULL) { @@ -317,8 +315,13 @@ int main(int argc, char **argv) { } } else { char *out_ext = strrchr(out_file, '.'); - if (out_ext != NULL) + if (out_ext != NULL) { + if (strcasecmp(out_ext, ".zraw") == 0 && window_bits == INT32_MAX) { + fprintf(stderr, "Must specify window bits for raw deflate stream\n"); + exit(1); + } *out_ext = 0; + } } fout = fopen(out_file, "wb"); if (fout == NULL) { @@ -328,6 +331,13 @@ int main(int argc, char **argv) { free(out_file); } } + + if (window_bits == INT32_MAX) { + window_bits = MAX_WBITS; + /* Auto-detect wrapper for inflateInit */ + if (uncompr) + window_bits += 32; + } if (uncompr) { inflate_params(fin, fout, read_buf_size, write_buf_size, window_bits, flush);