]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Initialize data_type in inflateResetKeep and update inflatePrime docs.
authorMark Adler <madler@alumni.caltech.edu>
Sat, 4 Apr 2026 01:34:42 +0000 (18:34 -0700)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Wed, 29 Jul 2026 09:46:58 +0000 (11:46 +0200)
Assure that data_type is correct after initialization and a
Z_NEED_DICT return. Elaborate on the inflatePrime() error return
and correct data_type description in inflate() docs.

Upstream: https://github.com/madler/zlib/commit/473f7853

inflate.c
zlib-ng.h.in
zlib.h.in

index 2eae9e3ce80c6a18c7e085399ce7d72b9c106be4..a05f292a88bcfe1cae99ab36d095781029627c10 100644 (file)
--- a/inflate.c
+++ b/inflate.c
@@ -68,6 +68,7 @@ int32_t Z_EXPORT PREFIX(inflateResetKeep)(PREFIX3(stream) *strm) {
     state = (struct inflate_state *)strm->state;
     strm->total_in = strm->total_out = state->total = 0;
     strm->msg = NULL;
+    strm->data_type = 0;
     if (state->wrap)        /* to support ill-conceived Java test suite */
         strm->adler = state->wrap & 1;
     state->mode = HEAD;
index 5bfcfecde77ef8ebd3f54a41d548bab16fc6beab..fe6b6d88df2d68241674a27efd634aa47d3bb24d 100644 (file)
@@ -441,7 +441,7 @@ int32_t zng_inflate(zng_stream *strm, int32_t flush);
 
     The Z_BLOCK option assists in appending to or combining deflate streams.
   To assist in this, on return inflate() always sets strm->data_type to the
-  number of unused bits in the last byte taken from strm->next_in, plus 64 if
+  number of unused bits in the input taken from strm->next_in, plus 64 if
   inflate() is currently decoding the last block in the deflate stream, plus
   128 if inflate() returned immediately after decoding an end-of-block code or
   decoding the complete header up to just before the first byte of the deflate
@@ -985,13 +985,15 @@ int32_t zng_inflateReset2(zng_stream *strm, int32_t windowBits);
 Z_EXTERN Z_EXPORT
 int32_t zng_inflatePrime(zng_stream *strm, int32_t bits, int32_t value);
 /*
-     This function inserts bits in the inflate input stream.  The intent is
-   that this function is used to start inflating at a bit position in the
-   middle of a byte.  The provided bits will be used before any bytes are used
-   from next_in.  This function should only be used with raw inflate, and
-   should be used before the first inflate() call after inflateInit2() or
-   inflateReset().  bits must be less than or equal to 16, and that many of the
-   least significant bits of value will be inserted in the input.
+     This function inserts bits in the inflate input stream.  The intent is to
+   use inflatePrime() to start inflating at a bit position in the middle of a
+   byte.  The provided bits will be used before any bytes are used from
+   next_in.  This function should be used with raw inflate, before the first
+   inflate() call, after inflateInit2() or inflateReset().  It can also be used
+   after an inflate() return indicates the end of a deflate block or header
+   when using Z_BLOCK.  bits must be less than or equal to 16, and that many of
+   the least significant bits of value will be inserted in the input.  The
+   other bits in value can be non-zero, and will be ignored.
 
      If bits is negative, then the input stream bit buffer is emptied.  Then
    inflatePrime() can be called again to put bits in the buffer.  This is used
@@ -999,7 +1001,15 @@ int32_t zng_inflatePrime(zng_stream *strm, int32_t bits, int32_t value);
    to feeding inflate codes.
 
      inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source
-   stream state was inconsistent.
+   stream state was inconsistent, or if bits is out of range.  If inflate was
+   in the middle of processing a header, trailer, or stored block lengths, then
+   it is possible for there to be only eight bits available in the bit buffer.
+   In that case, bits > 8 is considered out of range.  However, when used as
+   outlined above, there will always be 16 bits available in the buffer for
+   insertion.  As noted in its documentation above, inflate records the number
+   of bits in the bit buffer on return in data_type. 32 minus that is the
+   number of bits available for insertion.  inflatePrime does not update
+   data_type with the new number of bits in buffer.
 */
 
 Z_EXTERN Z_EXPORT
index 5bbde5505c3311375d30fc497ecc95326fb45507..25a80c4ef44dd52a7a0c88bbedbba3a100a2e2d5 100644 (file)
--- a/zlib.h.in
+++ b/zlib.h.in
@@ -452,7 +452,7 @@ Z_EXTERN int Z_EXPORT inflate(z_stream *strm, int flush);
 
     The Z_BLOCK option assists in appending to or combining deflate streams.
   To assist in this, on return inflate() always sets strm->data_type to the
-  number of unused bits in the last byte taken from strm->next_in, plus 64 if
+  number of unused bits in the input taken from strm->next_in, plus 64 if
   inflate() is currently decoding the last block in the deflate stream, plus
   128 if inflate() returned immediately after decoding an end-of-block code or
   decoding the complete header up to just before the first byte of the deflate
@@ -988,13 +988,15 @@ Z_EXTERN int Z_EXPORT inflateReset2(z_stream *strm, int windowBits);
 
 Z_EXTERN int Z_EXPORT inflatePrime(z_stream *strm, int bits, int value);
 /*
-     This function inserts bits in the inflate input stream.  The intent is
-   that this function is used to start inflating at a bit position in the
-   middle of a byte.  The provided bits will be used before any bytes are used
-   from next_in.  This function should only be used with raw inflate, and
-   should be used before the first inflate() call after inflateInit2() or
-   inflateReset().  bits must be less than or equal to 16, and that many of the
-   least significant bits of value will be inserted in the input.
+     This function inserts bits in the inflate input stream.  The intent is to
+   use inflatePrime() to start inflating at a bit position in the middle of a
+   byte.  The provided bits will be used before any bytes are used from
+   next_in.  This function should be used with raw inflate, before the first
+   inflate() call, after inflateInit2() or inflateReset().  It can also be used
+   after an inflate() return indicates the end of a deflate block or header
+   when using Z_BLOCK.  bits must be less than or equal to 16, and that many of
+   the least significant bits of value will be inserted in the input.  The
+   other bits in value can be non-zero, and will be ignored.
 
      If bits is negative, then the input stream bit buffer is emptied.  Then
    inflatePrime() can be called again to put bits in the buffer.  This is used
@@ -1002,7 +1004,15 @@ Z_EXTERN int Z_EXPORT inflatePrime(z_stream *strm, int bits, int value);
    to feeding inflate codes.
 
      inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source
-   stream state was inconsistent.
+   stream state was inconsistent, or if bits is out of range.  If inflate was
+   in the middle of processing a header, trailer, or stored block lengths, then
+   it is possible for there to be only eight bits available in the bit buffer.
+   In that case, bits > 8 is considered out of range.  However, when used as
+   outlined above, there will always be 16 bits available in the buffer for
+   insertion.  As noted in its documentation above, inflate records the number
+   of bits in the bit buffer on return in data_type. 32 minus that is the
+   number of bits available for insertion.  inflatePrime does not update
+   data_type with the new number of bits in buffer.
 */
 
 Z_EXTERN long Z_EXPORT inflateMark(z_stream *strm);