From: Hans Wennborg Date: Tue, 30 Jan 2024 00:42:46 +0000 (-0800) Subject: Fix the copy of pending_buf in deflateCopy() for the LIT_MEM case. X-Git-Tag: 2.2.0~92 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6345d05782a24e5297f2f18d675fd7000c90d93a;p=thirdparty%2Fzlib-ng.git Fix the copy of pending_buf in deflateCopy() for the LIT_MEM case. madler/zlib#60c31985ecdc2b40873564867e1ad2aef0b88697 --- diff --git a/deflate.c b/deflate.c index c6accfd0..8f6300dc 100644 --- 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 diff --git a/deflate.h b/deflate.h index 3db110a4..392cf117 100644 --- 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