ReactOS 0.4.15-dev-7654-g6bc40d3
inflate.c File Reference
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include "winternl.h"
#include "zlib.h"
Include dependency graph for inflate.c:

Go to the source code of this file.

Classes

struct  code
 
struct  inflate_state
 

Macros

#define DEF_WBITS   MAX_WBITS
 
#define zmemcpy   memcpy
 
#define zmemzero(dest, len)   memset(dest, 0, len)
 
#define Assert(cond, msg)
 
#define Trace(x)
 
#define Tracev(x)
 
#define Tracevv(x)
 
#define Tracecv(c, x)
 
#define GUNZIP
 
#define ZALLOC(strm, items, size)    (*((strm)->zalloc))((strm)->opaque, (items), (size))
 
#define ZFREE(strm, addr)   (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
 
#define TRY_FREE(s, p)   {if (p) ZFREE(s, p);}
 
#define ZSWAP32(q)
 
#define BASE   65521U /* largest prime smaller than 65536 */
 
#define NMAX   5552
 
#define DO1(buf, i)   {adler += (buf)[i]; sum2 += adler;}
 
#define DO2(buf, i)   DO1(buf,i); DO1(buf,i+1);
 
#define DO4(buf, i)   DO2(buf,i); DO2(buf,i+2);
 
#define DO8(buf, i)   DO4(buf,i); DO4(buf,i+4);
 
#define DO16(buf)   DO8(buf,0); DO8(buf,8);
 
#define MOD(a)   a %= BASE
 
#define MOD28(a)   a %= BASE
 
#define MOD63(a)   a %= BASE
 
#define ENOUGH_LENS   852
 
#define ENOUGH_DISTS   592
 
#define ENOUGH   (ENOUGH_LENS+ENOUGH_DISTS)
 
#define MAXBITS   15
 
#define crc32(crc, buf, len)   RtlComputeCrc32(crc,buf,len)
 
#define UPDATE(check, buf, len)    (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
 
#define CRC2(check, word)
 
#define CRC4(check, word)
 
#define LOAD()
 
#define RESTORE()
 
#define INITBITS()
 
#define PULLBYTE()
 
#define NEEDBITS(n)
 
#define BITS(n)    ((unsigned)hold & ((1U << (n)) - 1))
 
#define DROPBITS(n)
 
#define BYTEBITS()
 

Enumerations

enum  codetype {
  CODES , LENS , DISTS , CODES ,
  LENS , DISTS , CODES , LENS ,
  DISTS
}
 
enum  inflate_mode {
  HEAD = 16180 , FLAGS , TIME , OS ,
  EXLEN , EXTRA , NAME , COMMENT ,
  HCRC , DICTID , DICT , TYPE ,
  TYPEDO , STORED , COPY_ , COPY ,
  TABLE , LENLENS , CODELENS , LEN_ ,
  LEN , LENEXT , DIST , DISTEXT ,
  MATCH , LIT , CHECK , LENGTH ,
  DONE , BAD , MEM , SYNC ,
  HEAD = 16180 , FLAGS , TIME , OS ,
  EXLEN , EXTRA , NAME , COMMENT ,
  HCRC , DICTID , DICT , TYPE ,
  TYPEDO , STORED , COPY_ , COPY ,
  TABLE , LENLENS , CODELENS , LEN_ ,
  LEN , LENEXT , DIST , DISTEXT ,
  MATCH , LIT , CHECK , LENGTH ,
  DONE , BAD , MEM , SYNC ,
  METHOD , FLAG , DICT4 , DICT3 ,
  DICT2 , DICT1 , DICT0 , BLOCKS ,
  CHECK4 , CHECK3 , CHECK2 , CHECK1 ,
  DONE , BAD , HEAD = 16180 , FLAGS ,
  TIME , OS , EXLEN , EXTRA ,
  NAME , COMMENT , HCRC , DICTID ,
  DICT , TYPE , TYPEDO , STORED ,
  COPY_ , COPY , TABLE , LENLENS ,
  CODELENS , LEN_ , LEN , LENEXT ,
  DIST , DISTEXT , MATCH , LIT ,
  CHECK , LENGTH , DONE , BAD ,
  MEM , SYNC
}
 

Functions

static uLong adler32 (uLong adler, const Bytef *buf, uInt len)
 
static void inflate_fast (z_streamp strm, unsigned start)
 
static int inflate_table (codetype type, unsigned short FAR *lens, unsigned codes, code FAR *FAR *table, unsigned FAR *bits, unsigned short FAR *work)
 
static int inflateStateCheck (z_streamp strm)
 
static int inflateResetKeep (z_streamp strm)
 
static int inflateReset (z_streamp strm)
 
static int inflateReset2 (z_streamp strm, int windowBits)
 
int inflateInit2 (z_streamp strm, int windowBits)
 
int inflateInit (z_streamp strm)
 
static void fixedtables (struct inflate_state FAR *state)
 
static int updatewindow (z_streamp strm, const Bytef *end, unsigned copy)
 
int inflate (z_streamp strm, int flush)
 
int inflateEnd (z_streamp strm)
 

Macro Definition Documentation

◆ Assert

#define Assert (   cond,
  msg 
)

Definition at line 36 of file inflate.c.

◆ BASE

#define BASE   65521U /* largest prime smaller than 65536 */

Definition at line 53 of file inflate.c.

◆ BITS

#define BITS (   n)     ((unsigned)hold & ((1U << (n)) - 1))

Definition at line 1153 of file inflate.c.

◆ BYTEBITS

#define BYTEBITS ( )
Value:
do { \
hold >>= bits & 7; \
bits -= bits & 7; \
} while (0)
GLenum GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * bits
Definition: glext.h:10929

Definition at line 1164 of file inflate.c.

◆ CRC2

#define CRC2 (   check,
  word 
)
Value:
do { \
hbuf[0] = (unsigned char)(word); \
hbuf[1] = (unsigned char)((word) >> 8); \
check = crc32(check, hbuf, 2); \
} while (0)
#define crc32(crc, buf, len)
Definition: inflate.c:1081
unsigned char
Definition: typeof.h:29
#define check(expected, result)
Definition: dplayx.c:32
const WCHAR * word
Definition: lex.c:36

Definition at line 1088 of file inflate.c.

◆ crc32

#define crc32 (   crc,
  buf,
  len 
)    RtlComputeCrc32(crc,buf,len)

Definition at line 1076 of file inflate.c.

◆ CRC4

#define CRC4 (   check,
  word 
)
Value:
do { \
hbuf[0] = (unsigned char)(word); \
hbuf[1] = (unsigned char)((word) >> 8); \
hbuf[2] = (unsigned char)((word) >> 16); \
hbuf[3] = (unsigned char)((word) >> 24); \
check = crc32(check, hbuf, 4); \
} while (0)

Definition at line 1095 of file inflate.c.

◆ DEF_WBITS

#define DEF_WBITS   MAX_WBITS

Definition at line 32 of file inflate.c.

◆ DO1

#define DO1 (   buf,
  i 
)    {adler += (buf)[i]; sum2 += adler;}

Definition at line 57 of file inflate.c.

◆ DO16

#define DO16 (   buf)    DO8(buf,0); DO8(buf,8);

Definition at line 61 of file inflate.c.

◆ DO2

#define DO2 (   buf,
  i 
)    DO1(buf,i); DO1(buf,i+1);

Definition at line 58 of file inflate.c.

◆ DO4

#define DO4 (   buf,
  i 
)    DO2(buf,i); DO2(buf,i+2);

Definition at line 59 of file inflate.c.

◆ DO8

#define DO8 (   buf,
  i 
)    DO4(buf,i); DO4(buf,i+4);

Definition at line 60 of file inflate.c.

◆ DROPBITS

#define DROPBITS (   n)
Value:
do { \
hold >>= (n); \
bits -= (unsigned)(n); \
} while (0)
GLdouble n
Definition: glext.h:7729
static unsigned(__cdecl *hash_bstr)(bstr_t s)

Definition at line 1157 of file inflate.c.

◆ ENOUGH

Definition at line 142 of file inflate.c.

◆ ENOUGH_DISTS

#define ENOUGH_DISTS   592

Definition at line 141 of file inflate.c.

◆ ENOUGH_LENS

#define ENOUGH_LENS   852

Definition at line 140 of file inflate.c.

◆ GUNZIP

#define GUNZIP

Definition at line 42 of file inflate.c.

◆ INITBITS

#define INITBITS ( )
Value:
do { \
hold = 0; \
bits = 0; \
} while (0)

Definition at line 1128 of file inflate.c.

◆ LOAD

#define LOAD ( )
Value:
do { \
put = strm->next_out; \
left = strm->avail_out; \
next = strm->next_in; \
have = strm->avail_in; \
hold = state->hold; \
bits = state->bits; \
} while (0)
static int state
Definition: maze.c:121
GLint left
Definition: glext.h:7726
#define put(ret, state, sp, n)
Definition: match.c:105
static unsigned __int64 next
Definition: rand_nt.c:6

Definition at line 1106 of file inflate.c.

◆ MAXBITS

#define MAXBITS   15

Definition at line 526 of file inflate.c.

◆ MOD

#define MOD (   a)    a %= BASE

Definition at line 63 of file inflate.c.

◆ MOD28

#define MOD28 (   a)    a %= BASE

Definition at line 64 of file inflate.c.

◆ MOD63

