/* inflate.h -- internal inflate state definition1* Copyright (C) 1995-2019 Mark Adler2* For conditions of distribution and use, see copyright notice in zlib.h3*/45/* WARNING: this file should *not* be used by applications. It is6part of the implementation of the compression library and is7subject to change. Applications should only use zlib.h.8*/910/* define NO_GZIP when compiling if you want to disable gzip header and11trailer decoding by inflate(). NO_GZIP would be used to avoid linking in12the crc code when it is not needed. For shared libraries, gzip decoding13should be left enabled. */14#ifndef NO_GZIP15# define GUNZIP16#endif1718/* Possible inflate modes between inflate() calls */19typedef enum {20HEAD = 16180, /* i: waiting for magic header */21FLAGS, /* i: waiting for method and flags (gzip) */22TIME, /* i: waiting for modification time (gzip) */23OS, /* i: waiting for extra flags and operating system (gzip) */24EXLEN, /* i: waiting for extra length (gzip) */25EXTRA, /* i: waiting for extra bytes (gzip) */26NAME, /* i: waiting for end of file name (gzip) */27COMMENT, /* i: waiting for end of comment (gzip) */28HCRC, /* i: waiting for header crc (gzip) */29DICTID, /* i: waiting for dictionary check value */30DICT, /* waiting for inflateSetDictionary() call */31TYPE, /* i: waiting for type bits, including last-flag bit */32TYPEDO, /* i: same, but skip check to exit inflate on new block */33STORED, /* i: waiting for stored size (length and complement) */34COPY_, /* i/o: same as COPY below, but only first time in */35COPY, /* i/o: waiting for input or output to copy stored block */36TABLE, /* i: waiting for dynamic block table lengths */37LENLENS, /* i: waiting for code length code lengths */38CODELENS, /* i: waiting for length/lit and distance code lengths */39LEN_, /* i: same as LEN below, but only first time in */40LEN, /* i: waiting for length/lit/eob code */41LENEXT, /* i: waiting for length extra bits */42DIST, /* i: waiting for distance code */43DISTEXT, /* i: waiting for distance extra bits */44MATCH, /* o: waiting for output space to copy string */45LIT, /* o: waiting for output space to write literal */46CHECK, /* i: waiting for 32-bit check value */47LENGTH, /* i: waiting for 32-bit length (gzip) */48DONE, /* finished check, done -- remain here until reset */49BAD, /* got a data error -- remain here until reset */50MEM, /* got an inflate() memory error -- remain here until reset */51SYNC /* looking for synchronization bytes to restart inflate() */52} inflate_mode;5354/*55State transitions between above modes -5657(most modes can go to BAD or MEM on error -- not shown for clarity)5859Process header:60HEAD -> (gzip) or (zlib) or (raw)61(gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME -> COMMENT ->62HCRC -> TYPE63(zlib) -> DICTID or TYPE64DICTID -> DICT -> TYPE65(raw) -> TYPEDO66Read deflate blocks:67TYPE -> TYPEDO -> STORED or TABLE or LEN_ or CHECK68STORED -> COPY_ -> COPY -> TYPE69TABLE -> LENLENS -> CODELENS -> LEN_70LEN_ -> LEN71Read deflate codes in fixed or dynamic block:72LEN -> LENEXT or LIT or TYPE73LENEXT -> DIST -> DISTEXT -> MATCH -> LEN74LIT -> LEN75Process trailer:76CHECK -> LENGTH -> DONE77*/7879/* State maintained between inflate() calls -- approximately 7K bytes, not80including the allocated sliding window, which is up to 32K bytes. */81struct inflate_state {82z_streamp strm; /* pointer back to this zlib stream */83inflate_mode mode; /* current inflate mode */84int last; /* true if processing last block */85int wrap; /* bit 0 true for zlib, bit 1 true for gzip,86bit 2 true to validate check value */87int havedict; /* true if dictionary provided */88int flags; /* gzip header method and flags, 0 if zlib, or89-1 if raw or no header yet */90unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */91unsigned long check; /* protected copy of check value */92unsigned long total; /* protected copy of output count */93gz_headerp head; /* where to save gzip header information */94/* sliding window */95unsigned wbits; /* log base 2 of requested window size */96unsigned wsize; /* window size or zero if not using window */97unsigned whave; /* valid bytes in the window */98unsigned wnext; /* window write index */99unsigned char FAR *window; /* allocated sliding window, if needed */100/* bit accumulator */101unsigned long hold; /* input bit accumulator */102unsigned bits; /* number of bits in "in" */103/* for string and stored block copying */104unsigned length; /* literal or length of data to copy */105unsigned offset; /* distance back to copy string from */106/* for table and code decoding */107unsigned extra; /* extra bits needed */108/* fixed and dynamic code tables */109code const FAR *lencode; /* starting table for length/literal codes */110code const FAR *distcode; /* starting table for distance codes */111unsigned lenbits; /* index bits for lencode */112unsigned distbits; /* index bits for distcode */113/* dynamic table building */114unsigned ncode; /* number of code length code lengths */115unsigned nlen; /* number of length code lengths */116unsigned ndist; /* number of distance code lengths */117unsigned have; /* number of code lengths in lens[] */118code FAR *next; /* next available space in codes[] */119unsigned short lens[320]; /* temporary storage for code lengths */120unsigned short work[288]; /* work area for code table building */121code codes[ENOUGH]; /* space for code tables */122int sane; /* if false, allow invalid distance too far */123int back; /* bits back of last unprocessed length/lit */124unsigned was; /* initial length of match */125};126127128