]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Fix the copy of pending_buf in deflateCopy() for the LIT_MEM case.
authorHans Wennborg <hans@chromium.org>
Tue, 30 Jan 2024 00:42:46 +0000 (16:42 -0800)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Wed, 7 Feb 2024 18:15:56 +0000 (19:15 +0100)
madler/zlib#60c31985ecdc2b40873564867e1ad2aef0b88697

deflate.c
deflate.h

index c6accfd0eed25408fa6c6a89b8af4dec9507f3b5..8f6300dc99a404418321f4deefa04119dae99c97 100644 (file)
--- a/deflate.c
+++ b/deflate.c
@@ -295,11 +295,7 @@ int32_t ZNG_CONDEXPORT PREFIX(deflateInit2)(PREFIX3(stream) *strm, int32_t level
      * symbols from which it is being constructed.
      */
 
-#ifdef LIT_MEM
-    s->pending_buf = (unsigned char *) ZALLOC(strm, s->lit_bufsize, 5);
-#else
-    s->pending_buf = (unsigned char *) ZALLOC(strm, s->lit_bufsize, 4);
-#endif
+    s->pending_buf = (unsigned char *) ZALLOC(strm, s->lit_bufsize, LIT_BUFS);
     s->pending_buf_size = s->lit_bufsize * 4;
 
     if (s->window == NULL || s->prev == NULL || s->head == NULL || s->pending_buf == NULL) {
@@ -1073,7 +1069,7 @@ int32_t Z_EXPORT PREFIX(deflateCopy)(PREFIX3(stream) *dest, PREFIX3(stream) *sou
     ds->window = (unsigned char *) ZALLOC_WINDOW(dest, ds->w_size + window_padding, 2*sizeof(unsigned char));
     ds->prev   = (Pos *)  ZALLOC(dest, ds->w_size, sizeof(Pos));
     ds->head   = (Pos *)  ZALLOC(dest, HASH_SIZE, sizeof(Pos));
-    ds->pending_buf = (unsigned char *) ZALLOC(dest, ds->lit_bufsize, 4);
+    ds->pending_buf = (unsigned char *) ZALLOC(dest, ds->lit_bufsize, LIT_BUFS);
 
     if (ds->window == NULL || ds->prev == NULL || ds->head == NULL || ds->pending_buf == NULL) {
         PREFIX(deflateEnd)(dest);
@@ -1083,7 +1079,7 @@ int32_t Z_EXPORT PREFIX(deflateCopy)(PREFIX3(stream) *dest, PREFIX3(stream) *sou
     memcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(unsigned char));
     memcpy((void *)ds->prev, (void *)ss->prev, ds->w_size * sizeof(Pos));
     memcpy((void *)ds->head, (void *)ss->head, HASH_SIZE * sizeof(Pos));
-    memcpy(ds->pending_buf, ss->pending_buf, ds->pending_buf_size);
+    memcpy(ds->pending_buf, ss->pending_buf, ds->lit_bufsize * LIT_BUFS);
 
     ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
 #ifdef LIT_MEM
index 3db110a47028618c99bedd0caa9cc927f1f2003c..392cf117bcfb8debb184f9e7e5ed007b5207ce94 100644 (file)
--- a/deflate.h
+++ b/deflate.h
@@ -264,9 +264,11 @@ struct internal_state {
      */
 
 #ifdef LIT_MEM
+#   define LIT_BUFS 5
     uint16_t *d_buf;              /* buffer for distances */
     unsigned char *l_buf;         /* buffer for literals/lengths */
 #else
+#   define LIT_BUFS 4
     unsigned char *sym_buf;       /* buffer for distances and literals/lengths */
 #endif