#define MOD63 (   a)    a %= BASE

Definition at line 65 of file inflate.c.

◆ NEEDBITS

#define NEEDBITS (   n)
Value:
do { \
while (bits < (unsigned)(n)) \
PULLBYTE(); \
} while (0)

Definition at line 1146 of file inflate.c.

◆ NMAX

#define NMAX   5552

Definition at line 54 of file inflate.c.

◆ PULLBYTE

#define PULLBYTE ( )
Value:
do { \
if (have == 0) goto inf_leave; \
have--; \
hold += (unsigned long)(*next++) << bits; \
bits += 8; \
} while (0)
while(CdLookupNextInitialFileDirent(IrpContext, Fcb, FileContext))

Definition at line 1136 of file inflate.c.

◆ RESTORE

#define RESTORE ( )
Value:
do { \
strm->next_out = put; \
strm->avail_out = left; \
strm->next_in = next; \
strm->avail_in = have; \
state->hold = hold; \
state->bits = bits; \
} while (0)
#define bits
Definition: infblock.c:15

Definition at line 1117 of file inflate.c.

◆ Trace

#define Trace (   x)

Definition at line 37 of file inflate.c.

◆ Tracecv

#define Tracecv (   c,
  x 
)

Definition at line 40 of file inflate.c.

◆ Tracev

#define Tracev (   x)

Definition at line 38 of file inflate.c.

◆ Tracevv

#define Tracevv (   x)

Definition at line 39 of file inflate.c.

◆ TRY_FREE

#define TRY_FREE (   s,
  p 
)    {if (p) ZFREE(s, p);}

Definition at line 47 of file inflate.c.

◆ UPDATE

#define UPDATE (   check,
  buf,
  len 
)     (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))

Definition at line 1080 of file inflate.c.

◆ ZALLOC

#define ZALLOC (   strm,
  items,
  size 
)     (*((strm)->zalloc))((strm)->opaque, (items), (size))

Definition at line 44 of file inflate.c.

◆ ZFREE

#define ZFREE (   strm,
  addr 
)    (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))

Definition at line 46 of file inflate.c.

◆ zmemcpy

#define zmemcpy   memcpy

Definition at line 33 of file inflate.c.

◆ zmemzero

#define zmemzero (   dest,
  len 
)    memset(dest, 0, len)

Definition at line 34 of file inflate.c.

◆ ZSWAP32

