]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Add error propagation to gzread/gzwrite gzalloc 1928/head
authorHans Kristian Rosbach <hk-git@circlestorm.org>
Wed, 20 Aug 2025 14:24:16 +0000 (16:24 +0200)
committerHans Kristian Rosbach <hk-git@circlestorm.org>
Wed, 20 Aug 2025 14:38:41 +0000 (16:38 +0200)
gzread.c.in
gzwrite.c

index 0c9d7e200ee14bb966d6a6397fad37b8b45c0ec7..91494b2ccb9da1fd6f93f6e1955d5f1fb6e2bb96 100644 (file)
@@ -25,9 +25,14 @@ static int gz_read_init(gz_state *state) {
     }
 
     /* Initialize inflate state */
-    if (PREFIX(inflateInit2)(&(state->strm), MAX_WBITS + 16) != Z_OK) {
+    int ret = PREFIX(inflateInit2)(&(state->strm), MAX_WBITS + 16);
+    if (ret != Z_OK) {
         gz_buffer_free(state);
-        gz_error(state, Z_MEM_ERROR, "out of memory");
+        if (ret == Z_MEM_ERROR) {
+            gz_error(state, Z_MEM_ERROR, "out of memory");
+        } else {
+            gz_error(state, Z_STREAM_ERROR, "invalid compression parameters");
+        }
         return -1;
     }
     return 0;
index 8167ce20697d5b691326a07dcbf612bbe532f60f..5dc9e15b91515642ae4cdb323500f3a48e623c4a 100644 (file)
--- a/gzwrite.c
+++ b/gzwrite.c
@@ -29,10 +29,14 @@ static int gz_write_init(gz_state *state) {
     /* only need deflate state if compressing */
     if (!state->direct) {
         /* allocate deflate memory, set up for gzip compression */
-        ret = PREFIX(deflateInit2)(strm, state->level, Z_DEFLATED, MAX_WBITS + 16, DEF_MEM_LEVEL, state->strategy);
+        int ret = PREFIX(deflateInit2)(strm, state->level, Z_DEFLATED, MAX_WBITS + 16, DEF_MEM_LEVEL, state->strategy);
         if (ret != Z_OK) {
             gz_buffer_free(state);
-            gz_error(state, Z_MEM_ERROR, "out of memory");
+            if (ret == Z_MEM_ERROR) {
+                gz_error(state, Z_MEM_ERROR, "out of memory");
+            } else {
+                gz_error(state, Z_STREAM_ERROR, "invalid compression parameters");
+            }
             return -1;
         }
         strm->next_in = NULL;