From: Adam Stylinski Date: Fri, 17 Nov 2023 23:26:45 +0000 (-0500) Subject: Fix an issue with regard to finishing out the window X-Git-Tag: 2.1.5~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=90b6c364274abfbb7cd7030ef081e8609d14ccd8;p=thirdparty%2Fzlib-ng.git Fix an issue with regard to finishing out the window if inflate is invoked with Z_FINISH, and it deems a window was not necessary, there's a corner case where we never checksum the bytes. Detect this by checking the window size against zero and the value of the flush parameter. This should fix issue #1600, and possibly #1565 as well. --- diff --git a/inflate.c b/inflate.c index a01e10f7..0c9d499f 100644 --- a/inflate.c +++ b/inflate.c @@ -1112,11 +1112,12 @@ int32_t Z_EXPORT PREFIX(inflate)(PREFIX3(stream) *strm, int32_t flush) { */ inf_leave: RESTORE(); + uint32_t check_bytes = out - strm->avail_out; if (INFLATE_NEED_UPDATEWINDOW(strm) && (state->wsize || (out != strm->avail_out && state->mode < BAD && (state->mode < CHECK || flush != Z_FINISH)))) { /* update sliding window with respective checksum if not in "raw" mode */ - if (updatewindow(strm, strm->next_out, out - strm->avail_out, state->wrap & 4)) { + if (updatewindow(strm, strm->next_out, check_bytes, state->wrap & 4)) { state->mode = MEM; return Z_MEM_ERROR; } @@ -1129,8 +1130,13 @@ int32_t Z_EXPORT PREFIX(inflate)(PREFIX3(stream) *strm, int32_t flush) { strm->data_type = (int)state->bits + (state->last ? 64 : 0) + (state->mode == TYPE ? 128 : 0) + (state->mode == LEN_ || state->mode == COPY_ ? 256 : 0); - if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK) + if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK) { + /* when no sliding window is used, hash the output bytes if no CHECK state */ + if (INFLATE_NEED_CHECKSUM(strm) && !state->wsize && flush == Z_FINISH) { + inf_chksum(strm, put - check_bytes, check_bytes); + } ret = Z_BUF_ERROR; + } return ret; }