#define ZSWAP32 (   q)
Value:
((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
(((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063

Definition at line 50 of file inflate.c.

Enumeration Type Documentation

◆ codetype

Enumerator
CODES 
LENS 
DISTS 
CODES 
LENS 
DISTS 
CODES 
LENS 
DISTS 

Definition at line 145 of file inflate.c.

145 {
146 CODES,
147 LENS,
148 DISTS
149} codetype;
codetype
Definition: inflate.c:150
@ CODES
Definition: inflate.c:151
@ LENS
Definition: inflate.c:152
@ DISTS
Definition: inflate.c:153

◆ inflate_mode

Enumerator
HEAD 
FLAGS 
TIME 
OS 
EXLEN 
EXTRA 
NAME 
COMMENT 
HCRC 
DICTID 
DICT 
TYPE 
TYPEDO 
STORED 
COPY_ 
COPY 
TABLE 
LENLENS 
CODELENS 
LEN_ 
LEN 
LENEXT 
DIST 
DISTEXT 
MATCH 
LIT 
CHECK 
LENGTH 
DONE 
BAD 
MEM 
SYNC 
HEAD 
FLAGS 
TIME 
OS 
EXLEN 
EXTRA 
NAME 
COMMENT 
HCRC 
DICTID 
DICT 
TYPE 
TYPEDO 
STORED 
COPY_ 
COPY 
TABLE 
LENLENS 
CODELENS 
LEN_ 
LEN 
LENEXT 
DIST 
DISTEXT 
MATCH 
LIT 
CHECK 
LENGTH 
DONE 
BAD 
MEM 
SYNC 
METHOD 
FLAG 
DICT4 
DICT3 
DICT2 
DICT1 
DICT0 
BLOCKS 
CHECK4 
CHECK3 
CHECK2 
CHECK1 
DONE 
BAD 
HEAD 
FLAGS 
TIME 
OS 
EXLEN 
EXTRA 
NAME 
COMMENT 
HCRC 
DICTID 
DICT 
TYPE 
TYPEDO 
STORED 
COPY_ 
COPY 
TABLE 
LENLENS 
CODELENS 
LEN_ 
LEN 
LENEXT 
DIST 
DISTEXT 
MATCH 
LIT 
CHECK 
LENGTH 
DONE 
BAD 
MEM 
SYNC 

Definition at line 152 of file inflate.c.

152 {
153 HEAD = 16180, /* i: waiting for magic header */
154 FLAGS, /* i: waiting for method and flags (gzip) */
155 TIME, /* i: waiting for modification time (gzip) */
156 OS, /* i: waiting for extra flags and operating system (gzip) */
157 EXLEN, /* i: waiting for extra length (gzip) */
158 EXTRA, /* i: waiting for extra bytes (gzip) */
159 NAME, /* i: waiting for end of file name (gzip) */
160 COMMENT, /* i: waiting for end of comment (gzip) */
161 HCRC, /* i: waiting for header crc (gzip) */
162 DICTID, /* i: waiting for dictionary check value */
163 DICT, /* waiting for inflateSetDictionary() call */
164 TYPE, /* i: waiting for type bits, including last-flag bit */
165 TYPEDO, /* i: same, but skip check to exit inflate on new block */
166 STORED, /* i: waiting for stored size (length and complement) */
167 COPY_, /* i/o: same as COPY below, but only first time in */
168 COPY, /* i/o: waiting for input or output to copy stored block */
169 TABLE, /* i: waiting for dynamic block table lengths */
170 LENLENS, /* i: waiting for code length code lengths */
171 CODELENS, /* i: waiting for length/lit and distance code lengths */
172 LEN_, /* i: same as LEN below, but only first time in */
173 LEN, /* i: waiting for length/lit/eob code */
174 LENEXT, /* i: waiting for length extra bits */
175 DIST, /* i: waiting for distance code */
176 DISTEXT, /* i: waiting for distance extra bits */
177 MATCH, /* o: waiting for output space to copy string */
178 LIT, /* o: waiting for output space to write literal */
179 CHECK, /* i: waiting for 32-bit check value */
180 LENGTH, /* i: waiting for 32-bit length (gzip) */
181 DONE, /* finished check, done -- remain here until reset */
182 BAD, /* got a data error -- remain here until reset */
183 MEM, /* got an inflate() memory error -- remain here until reset */
184 SYNC /* looking for synchronization bytes to restart inflate() */
inflate_mode
Definition: inflate.c:157
@ MATCH
Definition: inflate.c:182
@ DICT
Definition: inflate.c:168
@ TABLE
Definition: inflate.c:174
@ LENGTH
Definition: inflate.c:185
@ FLAGS
Definition: inflate.c:159
@ LIT
Definition: inflate.c:183
@ SYNC
Definition: inflate.c:189
@ OS
Definition: inflate.c:161
@ EXLEN
Definition: inflate.c:162
@ MEM
Definition: inflate.c:188
@ NAME
Definition: inflate.c:164
@ STORED
Definition: inflate.c:171
@ CODELENS
Definition: inflate.c:176
@ DICTID
Definition: inflate.c:167
@ DONE
Definition: inflate.c:186
@ TYPEDO
Definition: inflate.c:170
@ COMMENT
Definition: inflate.c:165
@ LENLENS
Definition: inflate.c:175
@ TYPE
Definition: inflate.c:169
@ COPY
Definition: inflate.c:173
@ LEN_
Definition: inflate.c:177
@ COPY_
Definition: inflate.c:172
@ DIST
Definition: inflate.c:180
@ LENEXT
Definition: inflate.c:179
@ HCRC
Definition: inflate.c:166
@ TIME
Definition: inflate.c:160
@ CHECK
Definition: inflate.c:184
@ DISTEXT
Definition: inflate.c:181
@ BAD
Definition: inflate.c:187
@ LEN
Definition: inflate.c:178
@ EXTRA
Definition: inflate.c:163
Definition: ntuser.h:180

Function Documentation

◆ adler32()

static uLong adler32 ( uLong  adler,
const Bytef buf,
uInt  len 
)
static

Definition at line 67 of file inflate.c.

68{
69 unsigned long sum2;
70 unsigned n;
71
72 /* split Adler-32 into component sums */
73 sum2 = (adler >> 16) & 0xffff;
74 adler &= 0xffff;
75
76 /* in case user likes doing a byte at a time, keep it fast */
77 if (len == 1) {
78 adler += buf[0];
79 if (adler >= BASE)
80 adler -= BASE;
81 sum2 += adler;
82 if (sum2 >= BASE)
83 sum2 -= BASE;
84 return adler | (sum2 << 16);
85 }
86
87 /* initial Adler-32 value (deferred check for len == 1 speed) */
88 if (buf == Z_NULL)
89 return 1L;
90
91 /* in case short lengths are provided, keep it somewhat fast */
92 if (len < 16) {
93 while (len--) {
94 adler += *buf++;
95 sum2 += adler;
96 }
97 if (adler >= BASE)
98 adler -= BASE;
99 MOD28(sum2); /* only added so many BASE's */
100 return adler | (sum2 << 16);
101 }
102
103 /* do length NMAX blocks -- requires just one modulo operation */
104 while (len >= NMAX) {
105 len -= NMAX;
106 n = NMAX / 16; /* NMAX is divisible by 16 */
107 do {
108 DO16(buf); /* 16 sums unrolled */
109 buf += 16;
110 } while (--n);
111 MOD(adler);
112 MOD(sum2);
113 }
114
115 /* do remaining bytes (less than NMAX, still just one modulo) */
116 if (len) { /* avoid modulos if none remaining */
117 while (len >= 16) {
118 len -= 16;
119 DO16(buf);
120 buf += 16;
121 }
122 while (len--) {
123 adler += *buf++;
124 sum2 += adler;
125 }
126 MOD(adler);
127 MOD(sum2);
128 }
129
130 /* return recombined sums */
131 return adler | (sum2 << 16);
132}
#define MOD28(a)
Definition: inflate.c:69
#define NMAX
Definition: inflate.c:59
#define DO16(buf)
Definition: inflate.c:66
#define BASE
Definition: inflate.c:58
#define MOD(a)
Definition: inflate.c:68
#define Z_NULL
Definition: zlib.h:149
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLenum GLsizei len
Definition: glext.h:6722

◆ fixedtables()

static void fixedtables ( struct inflate_state FAR state)
static

Definition at line 919 of file inflate.c.

920{
921 static const code lenfix[512] = {
922 {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48},
923 {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128},
924 {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59},
925 {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176},
926 {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20},
927 {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100},
928 {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8},
929 {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216},
930 {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76},
931 {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114},
932 {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2},
933 {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148},
934 {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42},
935 {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86},
936 {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15},
937 {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236},
938 {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62},
939 {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142},
940 {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31},
941 {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162},
942 {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25},
943 {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105},
944 {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4},
945 {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202},
946 {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69},
947 {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125},
948 {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13},
949 {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195},
950 {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35},
951 {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91},
952 {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19},
953 {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246},
954 {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55},
955 {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135},
956 {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99},
957 {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190},
958 {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16},
959 {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96},
960 {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6},
961 {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209},
962 {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72},
963 {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116},
964 {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4},
965 {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153},
966 {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44},
967 {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82},
968 {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11},
969 {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229},
970 {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58},
971 {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138},
972 {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51},
973 {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173},
974 {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30},
975 {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110},
976 {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0},
977 {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195},
978 {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65},
979 {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121},
980 {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9},
981 {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258},
982 {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37},
983 {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93},
984 {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23},
985 {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251},
986 {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51},
987 {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131},
988 {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67},
989 {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183},
990 {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23},
991 {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103},
992 {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9},
993 {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223},
994 {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79},
995 {0,9,255}
996 };
997
998 static const code distfix[32] = {
999 {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025},
1000 {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193},
1001 {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385},
1002 {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577},
1003 {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073},
1004 {22,5,193},{64,5,0}
1005 };
1006
1007 state->lencode = lenfix;
1008 state->lenbits = 9;
1009 state->distcode = distfix;
1010 state->distbits = 5;
1011}
Definition: inflate.c:139
static const code distfix[32]
Definition: inffixed.h:87
static const code lenfix[512]
Definition: inffixed.h:10

◆ inflate()

int inflate ( z_streamp  strm,
int  flush 
)

Definition at line 1252 of file inflate.c.

1253{
1254 struct inflate_state FAR *state;
1255 z_const unsigned char FAR *next; /* next input */
1256 unsigned char FAR *put; /* next output */
1257 unsigned have, left; /* available input and output */
1258 unsigned long hold; /* bit buffer */
1259 unsigned bits; /* bits in bit buffer */
1260 unsigned in, out; /* save starting available input and output */
1261 unsigned copy; /* number of stored or match bytes to copy */
1262 unsigned char FAR *from; /* where to copy match bytes from */
1263 code here; /* current decoding table entry */
1264 code last; /* parent table entry */
1265 unsigned len; /* length to copy for repeats, bits to drop */
1266 int ret; /* return code */
1267#ifdef GUNZIP
1268 unsigned char hbuf[4]; /* buffer for gzip header crc calculation */
1269#endif
1270 static const unsigned short order[19] = /* permutation of code lengths */
1271 {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
1272
1273 if (inflateStateCheck(strm) || strm->next_out == Z_NULL ||
1274 (strm->next_in == Z_NULL && strm->avail_in != 0))
1275 return Z_STREAM_ERROR;
1276
1277 state = (struct inflate_state FAR *)strm->state;
1278 if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */
1279 LOAD();
1280 in = have;
1281 out = left;
1282 ret = Z_OK;
1283 for (;;)
1284 switch (state->mode) {
1285 case HEAD:
1286 if (state->wrap == 0) {
1287 state->mode = TYPEDO;
1288 break;
1289 }
1290 NEEDBITS(16);
1291#ifdef GUNZIP
1292 if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */
1293 if (state->wbits == 0)
1294 state->wbits = 15;
1295 state->check = crc32(0L, Z_NULL, 0);
1296 CRC2(state->check, hold);
1297 INITBITS();
1298 state->mode = FLAGS;
1299 break;
1300 }
1301 state->flags = 0; /* expect zlib header */
1302 if (state->head != Z_NULL)
1303 state->head->done = -1;
1304 if (!(state->wrap & 1) || /* check if zlib header allowed */
1305#else
1306 if (
1307#endif
1308 ((BITS(8) << 8) + (hold >> 8)) % 31) {
1309 strm->msg = (char *)"incorrect header check";
1310 state->mode = BAD;
1311 break;
1312 }
1313 if (BITS(4) != Z_DEFLATED) {
1314 strm->msg = (char *)"unknown compression method";
1315 state->mode = BAD;
1316 break;
1317 }
1318 DROPBITS(4);
1319 len = BITS(4) + 8;
1320 if (state->wbits == 0)
1321 state->wbits = len;
1322 if (len > 15 || len > state->wbits) {
1323 strm->msg = (char *)"invalid window size";
1324 state->mode = BAD;
1325 break;
1326 }
1327 state->dmax = 1U << len;
1328 Tracev((stderr, "inflate: zlib header ok\n"));
1329 strm->adler = state->check = adler32(0L, Z_NULL, 0);
1330 state->mode = hold & 0x200 ? DICTID : TYPE;
1331 INITBITS();
1332 break;
1333#ifdef GUNZIP
1334 case FLAGS:
1335 NEEDBITS(16);
1336 state->flags = (int)(hold);
1337 if ((state->flags & 0xff) != Z_DEFLATED) {
1338 strm->msg = (char *)"unknown compression method";
1339 state->mode = BAD;
1340 break;
1341 }
1342 if (state->flags & 0xe000) {
1343 strm->msg = (char *)"unknown header flags set";
1344 state->mode = BAD;
1345 break;
1346 }
1347 if (state->head != Z_NULL)
1348 state->head->text = (int)((hold >> 8) & 1);
1349 if ((state->flags & 0x0200) && (state->wrap & 4))
1350 CRC2(state->check, hold);
1351 INITBITS();
1352 state->mode = TIME;
1353 case TIME:
1354 NEEDBITS(32);
1355 if (state->head != Z_NULL)
1356 state->head->time = hold;
1357 if ((state->flags & 0x0200) && (state->wrap & 4))
1358 CRC4(state->check, hold);
1359 INITBITS();
1360 state->mode = OS;
1361 case OS:
1362 NEEDBITS(16);
1363 if (state->head != Z_NULL) {
1364 state->head->xflags = (int)(hold & 0xff);
1365 state->head->os = (int)(hold >> 8);
1366 }
1367 if ((state->flags & 0x0200) && (state->wrap & 4))
1368 CRC2(state->check, hold);
1369 INITBITS();
1370 state->mode = EXLEN;
1371 case EXLEN:
1372 if (state->flags & 0x0400) {
1373 NEEDBITS(16);
1374 state->length = (unsigned)(hold);
1375 if (state->head != Z_NULL)
1376 state->head->extra_len = (unsigned)hold;
1377 if ((state->flags & 0x0200) && (state->wrap & 4))
1378 CRC2(state->check, hold);
1379 INITBITS();
1380 }
1381 else if (state->head != Z_NULL)
1382 state->head->extra = Z_NULL;
1383 state->mode = EXTRA;
1384 case EXTRA:
1385 if (state->flags & 0x0400) {
1386 copy = state->length;
1387 if (copy > have) copy = have;
1388 if (copy) {
1389 if (state->head != Z_NULL &&
1390 state->head->extra != Z_NULL) {
1391 len = state->head->extra_len - state->length;
1392 zmemcpy(state->head->extra + len, next,
1393 len + copy > state->head->extra_max ?
1394 state->head->extra_max - len : copy);
1395 }
1396 if ((state->flags & 0x0200) && (state->wrap & 4))
1397 state->check = crc32(state->check, next, copy);
1398 have -= copy;
1399 next += copy;
1400 state->length -= copy;
1401 }
1402 if (state->length) goto inf_leave;
1403 }
1404 state->length = 0;
1405 state->mode = NAME;
1406 case NAME:
1407 if (state->flags & 0x0800) {
1408 if (have == 0) goto inf_leave;
1409 copy = 0;
1410 do {
1411 len = (unsigned)(next[copy++]);
1412 if (state->head != Z_NULL &&
1413 state->head->name != Z_NULL &&
1414 state->length < state->head->name_max)
1415 state->head->name[state->length++] = (Bytef)len;
1416 } while (len && copy < have);
1417 if ((state->flags & 0x0200) && (state->wrap & 4))
1418 state->check = crc32(state->check, next, copy);
1419 have -= copy;
1420 next += copy;
1421 if (len) goto inf_leave;
1422 }
1423 else if (state->head != Z_NULL)
1424 state->head->name = Z_NULL;
1425 state->length = 0;
1426 state->mode = COMMENT;
1427 case COMMENT:
1428 if (state->flags & 0x1000) {
1429 if (have == 0) goto inf_leave;
1430 copy = 0;
1431 do {
1432 len = (unsigned)(next[copy++]);
1433 if (state->head != Z_NULL &&
1434 state->head->comment != Z_NULL &&
1435 state->length < state->head->comm_max)
1436 state->head->comment[state->length++] = (Bytef)len;
1437 } while (len && copy < have);
1438 if ((state->flags & 0x0200) && (state->wrap & 4))
1439 state->check = crc32(state->check, next, copy);
1440 have -= copy;
1441 next += copy;
1442 if (len) goto inf_leave;
1443 }
1444 else if (state->head != Z_NULL)
1445 state->head->comment = Z_NULL;
1446 state->mode = HCRC;
1447 case HCRC:
1448 if (state->flags & 0x0200) {
1449 NEEDBITS(16);
1450 if ((state->wrap & 4) && hold != (state->check & 0xffff)) {
1451 strm->msg = (char *)"header crc mismatch";
1452 state->mode = BAD;
1453 break;
1454 }
1455 INITBITS();
1456 }
1457 if (state->head != Z_NULL) {
1458 state->head->hcrc = (int)((state->flags >> 9) & 1);
1459 state->head->done = 1;
1460 }
1461 strm->adler = state->check = crc32(0L, Z_NULL, 0);
1462 state->mode = TYPE;
1463 break;
1464#endif
1465 case DICTID:
1466 NEEDBITS(32);
1467 strm->adler = state->check = ZSWAP32(hold);
1468 INITBITS();
1469 state->mode = DICT;
1470 case DICT:
1471 if (state->havedict == 0) {
1472 RESTORE();
1473 return Z_NEED_DICT;
1474 }
1475 strm->adler = state->check = adler32(0L, Z_NULL, 0);
1476 state->mode = TYPE;
1477 case TYPE:
1478 if (flush == Z_BLOCK || flush == Z_TREES) goto inf_leave;
1479 case TYPEDO:
1480 if (state->last) {
1481 BYTEBITS();
1482 state->mode = CHECK;
1483 break;
1484 }
1485 NEEDBITS(3);
1486 state->last = BITS(1);
1487 DROPBITS(1);
1488 switch (BITS(2)) {
1489 case 0: /* stored block */
1490 Tracev((stderr, "inflate: stored block%s\n",
1491 state->last ? " (last)" : ""));
1492 state->mode = STORED;
1493 break;
1494 case 1: /* fixed block */
1496 Tracev((stderr, "inflate: fixed codes block%s\n",
1497 state->last ? " (last)" : ""));
1498 state->mode = LEN_; /* decode codes */
1499 if (flush == Z_TREES) {
1500 DROPBITS(2);
1501 goto inf_leave;
1502 }
1503 break;
1504 case 2: /* dynamic block */
1505 Tracev((stderr, "inflate: dynamic codes block%s\n",
1506 state->last ? " (last)" : ""));
1507 state->mode = TABLE;
1508 break;
1509 case 3:
1510 strm->msg = (char *)"invalid block type";
1511 state->mode = BAD;
1512 }
1513 DROPBITS(2);
1514 break;
1515 case STORED:
1516 BYTEBITS(); /* go to byte boundary */
1517 NEEDBITS(32);
1518 if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
1519 strm->msg = (char *)"invalid stored block lengths";
1520 state->mode = BAD;
1521 break;
1522 }
1523 state->length = (unsigned)hold & 0xffff;
1524 Tracev((stderr, "inflate: stored length %u\n",
1525 state->length));
1526 INITBITS();
1527 state->mode = COPY_;
1528 if (flush == Z_TREES) goto inf_leave;
1529 case COPY_:
1530 state->mode = COPY;
1531 case COPY:
1532 copy = state->length;
1533 if (copy) {
1534 if (copy > have) copy = have;
1535 if (copy > left) copy = left;
1536 if (copy == 0) goto inf_leave;
1537 zmemcpy(put, next, copy);
1538 have -= copy;
1539 next += copy;
1540 left -= copy;
1541 put += copy;
1542 state->length -= copy;
1543 break;
1544 }
1545 Tracev((stderr, "inflate: stored end\n"));
1546 state->mode = TYPE;
1547 break;
1548 case TABLE:
1549 NEEDBITS(14);
1550 state->nlen = BITS(5) + 257;
1551 DROPBITS(5);
1552 state->ndist = BITS(5) + 1;
1553 DROPBITS(5);
1554 state->ncode = BITS(4) + 4;
1555 DROPBITS(4);
1556#ifndef PKZIP_BUG_WORKAROUND
1557 if (state->nlen > 286 || state->ndist > 30) {
1558 strm->msg = (char *)"too many length or distance symbols";
1559 state->mode = BAD;
1560 break;
1561 }
1562#endif
1563 Tracev((stderr, "inflate: table sizes ok\n"));
1564 state->have = 0;
1565 state->mode = LENLENS;
1566 case LENLENS:
1567 while (state->have < state->ncode) {
1568 NEEDBITS(3);
1569 state->lens[order[state->have++]] = (unsigned short)BITS(3);
1570 DROPBITS(3);
1571 }
1572 while (state->have < 19)
1573 state->lens[order[state->have++]] = 0;
1574 state->next = state->codes;
1575 state->lencode = (const code FAR *)(state->next);
1576 state->lenbits = 7;
1577 ret = inflate_table(CODES, state->lens, 19, &(state->next),
1578 &(state->lenbits), state->work);
1579 if (ret) {
1580 strm->msg = (char *)"invalid code lengths set";
1581 state->mode = BAD;
1582 break;
1583 }
1584 Tracev((stderr, "inflate: code lengths ok\n"));
1585 state->have = 0;
1586 state->mode = CODELENS;
1587 case CODELENS:
1588 while (state->have < state->nlen + state->ndist) {
1589 for (;;) {
1590 here = state->lencode[BITS(state->lenbits)];
1591 if ((unsigned)(here.bits) <= bits) break;
1592 PULLBYTE();
1593 }
1594 if (here.val < 16) {
1595 DROPBITS(here.bits);
1596 state->lens[state->have++] = here.val;
1597 }
1598 else {
1599 if (here.val == 16) {
1600 NEEDBITS(here.bits + 2);
1601 DROPBITS(here.bits);
1602 if (state->have == 0) {
1603 strm->msg = (char *)"invalid bit length repeat";
1604 state->mode = BAD;
1605 break;
1606 }
1607 len = state->lens[state->have - 1];
1608 copy = 3 + BITS(2);
1609 DROPBITS(2);
1610 }
1611 else if (here.val == 17) {
1612 NEEDBITS(here.bits + 3);
1613 DROPBITS(here.bits);
1614 len = 0;
1615 copy = 3 + BITS(3);
1616 DROPBITS(3);
1617 }
1618 else {
1619 NEEDBITS(here.bits + 7);
1620 DROPBITS(here.bits);
1621 len = 0;
1622 copy = 11 + BITS(7);
1623 DROPBITS(7);
1624 }
1625 if (state->have + copy > state->nlen + state->ndist) {
1626 strm->msg = (char *)"invalid bit length repeat";
1627 state->mode = BAD;
1628 break;
1629 }
1630 while (copy--)
1631 state->lens[state->have++] = (unsigned short)len;
1632 }
1633 }
1634
1635 /* handle error breaks in while */
1636 if (state->mode == BAD) break;
1637
1638 /* check for end-of-block code (better have one) */
1639 if (state->lens[256] == 0) {
1640 strm->msg = (char *)"invalid code -- missing end-of-block";
1641 state->mode = BAD;
1642 break;
1643 }
1644
1645 /* build code tables -- note: do not change the lenbits or distbits
1646 values here (9 and 6) without reading the comments in inftrees.h
1647 concerning the ENOUGH constants, which depend on those values */
1648 state->next = state->codes;
1649 state->lencode = (const code FAR *)(state->next);
1650 state->lenbits = 9;
1651 ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
1652 &(state->lenbits), state->work);
1653 if (ret) {
1654 strm->msg = (char *)"invalid literal/lengths set";
1655 state->mode = BAD;
1656 break;
1657 }
1658 state->distcode = (const code FAR *)(state->next);
1659 state->distbits = 6;
1660 ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
1661 &(state->next), &(state->distbits), state->work);
1662 if (ret) {
1663 strm->msg = (char *)"invalid distances set";
1664 state->mode = BAD;
1665 break;
1666 }
1667 Tracev((stderr, "inflate: codes ok\n"));
1668 state->mode = LEN_;
1669 if (flush == Z_TREES) goto inf_leave;
1670 case LEN_:
1671 state->mode = LEN;
1672 case LEN:
1673 if (have >= 6 && left >= 258) {
1674 RESTORE();
1676 LOAD();
1677 if (state->mode == TYPE)
1678 state->back = -1;
1679 break;
1680 }
1681 state->back = 0;
1682 for (;;) {
1683 here = state->lencode[BITS(state->lenbits)];
1684 if ((unsigned)(here.bits) <= bits) break;
1685 PULLBYTE();
1686 }
1687 if (here.op && (here.op & 0xf0) == 0) {
1688 last = here;
1689 for (;;) {
1690 here = state->lencode[last.val +
1691 (BITS(last.bits + last.op) >> last.bits)];
1692 if ((unsigned)(last.bits + here.bits) <= bits) break;
1693 PULLBYTE();
1694 }
1695 DROPBITS(last.bits);
1696 state->back += last.bits;
1697 }
1698 DROPBITS(here.bits);
1699 state->back += here.bits;
1700 state->length = (unsigned)here.val;
1701 if ((int)(here.op) == 0) {
1702 Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
1703 "inflate: literal '%c'\n" :
1704 "inflate: literal 0x%02x\n", here.val));
1705 state->mode = LIT;
1706 break;
1707 }
1708 if (here.op & 32) {
1709 Tracevv((stderr, "inflate: end of block\n"));
1710 state->back = -1;
1711 state->mode = TYPE;
1712 break;
1713 }
1714 if (here.op & 64) {
1715 strm->msg = (char *)"invalid literal/length code";
1716 state->mode = BAD;
1717 break;
1718 }
1719 state->extra = (unsigned)(here.op) & 15;
1720 state->mode = LENEXT;
1721 case LENEXT:
1722 if (state->extra) {
1723 NEEDBITS(state->extra);
1724 state->length += BITS(state->extra);
1725 DROPBITS(state->extra);
1726 state->back += state->extra;
1727 }
1728 Tracevv((stderr, "inflate: length %u\n", state->length));
1729 state->was = state->length;
1730 state->mode = DIST;
1731 case DIST:
1732 for (;;) {
1733 here = state->distcode[BITS(state->distbits)];
1734 if ((unsigned)(here.bits) <= bits) break;
1735 PULLBYTE();
1736 }
1737 if ((here.op & 0xf0) == 0) {
1738 last = here;
1739 for (;;) {
1740 here = state->distcode[last.val +
1741 (BITS(last.bits + last.op) >> last.bits)];
1742 if ((unsigned)(last.bits + here.bits) <= bits) break;
1743 PULLBYTE();
1744 }
1745 DROPBITS(last.bits);
1746 state->back += last.bits;
1747 }
1748 DROPBITS(here.bits);
1749 state->back += here.bits;
1750 if (here.op & 64) {
1751 strm->msg = (char *)"invalid distance code";
1752 state->mode = BAD;
1753 break;
1754 }
1755 state->offset = (unsigned)here.val;
1756 state->extra = (unsigned)(here.op) & 15;
1757 state->mode = DISTEXT;
1758 case DISTEXT:
1759 if (state->extra) {
1760 NEEDBITS(state->extra);
1761 state->offset += BITS(state->extra);
1762 DROPBITS(state->extra);
1763 state->back += state->extra;
1764 }
1765#ifdef INFLATE_STRICT
1766 if (state->offset > state->dmax) {
1767 strm->msg = (char *)"invalid distance too far back";
1768 state->mode = BAD;
1769 break;
1770 }
1771#endif
1772 Tracevv((stderr, "inflate: distance %u\n", state->offset));
1773 state->mode = MATCH;
1774 case MATCH:
1775 if (left == 0) goto inf_leave;
1776 copy = out - left;
1777 if (state->offset > copy) { /* copy from window */
1778 copy = state->offset - copy;
1779 if (copy > state->whave) {
1780 if (state->sane) {
1781 strm->msg = (char *)"invalid distance too far back";
1782 state->mode = BAD;
1783 break;
1784 }
1785#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
1786 Trace((stderr, "inflate.c too far\n"));
1787 copy -= state->whave;
1788 if (copy > state->length) copy = state->length;
1789 if (copy > left) copy = left;
1790 left -= copy;
1791 state->length -= copy;
1792 do {
1793 *put++ = 0;
1794 } while (--copy);
1795 if (state->length == 0) state->mode = LEN;
1796 break;
1797#endif
1798 }
1799 if (copy > state->wnext) {
1800 copy -= state->wnext;
1801 from = state->window + (state->wsize - copy);
1802 }
1803 else
1804 from = state->window + (state->wnext - copy);
1805 if (copy > state->length) copy = state->length;
1806 }
1807 else { /* copy from output */
1808 from = put - state->offset;
1809 copy = state->length;
1810 }
1811 if (copy > left) copy = left;
1812 left -= copy;
1813 state->length -= copy;
1814 do {
1815 *put++ = *from++;
1816 } while (--copy);
1817 if (state->length == 0) state->mode = LEN;
1818 break;
1819 case LIT:
1820 if (left == 0) goto inf_leave;
1821 *put++ = (unsigned char)(state->length);
1822 left--;
1823 state->mode = LEN;
1824 break;
1825 case CHECK:
1826 if (state->wrap) {
1827 NEEDBITS(32);
1828 out -= left;
1829 strm->total_out += out;
1830 state->total += out;
1831 if ((state->wrap & 4) && out)
1832 strm->adler = state->check =
1833 UPDATE(state->check, put - out, out);
1834 out = left;
1835 if ((state->wrap & 4) && (
1836#ifdef GUNZIP
1837 state->flags ? hold :
1838#endif
1839 ZSWAP32(hold)) != state->check) {
1840 strm->msg = (char *)"incorrect data check";
1841 state->mode = BAD;
1842 break;
1843 }
1844 INITBITS();
1845 Tracev((stderr, "inflate: check matches trailer\n"));
1846 }
1847#ifdef GUNZIP
1848 state->mode = LENGTH;
1849 case LENGTH:
1850 if (state->wrap && state->flags) {
1851 NEEDBITS(32);
1852 if (hold != (state->total & 0xffffffffUL)) {
1853 strm->msg = (char *)"incorrect length check";
1854 state->mode = BAD;
1855 break;
1856 }
1857 INITBITS();
1858 Tracev((stderr, "inflate: length matches trailer\n"));
1859 }
1860#endif
1861 state->mode = DONE;
1862 case DONE:
1863 ret = Z_STREAM_END;
1864 goto inf_leave;
1865 case BAD:
1866 ret = Z_DATA_ERROR;
1867 goto inf_leave;
1868 case MEM:
1869 return Z_MEM_ERROR;
1870 case SYNC:
1871 default:
1872 return Z_STREAM_ERROR;
1873 }
1874
1875 /*
1876 Return from inflate(), updating the total counts and the check value.
1877 If there was no progress during the inflate() call, return a buffer
1878 error. Call updatewindow() to create and/or update the window state.
1879 Note: a memory error from inflate() is non-recoverable.
1880 */
1881 inf_leave:
1882 RESTORE();
1883 if (state->wsize || (out != strm->avail_out && state->mode < BAD &&
1884 (state->mode < CHECK || flush != Z_FINISH)))
1885 if (updatewindow(strm, strm->next_out, out - strm->avail_out)) {
1886 state->mode = MEM;
1887 return Z_MEM_ERROR;
1888 }
1889 in -= strm->avail_in;
1890 out -= strm->avail_out;
1891 strm->total_in += in;
1892 strm->total_out += out;
1893 state->total += out;
1894 if ((state->wrap & 4) && out)
1895 strm->adler = state->check =
1896 UPDATE(state->check, strm->next_out - out, out);
1897 strm->data_type = (int)state->bits + (state->last ? 64 : 0) +
1898 (state->mode == TYPE ? 128 : 0) +
1899 (state->mode == LEN_ || state->mode == COPY_ ? 256 : 0);
1900 if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK)
1901 ret = Z_BUF_ERROR;
1902 return ret;
1903}
INT copy(TCHAR source[MAX_PATH], TCHAR dest[MAX_PATH], INT append, DWORD lpdwFlags, BOOL bTouch)
Definition: copy.c:51
#define LOAD()
Definition: inflate.c:1111
@ HEAD
Definition: inflate.c:158
#define CRC2(check, word)
Definition: inflate.c:1093
#define zmemcpy
Definition: inflate.c:38
static int inflate_table(codetype type, unsigned short FAR *lens, unsigned codes, code FAR *FAR *table, unsigned FAR *bits, unsigned short FAR *work)
Definition: inflate.c:533
#define INITBITS()
Definition: inflate.c:1133
#define CRC4(check, word)
Definition: inflate.c:1100
#define BITS(n)
Definition: inflate.c:1158
static void inflate_fast(z_streamp strm, unsigned start)
Definition: inflate.c:274
#define UPDATE(check, buf, len)
Definition: inflate.c:1085
#define DROPBITS(n)
Definition: inflate.c:1162
static int inflateStateCheck(z_streamp strm)
Definition: inflate.c:802
#define Tracev(x)
Definition: inflate.c:43
static void fixedtables(struct inflate_state FAR *state)
Definition: inflate.c:924
#define Trace(x)
Definition: inflate.c:42
#define BYTEBITS()
Definition: inflate.c:1169
#define ZSWAP32(q)
Definition: inflate.c:55
static uLong adler32(uLong adler, const Bytef *buf, uInt len)
Definition: inflate.c:72
#define NEEDBITS(n)
Definition: inflate.c:1151
#define PULLBYTE()
Definition: inflate.c:1141
#define Tracevv(x)
Definition: inflate.c:44
#define GUNZIP
Definition: inflate.c:47
static int updatewindow(z_streamp strm, const Bytef *end, unsigned copy)
Definition: inflate.c:1032
#define RESTORE()
Definition: inflate.c:1122
#define Z_TREES
Definition: zlib.h:111
#define Z_DEFLATED
Definition: zlib.h:146
#define Z_NEED_DICT
Definition: zlib.h:116
#define Z_BUF_ERROR
Definition: zlib.h:121
#define Z_BLOCK
Definition: zlib.h:110
#define Z_STREAM_END
Definition: zlib.h:115
#define Z_FINISH
Definition: zlib.h:109
#define Z_OK
Definition: zlib.h:114
#define z_const
Definition: zlib.h:35
#define Z_DATA_ERROR
Definition: zlib.h:119
#define Z_STREAM_ERROR
Definition: zlib.h:118
#define Z_MEM_ERROR
Definition: zlib.h:120
Byte FAR Bytef
Definition: zlib.h:41
#define FAR
Definition: zlib.h:34
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
unsigned short(__cdecl typeof(TIFFCurrentDirectory))(struct tiff *)
Definition: typeof.h:94
TYPE
Definition: eventcreate.c:652
GLuint in
Definition: glext.h:9616
GLuint GLdouble GLdouble GLint GLint order
Definition: glext.h:11194
#define stderr
Definition: stdio.h:100
if(dx< 0)
Definition: linetemp.h:194
static UINT UINT last
Definition: font.c:45
#define L(x)
Definition: ntvdm.h:50
static FILE * out
Definition: regtests2xml.c:44
int flush
Definition: zlib.h:309
CardRegion * from
Definition: spigame.cpp:19
unsigned char op
Definition: inflate.c:140
unsigned char bits
Definition: inflate.c:141
unsigned short val
Definition: inflate.c:142
unsigned have
Definition: inflate.c:229
unsigned long hold
Definition: inflate.c:213
z_streamp strm
Definition: inflate.c:195
int ret

◆ inflate_fast()

static void inflate_fast ( z_streamp  strm,
unsigned  start 
)
static

Definition at line 269 of file inflate.c.

270{
271 struct inflate_state FAR *state;
272 z_const unsigned char FAR *in; /* local strm->next_in */
273 z_const unsigned char FAR *last; /* have enough input while in < last */
274 unsigned char FAR *out; /* local strm->next_out */
275 unsigned char FAR *beg; /* inflate()'s initial strm->next_out */
276 unsigned char FAR *end; /* while out < end, enough space available */
277#ifdef INFLATE_STRICT
278 unsigned dmax; /* maximum distance from zlib header */
279#endif
280 unsigned wsize; /* window size or zero if not using window */
281 unsigned whave; /* valid bytes in the window */
282 unsigned wnext; /* window write index */
283 unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */
284 unsigned long hold; /* local strm->hold */
285 unsigned bits; /* local strm->bits */
286 code const FAR *lcode; /* local strm->lencode */
287 code const FAR *dcode; /* local strm->distcode */
288 unsigned lmask; /* mask for first level of length codes */
289 unsigned dmask; /* mask for first level of distance codes */
290 code here; /* retrieved table entry */
291 unsigned op; /* code bits, operation, extra bits, or */
292 /* window position, window bytes to copy */
293 unsigned len; /* match length, unused bytes */
294 unsigned dist; /* match distance */
295 unsigned char FAR *from; /* where to copy match from */
296
297 /* copy state to local variables */
298 state = (struct inflate_state FAR *)strm->state;
299 in = strm->next_in;
300 last = in + (strm->avail_in - 5);
301 out = strm->next_out;
302 beg = out - (start - strm->avail_out);
303 end = out + (strm->avail_out - 257);
304#ifdef INFLATE_STRICT
305 dmax = state->dmax;
306#endif
307 wsize = state->wsize;
308 whave = state->whave;
309 wnext = state->wnext;
310 window = state->window;
311 hold = state->hold;
312 bits = state->bits;
313 lcode = state->lencode;
314 dcode = state->distcode;
315 lmask = (1U << state->lenbits) - 1;
316 dmask = (1U << state->distbits) - 1;
317
318 /* decode literals and length/distances until end-of-block or not enough
319 input data or output space */
320 do {
321 if (bits < 15) {
322 hold += (unsigned long)(*in++) << bits;
323 bits += 8;
324 hold += (unsigned long)(*in++) << bits;
325 bits += 8;
326 }
327 here = lcode[hold & lmask];
328 dolen:
329 op = (unsigned)(here.bits);
330 hold >>= op;
331 bits -= op;
332 op = (unsigned)(here.op);
333 if (op == 0) { /* literal */
334 Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
335 "inflate: literal '%c'\n" :
336 "inflate: literal 0x%02x\n", here.val));
337 *out++ = (unsigned char)(here.val);
338 }
339 else if (op & 16) { /* length base */
340 len = (unsigned)(here.val);
341 op &= 15; /* number of extra bits */
342 if (op) {
343 if (bits < op) {
344 hold += (unsigned long)(*in++) << bits;
345 bits += 8;
346 }
347 len += (unsigned)hold & ((1U << op) - 1);
348 hold >>= op;
349 bits -= op;
350 }
351 Tracevv((stderr, "inflate: length %u\n", len));
352 if (bits < 15) {
353 hold += (unsigned long)(*in++) << bits;
354 bits += 8;
355 hold += (unsigned long)(*in++) << bits;
356 bits += 8;
357 }
358 here = dcode[hold & dmask];
359 dodist:
360 op = (unsigned)(here.bits);
361 hold >>= op;
362 bits -= op;
363 op = (unsigned)(here.op);
364 if (op & 16) { /* distance base */
365 dist = (unsigned)(here.val);
366 op &= 15; /* number of extra bits */
367 if (bits < op) {
368 hold += (unsigned long)(*in++) << bits;
369 bits += 8;
370 if (bits < op) {
371 hold += (unsigned long)(*in++) << bits;
372 bits += 8;
373 }
374 }
375 dist += (unsigned)hold & ((1U << op) - 1);
376#ifdef INFLATE_STRICT
377 if (dist > dmax) {
378 strm->msg = (char *)"invalid distance too far back";
379 state->mode = BAD;
380 break;
381 }
382#endif
383 hold >>= op;
384 bits -= op;
385 Tracevv((stderr, "inflate: distance %u\n", dist));
386 op = (unsigned)(out - beg); /* max distance in output */
387 if (dist > op) { /* see if copy from window */
388 op = dist - op; /* distance back in window */
389 if (op > whave) {
390 if (state->sane) {
391 strm->msg =
392 (char *)"invalid distance too far back";
393 state->mode = BAD;
394 break;
395 }
396#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
397 if (len <= op - whave) {
398 do {
399 *out++ = 0;
400 } while (--len);
401 continue;
402 }
403 len -= op - whave;
404 do {
405 *out++ = 0;
406 } while (--op > whave);
407 if (op == 0) {
408 from = out - dist;
409 do {
410 *out++ = *from++;
411 } while (--len);
412 continue;
413 }
414#endif
415 }
416 from = window;
417 if (wnext == 0) { /* very common case */
418 from += wsize - op;
419 if (op < len) { /* some from window */
420 len -= op;
421 do {
422 *out++ = *from++;
423 } while (--op);
424 from = out - dist; /* rest from output */
425 }
426 }
427 else if (wnext < op) { /* wrap around window */
428 from += wsize + wnext - op;
429 op -= wnext;
430 if (op < len) { /* some from end of window */
431 len -= op;
432 do {
433 *out++ = *from++;
434 } while (--op);
435 from = window;
436 if (wnext < len) { /* some from start of window */
437 op = wnext;
438 len -= op;
439 do {
440 *out++ = *from++;
441 } while (--op);
442 from = out - dist; /* rest from output */
443 }
444 }
445 }
446 else { /* contiguous in window */
447 from += wnext - op;
448 if (op < len) { /* some from window */
449 len -= op;
450 do {
451 *out++ = *from++;
452 } while (--op);
453 from = out - dist; /* rest from output */
454 }
455 }
456 while (len > 2) {
457 *out++ = *from++;
458 *out++ = *from++;
459 *out++ = *from++;
460 len -= 3;
461 }
462 if (len) {
463 *out++ = *from++;
464 if (len > 1)
465 *out++ = *from++;
466 }
467 }
468 else {
469 from = out - dist; /* copy direct from output */
470 do { /* minimum length is three */
471 *out++ = *from++;
472 *out++ = *from++;
473 *out++ = *from++;
474 len -= 3;
475 } while (len > 2);
476 if (len) {
477 *out++ = *from++;
478 if (len > 1)
479 *out++ = *from++;
480 }
481 }
482 }
483 else if ((op & 64) == 0) { /* 2nd level distance code */
484 here = dcode[here.val + (hold & ((1U << op) - 1))];
485 goto dodist;
486 }
487 else {
488 strm->msg = (char *)"invalid distance code";
489 state->mode = BAD;
490 break;
491 }
492 }
493 else if ((op & 64) == 0) { /* 2nd level length code */
494 here = lcode[here.val + (hold & ((1U << op) - 1))];
495 goto dolen;
496 }
497 else if (op & 32) { /* end-of-block */
498 Tracevv((stderr, "inflate: end of block\n"));
499 state->mode = TYPE;
500 break;
501 }
502 else {
503 strm->msg = (char *)"invalid literal/length code";
504 state->mode = BAD;
505 break;
506 }
507 } while (in < last && out < end);
508
509 /* return unused bytes (on entry, bits < 8, so in won't go too far back) */
510 len = bits >> 3;
511 in -= len;
512 bits -= len << 3;
513 hold &= (1U << bits) - 1;
514
515 /* update state and return */
516 strm->next_in = in;
517 strm->next_out = out;
518 strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
519 strm->avail_out = (unsigned)(out < end ?
520 257 + (end - out) : 257 - (out - end));
521 state->hold = hold;
522 state->bits = bits;
523 return;
524}
UINT op
Definition: effect.c:236
GLuint start
Definition: gl.h:1545
GLuint GLuint end
Definition: gl.h:1545
static IHTMLWindow2 * window
Definition: events.c:77
#define long
Definition: qsort.c:33
unsigned wnext
Definition: inflate.c:210
unsigned whave
Definition: inflate.c:209
unsigned wsize
Definition: inflate.c:208
unsigned dmax
Definition: inflate.c:202

