Path: blob/master/src/java.base/share/native/libzip/zlib/inflate.h
41153 views
/*1* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.2*3* This code is free software; you can redistribute it and/or modify it4* under the terms of the GNU General Public License version 2 only, as5* published by the Free Software Foundation. Oracle designates this6* particular file as subject to the "Classpath" exception as provided7* by Oracle in the LICENSE file that accompanied this code.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 2 along with this work; if not, write to the Free Software Foundation,17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18*19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*/2324/* inflate.h -- internal inflate state definition25* Copyright (C) 1995-2016 Mark Adler26* For conditions of distribution and use, see copyright notice in zlib.h27*/2829/* WARNING: this file should *not* be used by applications. It is30part of the implementation of the compression library and is31subject to change. Applications should only use zlib.h.32*/3334/* define NO_GZIP when compiling if you want to disable gzip header and35trailer decoding by inflate(). NO_GZIP would be used to avoid linking in36the crc code when it is not needed. For shared libraries, gzip decoding37should be left enabled. */38#ifndef NO_GZIP39# define GUNZIP40#endif4142/* Possible inflate modes between inflate() calls */43typedef enum {44HEAD = 16180, /* i: waiting for magic header */45FLAGS, /* i: waiting for method and flags (gzip) */46TIME, /* i: waiting for modification time (gzip) */47OS, /* i: waiting for extra flags and operating system (gzip) */48EXLEN, /* i: waiting for extra length (gzip) */49EXTRA, /* i: waiting for extra bytes (gzip) */50NAME, /* i: waiting for end of file name (gzip) */51COMMENT, /* i: waiting for end of comment (gzip) */52HCRC, /* i: waiting for header crc (gzip) */53DICTID, /* i: waiting for dictionary check value */54DICT, /* waiting for inflateSetDictionary() call */55TYPE, /* i: waiting for type bits, including last-flag bit */56TYPEDO, /* i: same, but skip check to exit inflate on new block */57STORED, /* i: waiting for stored size (length and complement) */58COPY_, /* i/o: same as COPY below, but only first time in */59COPY, /* i/o: waiting for input or output to copy stored block */60TABLE, /* i: waiting for dynamic block table lengths */61LENLENS, /* i: waiting for code length code lengths */62CODELENS, /* i: waiting for length/lit and distance code lengths */63LEN_, /* i: same as LEN below, but only first time in */64LEN, /* i: waiting for length/lit/eob code */65LENEXT, /* i: waiting for length extra bits */66DIST, /* i: waiting for distance code */67DISTEXT, /* i: waiting for distance extra bits */68MATCH, /* o: waiting for output space to copy string */69LIT, /* o: waiting for output space to write literal */70CHECK, /* i: waiting for 32-bit check value */71LENGTH, /* i: waiting for 32-bit length (gzip) */72DONE, /* finished check, done -- remain here until reset */73BAD, /* got a data error -- remain here until reset */74MEM, /* got an inflate() memory error -- remain here until reset */75SYNC /* looking for synchronization bytes to restart inflate() */76} inflate_mode;7778/*79State transitions between above modes -8081(most modes can go to BAD or MEM on error -- not shown for clarity)8283Process header:84HEAD -> (gzip) or (zlib) or (raw)85(gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME -> COMMENT ->86HCRC -> TYPE87(zlib) -> DICTID or TYPE88DICTID -> DICT -> TYPE89(raw) -> TYPEDO90Read deflate blocks:91TYPE -> TYPEDO -> STORED or TABLE or LEN_ or CHECK92STORED -> COPY_ -> COPY -> TYPE93TABLE -> LENLENS -> CODELENS -> LEN_94LEN_ -> LEN95Read deflate codes in fixed or dynamic block:96LEN -> LENEXT or LIT or TYPE97LENEXT -> DIST -> DISTEXT -> MATCH -> LEN98LIT -> LEN99Process trailer:100CHECK -> LENGTH -> DONE101*/102103/* State maintained between inflate() calls -- approximately 7K bytes, not104including the allocated sliding window, which is up to 32K bytes. */105struct inflate_state {106z_streamp strm; /* pointer back to this zlib stream */107inflate_mode mode; /* current inflate mode */108int last; /* true if processing last block */109int wrap; /* bit 0 true for zlib, bit 1 true for gzip,110bit 2 true to validate check value */111int havedict; /* true if dictionary provided */112int flags; /* gzip header method and flags (0 if zlib) */113unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */114unsigned long check; /* protected copy of check value */115unsigned long total; /* protected copy of output count */116gz_headerp head; /* where to save gzip header information */117/* sliding window */118unsigned wbits; /* log base 2 of requested window size */119unsigned wsize; /* window size or zero if not using window */120unsigned whave; /* valid bytes in the window */121unsigned wnext; /* window write index */122unsigned char FAR *window; /* allocated sliding window, if needed */123/* bit accumulator */124unsigned long hold; /* input bit accumulator */125unsigned bits; /* number of bits in "in" */126/* for string and stored block copying */127unsigned length; /* literal or length of data to copy */128unsigned offset; /* distance back to copy string from */129/* for table and code decoding */130unsigned extra; /* extra bits needed */131/* fixed and dynamic code tables */132code const FAR *lencode; /* starting table for length/literal codes */133code const FAR *distcode; /* starting table for distance codes */134unsigned lenbits; /* index bits for lencode */135unsigned distbits; /* index bits for distcode */136/* dynamic table building */137unsigned ncode; /* number of code length code lengths */138unsigned nlen; /* number of length code lengths */139unsigned ndist; /* number of distance code lengths */140unsigned have; /* number of code lengths in lens[] */141code FAR *next; /* next available space in codes[] */142unsigned short lens[320]; /* temporary storage for code lengths */143unsigned short work[288]; /* work area for code table building */144code codes[ENOUGH]; /* space for code tables */145int sane; /* if false, allow invalid distance too far */146int back; /* bits back of last unprocessed length/lit */147unsigned was; /* initial length of match */148};149150151