if (windowBits < 0) { /* suppress zlib wrapper */
wrap = 0;
- if (windowBits < -15)
+ if (windowBits < -MAX_WBITS)
return Z_STREAM_ERROR;
windowBits = -windowBits;
#ifdef GZIP
- } else if (windowBits > 15) {
+ } else if (windowBits > MAX_WBITS) {
wrap = 2; /* write gzip wrapper instead */
windowBits -= 16;
#endif
}
- if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED || windowBits < 8 ||
- windowBits > 15 || level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED ||
+ if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED || windowBits < MIN_WBITS ||
+ windowBits > MAX_WBITS || level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED ||
(windowBits == 8 && wrap != 1)) {
return Z_STREAM_ERROR;
}
/* if not default parameters, return conservative bound */
if (DEFLATE_NEED_CONSERVATIVE_BOUND(strm) || /* hook for IBM Z DFLTCC */
- s->w_bits != 15 || HASH_BITS < 15) {
+ s->w_bits != MAX_WBITS || HASH_BITS < 15) {
if (s->level == 0) {
/* upper bound for stored blocks with length 127 (memLevel == 1) --
~4% overhead plus a small constant */
#define HEAP_SIZE (2*L_CODES+1)
/* maximum heap size */
-#define MAX_BITS 15
-/* All codes must not exceed MAX_BITS bits */
-
#define BIT_BUF_SIZE 64
/* size of bit buffer in bi_buf */
state->strm.opaque = NULL;
state->strm.avail_in = 0;
state->strm.next_in = NULL;
- if (PREFIX(inflateInit2)(&(state->strm), 15 + 16) != Z_OK) { /* gunzip */
+ if (PREFIX(inflateInit2)(&(state->strm), MAX_WBITS + 16) != Z_OK) { /* gunzip */
zng_free(state->out);
zng_free(state->in);
state->size = 0;
int32_t ZNG_CONDEXPORT PREFIX(inflateBackInit)(PREFIX3(stream) *strm, int32_t windowBits, uint8_t *window) {
struct inflate_state *state;
- if (strm == NULL || window == NULL || windowBits < 8 || windowBits > 15)
+ if (strm == NULL || window == NULL || windowBits < MIN_WBITS || windowBits > MAX_WBITS)
return Z_STREAM_ERROR;
strm->msg = NULL; /* in case we return an error */
if (strm->zalloc == NULL) {
}
/* length code -- get extra bits, if any */
- state->extra = (here.op & 15);
+ state->extra = (here.op & MAX_BITS);
if (state->extra) {
NEEDBITS(state->extra);
state->length += BITS(state->extra);
break;
}
state->offset = here.val;
- state->extra = (here.op & 15);
+ state->extra = (here.op & MAX_BITS);
/* get distance extra bits, if any */
if (state->extra) {
/* decode literals and length/distances until end-of-block or not enough
input data or output space */
do {
- if (bits < 15) {
+ if (bits < MAX_BITS) {
hold |= load_64_bits(in, bits);
in += 6;
bits += 48;
len += BITS(op);
DROPBITS(op);
Tracevv((stderr, "inflate: length %u\n", len));
- if (bits < 15) {
+ if (bits < MAX_BITS) {
hold |= load_64_bits(in, bits);
in += 6;
bits += 48;
op = here->op;
if (op & 16) { /* distance base */
dist = here->val;
- op &= 15; /* number of extra bits */
+ op &= MAX_BITS; /* number of extra bits */
if (bits < op) {
hold |= load_64_bits(in, bits);
in += 6;
/* extract wrap request from windowBits parameter */
if (windowBits < 0) {
wrap = 0;
- if (windowBits < -15)
+ if (windowBits < -MAX_WBITS)
return Z_STREAM_ERROR;
windowBits = -windowBits;
} else {
wrap = (windowBits >> 4) + 5;
#ifdef GUNZIP
if (windowBits < 48)
- windowBits &= 15;
+ windowBits &= MAX_WBITS;
#endif
}
/* set number of window bits, free window if different */
- if (windowBits && (windowBits < 8 || windowBits > 15))
+ if (windowBits && (windowBits < MIN_WBITS || windowBits > MAX_WBITS))
return Z_STREAM_ERROR;
if (state->window != NULL && state->wbits != (unsigned)windowBits) {
ZFREE_WINDOW(strm, state->window);
#ifdef GUNZIP
if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */
if (state->wbits == 0)
- state->wbits = 15;
+ state->wbits = MAX_WBITS;
state->check = CRC32_INITIAL_VALUE;
CRC2(state->check, hold);
INITBITS();
len = BITS(4) + 8;
if (state->wbits == 0)
state->wbits = len;
- if (len > 15 || len > state->wbits) {
+ if (len > MAX_WBITS || len > state->wbits) {
SET_BAD("invalid window size");
break;
}
}
/* length code */
- state->extra = (here.op & 15);
+ state->extra = (here.op & MAX_BITS);
state->mode = LENEXT;
Z_FALLTHROUGH;
break;
}
state->offset = here.val;
- state->extra = (here.op & 15);
+ state->extra = (here.op & MAX_BITS);
state->mode = DISTEXT;
Z_FALLTHROUGH;
#include "zutil.h"
#include "inftrees.h"
-#define MAXBITS 15
-
const char PREFIX(inflate_copyright)[] = " inflate 1.2.13 Copyright 1995-2022 Mark Adler ";
/*
If you use the zlib library in a product, an acknowledgment is welcome
const uint16_t *base; /* base value table to use */
const uint16_t *extra; /* extra bits table to use */
unsigned match; /* use base and extra for symbol >= match */
- uint16_t count[MAXBITS+1]; /* number of codes of each length */
- uint16_t offs[MAXBITS+1]; /* offsets in table for each length */
+ uint16_t count[MAX_BITS+1]; /* number of codes of each length */
+ uint16_t offs[MAX_BITS+1]; /* offsets in table for each length */
static const uint16_t lbase[31] = { /* Length codes 257..285 base */
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
*/
/* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */
- for (len = 0; len <= MAXBITS; len++)
+ for (len = 0; len <= MAX_BITS; len++)
count[len] = 0;
for (sym = 0; sym < codes; sym++)
count[lens[sym]]++;
/* bound code lengths, force root to be within code lengths */
root = *bits;
- for (max = MAXBITS; max >= 1; max--)
+ for (max = MAX_BITS; max >= 1; max--)
if (count[max] != 0) break;
root = MIN(root, max);
if (UNLIKELY(max == 0)) { /* no symbols to code at all */
/* check for an over-subscribed or incomplete set of lengths */
left = 1;
- for (len = 1; len <= MAXBITS; len++) {
+ for (len = 1; len <= MAX_BITS; len++) {
left <<= 1;
left -= count[len];
if (left < 0) return -1; /* over-subscribed */
/* generate offsets into symbol table for each length for sorting */
offs[1] = 0;
- for (len = 1; len < MAXBITS; len++)
+ for (len = 1; len < MAX_BITS; len++)
offs[len + 1] = offs[len] + count[len];
/* sort symbols by length, by symbol order within each length */
EXPECT_EQ(err, Z_OK);
memset(&strm, 0, sizeof(strm));
- err = PREFIX(inflateInit2)(&strm, -15);
+ err = PREFIX(inflateInit2)(&strm, -MAX_WBITS);
EXPECT_EQ(err, Z_OK);
strm.next_in = next_out;
int err;
memset(&strm, 0, sizeof(strm));
- err = PREFIX(deflateInit2)(&strm, 1, Z_DEFLATED, -15, 1, Z_FILTERED);
+ err = PREFIX(deflateInit2)(&strm, 1, Z_DEFLATED, -MAX_WBITS, 1, Z_FILTERED);
EXPECT_EQ(err, Z_OK);
z_const unsigned char next_in[495] =
EXPECT_EQ(err, Z_OK);
memset(&strm, 0, sizeof(strm));
- err = PREFIX(inflateInit2)(&strm, -15);
+ err = PREFIX(inflateInit2)(&strm, -MAX_WBITS);
EXPECT_EQ(err, Z_OK);
strm.next_in = next_out;
EXPECT_EQ(err, Z_OK);
memset(&stream, 0, sizeof(stream));
- err = PREFIX(inflateInit2)(&stream, -15);
+ err = PREFIX(inflateInit2)(&stream, -MAX_WBITS);
EXPECT_EQ(err, Z_OK);
stream.adler = 0x87654321;
* created by gzip. (Files created by minigzip can still be extracted by
* gzip.)
*/
+#ifndef MIN_WBITS
+# define MIN_WBITS 8 /* 256 LZ77 window */
+#endif
#ifndef MAX_WBITS
# define MAX_WBITS 15 /* 32K LZ77 window */
#endif
* created by gzip. (Files created by minigzip can still be extracted by
* gzip.)
*/
+#ifndef MIN_WBITS
+# define MIN_WBITS 8 /* 256 LZ77 window */
+#endif
#ifndef MAX_WBITS
# define MAX_WBITS 15 /* 32K LZ77 window */
#endif
#endif
/* default windowBits for decompression. MAX_WBITS is for compression only */
+#define MAX_BITS 15
+/* all codes must not exceed MAX_BITS bits */
+
#if MAX_MEM_LEVEL >= 8
# define DEF_MEM_LEVEL 8
#else