◆ inflate_table()

static int inflate_table ( codetype  type,
unsigned short FAR lens,
unsigned  codes,
code FAR *FAR table,
unsigned FAR bits,
unsigned short FAR work 
)
static

Definition at line 528 of file inflate.c.

530{
531 unsigned len; /* a code's length in bits */
532 unsigned sym; /* index of code symbols */
533 unsigned min, max; /* minimum and maximum code lengths */
534 unsigned root; /* number of index bits for root table */
535 unsigned curr; /* number of index bits for current table */
536 unsigned drop; /* code bits to drop for sub-table */
537 int left; /* number of prefix codes available */
538 unsigned used; /* code entries in table used */
539 unsigned huff; /* Huffman code */
540 unsigned incr; /* for incrementing code, index */
541 unsigned fill; /* index for replicating entries */
542 unsigned low; /* low bits for current root entry */
543 unsigned mask; /* mask for low root bits */
544 code here; /* table entry for duplication */
545 code FAR *next; /* next available space in table */
546 const unsigned short FAR *base; /* base value table to use */
547 const unsigned short FAR *extra; /* extra bits table to use */
548 unsigned match; /* use base and extra for symbol >= match */
549 unsigned short count[MAXBITS+1]; /* number of codes of each length */
550 unsigned short offs[MAXBITS+1]; /* offsets in table for each length */
551 static const unsigned short lbase[31] = { /* Length codes 257..285 base */
552 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
553 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
554 static const unsigned short lext[31] = { /* Length codes 257..285 extra */
555 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
556 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 77, 202};
557 static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
558 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
559 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
560 8193, 12289, 16385, 24577, 0, 0};
561 static const unsigned short dext[32] = { /* Distance codes 0..29 extra */
562 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,
563 23, 23, 24, 24, 25, 25, 26, 26, 27, 27,
564 28, 28, 29, 29, 64, 64};
565
566 /*
567 Process a set of code lengths to create a canonical Huffman code. The
568 code lengths are lens[0..codes-1]. Each length corresponds to the
569 symbols 0..codes-1. The Huffman code is generated by first sorting the
570 symbols by length from short to long, and retaining the symbol order
571 for codes with equal lengths. Then the code starts with all zero bits
572 for the first code of the shortest length, and the codes are integer
573 increments for the same length, and zeros are appended as the length
574 increases. For the deflate format, these bits are stored backwards
575 from their more natural integer increment ordering, and so when the
576 decoding tables are built in the large loop below, the integer codes
577 are incremented backwards.
578
579 This routine assumes, but does not check, that all of the entries in
580 lens[] are in the range 0..MAXBITS. The caller must assure this.
581 1..MAXBITS is interpreted as that code length. zero means that that
582 symbol does not occur in this code.
583
584 The codes are sorted by computing a count of codes for each length,
585 creating from that a table of starting indices for each length in the
586 sorted table, and then entering the symbols in order in the sorted
587 table. The sorted table is work[], with that space being provided by
588 the caller.
589
590 The length counts are used for other purposes as well, i.e. finding
591 the minimum and maximum length codes, determining if there are any
592 codes at all, checking for a valid set of lengths, and looking ahead
593 at length counts to determine sub-table sizes when building the
594 decoding tables.
595 */
596
597 /* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */
598 for (len = 0; len <= MAXBITS; len++)
599 count[len] = 0;
600 for (sym = 0; sym < codes; sym++)
601 count[lens[sym]]++;
602
603 /* bound code lengths, force root to be within code lengths */
604 root = *bits;
605 for (max = MAXBITS; max >= 1; max--)
606 if (count[max] != 0) break;
607 if (root > max) root = max;
608 if (max == 0) { /* no symbols to code at all */
609 here.op = (unsigned char)64; /* invalid code marker */
610 here.bits = (unsigned char)1;
611 here.val = (unsigned short)0;
612 *(*table)++ = here; /* make a table to force an error */
613 *(*table)++ = here;
614 *bits = 1;
615 return 0; /* no symbols, but wait for decoding to report error */
616 }
617 for (min = 1; min < max; min++)
618 if (count[min] != 0) break;
619 if (root < min) root = min;
620
621 /* check for an over-subscribed or incomplete set of lengths */
622 left = 1;
623 for (len = 1; len <= MAXBITS; len++) {
624 left <<= 1;
625 left -= count[len];
626 if (left < 0) return -1; /* over-subscribed */
627 }
628 if (left > 0 && (type == CODES || max != 1))
629 return -1; /* incomplete set */
630
631 /* generate offsets into symbol table for each length for sorting */
632 offs[1] = 0;
633 for (len = 1; len < MAXBITS; len++)
634 offs[len + 1] = offs[len] + count[len];
635
636 /* sort symbols by length, by symbol order within each length */
637 for (sym = 0; sym < codes; sym++)
638 if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym;
639
640 /*
641 Create and fill in decoding tables. In this loop, the table being
642 filled is at next and has curr index bits. The code being used is huff
643 with length len. That code is converted to an index by dropping drop
644 bits off of the bottom. For codes where len is less than drop + curr,
645 those top drop + curr - len bits are incremented through all values to
646 fill the table with replicated entries.
647
648 root is the number of index bits for the root table. When len exceeds
649 root, sub-tables are created pointed to by the root entry with an index
650 of the low root bits of huff. This is saved in low to check for when a
651 new sub-table should be started. drop is zero when the root table is
652 being filled, and drop is root when sub-tables are being filled.
653
654 When a new sub-table is needed, it is necessary to look ahead in the
655 code lengths to determine what size sub-table is needed. The length
656 counts are used for this, and so count[] is decremented as codes are
657 entered in the tables.
658
659 used keeps track of how many table entries have been allocated from the
660 provided *table space. It is checked for LENS and DIST tables against
661 the constants ENOUGH_LENS and ENOUGH_DISTS to guard against changes in
662 the initial root table size constants. See the comments in inftrees.h
663 for more information.
664
665 sym increments through all symbols, and the loop terminates when
666 all codes of length max, i.e. all codes, have been processed. This
667 routine permits incomplete codes, so another loop after this one fills
668 in the rest of the decoding tables with invalid code markers.
669 */
670
671 /* set up for code type */
672 switch (type) {
673 case CODES:
674 base = extra = work; /* dummy value--not used */
675 match = 20;
676 break;
677 case LENS:
678 base = lbase;
679 extra = lext;
680 match = 257;
681 break;
682 default: /* DISTS */
683 base = dbase;
684 extra = dext;
685 match = 0;
686 }
687
688 /* initialize state for loop */
689 huff = 0; /* starting code */
690 sym = 0; /* starting code symbol */
691 len = min; /* starting code length */
692 next = *table; /* current table to fill in */
693 curr = root; /* current table index bits */
694 drop = 0; /* current bits to drop from code for index */
695 low = (unsigned)(-1); /* trigger new sub-table when len > root */
696 used = 1U << root; /* use root table entries */
697 mask = used - 1; /* mask for comparing low */
698
699 /* check available table space */
700 if ((type == LENS && used > ENOUGH_LENS) ||
701 (type == DISTS && used > ENOUGH_DISTS))
702 return 1;
703
704 /* process all codes and make table entries */
705 for (;;) {
706 /* create table entry */
707 here.bits = (unsigned char)(len - drop);
708 if (work[sym] + 1U < match) {
709 here.op = (unsigned char)0;
710 here.val = work[sym];
711 }
712 else if (work[sym] >= match) {
713 here.op = (unsigned char)(extra[work[sym] - match]);
714 here.val = base[work[sym] - match];
715 }
716 else {
717 here.op = (unsigned char)(32 + 64); /* end of block */
718 here.val = 0;
719 }
720
721 /* replicate for those indices with low len bits equal to huff */
722 incr = 1U << (len - drop);
723 fill = 1U << curr;
724 min = fill; /* save offset to next table */
725 do {
726 fill -= incr;
727 next[(huff >> drop) + fill] = here;
728 } while (fill != 0);
729
730 /* backwards increment the len-bit code huff */
731 incr = 1U << (len - 1);
732 while (huff & incr)
733 incr >>= 1;
734 if (incr != 0) {
735 huff &= incr - 1;
736 huff += incr;
737 }
738 else
739 huff = 0;
740
741 /* go to next symbol, update count, len */
742 sym++;
743 if (--(count[len]) == 0) {
744 if (len == max) break;
745 len = lens[work[sym]];
746 }
747
748 /* create new sub-table if needed */
749 if (len > root && (huff & mask) != low) {
750 /* if first time, transition to sub-tables */
751 if (drop == 0)
752 drop = root;
753
754 /* increment past last table */
755 next += min; /* here min is 1 << curr */
756
757 /* determine length of next table */
758 curr = len - drop;
759 left = (int)(1 << curr);
760 while (curr + drop < max) {
761 left -= count[curr + drop];
762 if (left <= 0) break;
763 curr++;
764 left <<= 1;
765 }
766
767 /* check for enough space */
768 used += 1U << curr;
769 if ((type == LENS && used > ENOUGH_LENS) ||
770 (type == DISTS && used > ENOUGH_DISTS))
771 return 1;
772
773 /* point entry in root table to sub-table */
774 low = huff & mask;
775 (*table)[low].op = (unsigned char)curr;
776 (*table)[low].bits = (unsigned char)root;
777 (*table)[low].val = (unsigned short)(next - *table);
778 }
779 }
780
781 /* fill in remaining table entry if code is incomplete (guaranteed to have
782 at most one remaining entry, since if the code is incomplete, the
783 maximum code length that was allowed to get this far is one bit) */
784 if (huff != 0) {
785 here.op = (unsigned char)64; /* invalid code marker */
786 here.bits = (unsigned char)(len - drop);
787 here.val = (unsigned short)0;
788 next[huff] = here;
789 }
790
791 /* set return parameters */
792 *table += used;
793 *bits = root;
794 return 0;
795}
_STLP_MOVE_TO_STD_NAMESPACE void fill(_ForwardIter __first, _ForwardIter __last, const _Tp &__val)
Definition: _algobase.h:449
static int used
Definition: adh-main.c:39
struct _root root
#define MAXBITS
Definition: inflate.c:531
#define ENOUGH_LENS
Definition: inflate.c:145
#define ENOUGH_DISTS
Definition: inflate.c:146
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLenum GLint GLuint mask
Definition: glext.h:6028
@ extra
Definition: id3.c:95
#define min(a, b)
Definition: monoChain.cc:55
Definition: match.c:28
#define max(a, b)
Definition: svc.c:63

