]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Throw an error when input is raw deflate stream but window_bits is not supplied.
authorNathan Moinvaziri <nathan@nathanm.com>
Fri, 11 Mar 2022 23:45:06 +0000 (15:45 -0800)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Wed, 16 Mar 2022 10:42:45 +0000 (11:42 +0100)
test/minideflate.c

index e1295afc89771ced198733b96b778df68ac8b6b0..d4d8423a9f131c6fea724b6ae46faf66d0f1fa73 100644 (file)
 #if defined(_WIN32) || defined(__CYGWIN__)
 #  include <fcntl.h>
 #  include <io.h>
+#  include <string.h>
 #  define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
+#  ifdef _MSC_VER
+#    define strcasecmp _stricmp
+#  endif
 #else
+#  include <strings.h>
 #  define SET_BINARY_MODE(file)
 #endif
 
@@ -277,13 +282,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) {
@@ -307,8 +305,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) {
@@ -318,6 +321,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 (window_bits == INT32_MAX) {
         window_bits = MAX_WBITS;