◆ inflateEnd()

int inflateEnd ( z_streamp  strm)

Definition at line 1905 of file inflate.c.

1906{
1907 struct inflate_state FAR *state;
1909 return Z_STREAM_ERROR;
1910 state = (struct inflate_state FAR *)strm->state;
1911 if (state->window != Z_NULL) ZFREE(strm, state->window);
1912 ZFREE(strm, strm->state);
1913 strm->state = Z_NULL;
1914 Tracev((stderr, "inflate: end\n"));
1915 return Z_OK;
1916}
#define ZFREE(strm, addr)
Definition: inflate.c:51

◆ inflateInit()

int inflateInit ( z_streamp  strm)

Definition at line 904 of file inflate.c.

905{
906 return inflateInit2(strm, DEF_WBITS);
907}
#define DEF_WBITS
Definition: inflate.c:37
#define inflateInit2(strm, windowBits)
Definition: zlib.h:1817

◆ inflateInit2()

int inflateInit2 ( z_streamp  strm,
int  windowBits 
)

Definition at line 882 of file inflate.c.

883{
884 int ret;
885 struct inflate_state FAR *state;
886
887 strm->msg = Z_NULL; /* in case we return an error */
888 state = (struct inflate_state FAR *)
889 ZALLOC(strm, 1, sizeof(struct inflate_state));
890 if (state == Z_NULL) return Z_MEM_ERROR;
891 Tracev((stderr, "inflate: allocated\n"));
892 strm->state = (struct internal_state FAR *)state;
893 state->strm = strm;
894 state->window = Z_NULL;
895 state->mode = HEAD; /* to pass state test in inflateReset2() */
897 if (ret != Z_OK) {
898 ZFREE(strm, state);
899 strm->state = Z_NULL;
900 }
901 return ret;
902}
static int inflateReset2(z_streamp strm, int windowBits)
Definition: inflate.c:851
#define ZALLOC(strm, items, size)
Definition: inflate.c:49
int windowBits
Definition: zlib.h:813
z_streamp strm
Definition: deflate.h:101

◆ inflateReset()

static int inflateReset ( z_streamp  strm)
static

Definition at line 834 of file inflate.c.

835{
836 struct inflate_state FAR *state;
837
839 state = (struct inflate_state FAR *)strm->state;
840 state->wsize = 0;
841 state->whave = 0;
842 state->wnext = 0;
843 return inflateResetKeep(strm);
844}
static int inflateResetKeep(z_streamp strm)
Definition: inflate.c:815

◆ inflateReset2()

static int inflateReset2 ( z_streamp  strm,
int  windowBits 
)
static

Definition at line 846 of file inflate.c.

847{
848 int wrap;
849 struct inflate_state FAR *state;
850
851 /* get the state */
853 state = (struct inflate_state FAR *)strm->state;
854
855 /* extract wrap request from windowBits parameter */
856 if (windowBits < 0) {
857 wrap = 0;
859 }
860 else {
861 wrap = (windowBits >> 4) + 5;
862#ifdef GUNZIP
863 if (windowBits < 48)
864 windowBits &= 15;
865#endif
866 }
867
868 /* set number of window bits, free window if different */
869 if (windowBits && (windowBits < 8 || windowBits > 15))
870 return Z_STREAM_ERROR;
871 if (state->window != Z_NULL && state->wbits != (unsigned)windowBits) {
872 ZFREE(strm, state->window);
873 state->window = Z_NULL;
874 }
875
876 /* update state and reset the rest of it */
877 state->wrap = wrap;
878 state->wbits = (unsigned)windowBits;
879 return inflateReset(strm);
880}
static int inflateReset(z_streamp strm)
Definition: inflate.c:839
#define wrap(journal, var)
Definition: recovery.c:207

◆ inflateResetKeep()

static int inflateResetKeep ( z_streamp  strm)
static

Definition at line 810 of file inflate.c.

811{
812 struct inflate_state FAR *state;
813
815 state = (struct inflate_state FAR *)strm->state;
816 strm->total_in = strm->total_out = state->total = 0;
817 strm->msg = Z_NULL;
818 if (state->wrap) /* to support ill-conceived Java test suite */
819 strm->adler = state->wrap & 1;
820 state->mode = HEAD;
821 state->last = 0;
822 state->havedict = 0;
823 state->dmax = 32768U;
824 state->head = Z_NULL;
825 state->hold = 0;
826 state->bits = 0;
827 state->lencode = state->distcode = state->next = state->codes;
828 state->sane = 1;
829 state->back = -1;
830 Tracev((stderr, "inflate: reset\n"));
831 return Z_OK;
832}

◆ inflateStateCheck()

static int inflateStateCheck ( z_streamp  strm)
static

Definition at line 797 of file inflate.c.

798{
799 struct inflate_state FAR *state;
800 if (strm == Z_NULL ||
801 strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0)
802 return 1;
803 state = (struct inflate_state FAR *)strm->state;
804 if (state == Z_NULL || state->strm != strm ||
805 state->mode < HEAD || state->mode > SYNC)
806 return 1;
807 return 0;
808}
void(* free_func)(voidpf opaque, voidpf address)
Definition: zlib.h:54
voidpf(* alloc_func)(voidpf opaque, uInt items, uInt size)
Definition: zlib.h:53

◆ updatewindow()

static int updatewindow ( z_streamp  strm,
const Bytef end,
unsigned  copy 
)
static

Definition at line 1027 of file inflate.c.

1028{
1029 struct inflate_state FAR *state;
1030 unsigned dist;
1031
1032 state = (struct inflate_state FAR *)strm->state;
1033
1034 /* if it hasn't been done already, allocate space for the window */
1035 if (state->window == Z_NULL) {
1036 state->window = (unsigned char FAR *)
1037 ZALLOC(strm, 1U << state->wbits,
1038 sizeof(unsigned char));
1039 if (state->window == Z_NULL) return 1;
1040 }
1041
1042 /* if window not in use yet, initialize */
1043 if (state->wsize == 0) {
1044 state->wsize = 1U << state->wbits;
1045 state->wnext = 0;
1046 state->whave = 0;
1047 }
1048
1049 /* copy state->wsize or less output bytes into the circular window */
1050 if (copy >= state->wsize) {
1051 zmemcpy(state->window, end - state->wsize, state->wsize);
1052 state->wnext = 0;
1053 state->whave = state->wsize;
1054 }
1055 else {
1056 dist = state->wsize - state->wnext;
1057 if (dist > copy) dist = copy;
1058 zmemcpy(state->window + state->wnext, end - copy, dist);
1059 copy -= dist;
1060 if (copy) {
1061 zmemcpy(state->window, end - copy, copy);
1062 state->wnext = copy;
1063 state->whave = state->wsize;
1064 }
1065 else {
1066 state->wnext += dist;
1067 if (state->wnext == state->wsize) state->wnext = 0;
1068 if (state->whave < state->wsize) state->whave += dist;
1069 }
1070 }
1071 return 0;
1072}