Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
inffast.cc File Reference
#include "zutil.h"
#include "inftrees.h"
#include "inflate.h"
#include "inffast.h"
Include dependency graph for inffast.cc:

Go to the source code of this file.

Macros

#define OFF   1
 
#define PUP(a)   *++(a)
 

Functions

void ZLIB_INTERNAL inflate_fast (z_streamp strm, unsigned start)
 

Macro Definition Documentation

#define OFF   1

Definition at line 28 of file inffast.cc.

#define PUP (   a)    *++(a)

Definition at line 29 of file inffast.cc.

Function Documentation

void ZLIB_INTERNAL inflate_fast ( z_streamp  strm,
unsigned  start 
)

Definition at line 67 of file inffast.cc.

68 {
69  struct inflate_state FAR *state;
70  z_const unsigned char FAR *in; /* local strm->next_in */
71  z_const unsigned char FAR *last; /* have enough input while in < last */
72  unsigned char FAR *out; /* local strm->next_out */
73  unsigned char FAR *beg; /* inflate()'s initial strm->next_out */
74  unsigned char FAR *end; /* while out < end, enough space available */
75 #ifdef INFLATE_STRICT
76  unsigned dmax; /* maximum distance from zlib header */
77 #endif
78  unsigned wsize; /* window size or zero if not using window */
79  unsigned whave; /* valid bytes in the window */
80  unsigned wnext; /* window write index */
81  unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */
82  unsigned long hold; /* local strm->hold */
83  unsigned bits; /* local strm->bits */
84  code const FAR *lcode; /* local strm->lencode */
85  code const FAR *dcode; /* local strm->distcode */
86  unsigned lmask; /* mask for first level of length codes */
87  unsigned dmask; /* mask for first level of distance codes */
88  code here; /* retrieved table entry */
89  unsigned op; /* code bits, operation, extra bits, or */
90  /* window position, window bytes to copy */
91  unsigned len; /* match length, unused bytes */
92  unsigned dist; /* match distance */
93  unsigned char FAR *from; /* where to copy match from */
94 
95  /* copy state to local variables */
96  state = (struct inflate_state FAR *)strm->state;
97  in = strm->next_in - OFF;
98  last = in + (strm->avail_in - 5);
99  out = strm->next_out - OFF;
100  beg = out - (start - strm->avail_out);
101  end = out + (strm->avail_out - 257);
102 #ifdef INFLATE_STRICT
103  dmax = state->dmax;
104 #endif
105  wsize = state->wsize;
106  whave = state->whave;
107  wnext = state->wnext;
108  window = state->window;
109  hold = state->hold;
110  bits = state->bits;
111  lcode = state->lencode;
112  dcode = state->distcode;
113  lmask = (1U << state->lenbits) - 1;
114  dmask = (1U << state->distbits) - 1;
115 
116  /* decode literals and length/distances until end-of-block or not enough
117  input data or output space */
118  do {
119  if (bits < 15) {
120  hold += (unsigned long)(PUP(in)) << bits;
121  bits += 8;
122  hold += (unsigned long)(PUP(in)) << bits;
123  bits += 8;
124  }
125  here = lcode[hold & lmask];
126  dolen:
127  op = (unsigned)(here.bits);
128  hold >>= op;
129  bits -= op;
130  op = (unsigned)(here.op);
131  if (op == 0) { /* literal */
132  Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
133  "inflate: literal '%c'\n" :
134  "inflate: literal 0x%02x\n", here.val));
135  PUP(out) = (unsigned char)(here.val);
136  }
137  else if (op & 16) { /* length base */
138  len = (unsigned)(here.val);
139  op &= 15; /* number of extra bits */
140  if (op) {
141  if (bits < op) {
142  hold += (unsigned long)(PUP(in)) << bits;
143  bits += 8;
144  }
145  len += (unsigned)hold & ((1U << op) - 1);
146  hold >>= op;
147  bits -= op;
148  }
149  Tracevv((stderr, "inflate: length %u\n", len));
150  if (bits < 15) {
151  hold += (unsigned long)(PUP(in)) << bits;
152  bits += 8;
153  hold += (unsigned long)(PUP(in)) << bits;
154  bits += 8;
155  }
156  here = dcode[hold & dmask];
157  dodist:
158  op = (unsigned)(here.bits);
159  hold >>= op;
160  bits -= op;
161  op = (unsigned)(here.op);
162  if (op & 16) { /* distance base */
163  dist = (unsigned)(here.val);
164  op &= 15; /* number of extra bits */
165  if (bits < op) {
166  hold += (unsigned long)(PUP(in)) << bits;
167  bits += 8;
168  if (bits < op) {
169  hold += (unsigned long)(PUP(in)) << bits;
170  bits += 8;
171  }
172  }
173  dist += (unsigned)hold & ((1U << op) - 1);
174 #ifdef INFLATE_STRICT
175  if (dist > dmax) {
176  strm->msg = (char *)"invalid distance too far back";
177  state->mode = BAD;
178  break;
179  }
180 #endif
181  hold >>= op;
182  bits -= op;
183  Tracevv((stderr, "inflate: distance %u\n", dist));
184  op = (unsigned)(out - beg); /* max distance in output */
185  if (dist > op) { /* see if copy from window */
186  op = dist - op; /* distance back in window */
187  if (op > whave) {
188  if (state->sane) {
189  strm->msg =
190  (char *)"invalid distance too far back";
191  state->mode = BAD;
192  break;
193  }
194 #ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
195  if (len <= op - whave) {
196  do {
197  PUP(out) = 0;
198  } while (--len);
199  continue;
200  }
201  len -= op - whave;
202  do {
203  PUP(out) = 0;
204  } while (--op > whave);
205  if (op == 0) {
206  from = out - dist;
207  do {
208  PUP(out) = PUP(from);
209  } while (--len);
210  continue;
211  }
212 #endif
213  }
214  from = window - OFF;
215  if (wnext == 0) { /* very common case */
216  from += wsize - op;
217  if (op < len) { /* some from window */
218  len -= op;
219  do {
220  PUP(out) = PUP(from);
221  } while (--op);
222  from = out - dist; /* rest from output */
223  }
224  }
225  else if (wnext < op) { /* wrap around window */
226  from += wsize + wnext - op;
227  op -= wnext;
228  if (op < len) { /* some from end of window */
229  len -= op;
230  do {
231  PUP(out) = PUP(from);
232  } while (--op);
233  from = window - OFF;
234  if (wnext < len) { /* some from start of window */
235  op = wnext;
236  len -= op;
237  do {
238  PUP(out) = PUP(from);
239  } while (--op);
240  from = out - dist; /* rest from output */
241  }
242  }
243  }
244  else { /* contiguous in window */
245  from += wnext - op;
246  if (op < len) { /* some from window */
247  len -= op;
248  do {
249  PUP(out) = PUP(from);
250  } while (--op);
251  from = out - dist; /* rest from output */
252  }
253  }
254  while (len > 2) {
255  PUP(out) = PUP(from);
256  PUP(out) = PUP(from);
257  PUP(out) = PUP(from);
258  len -= 3;
259  }
260  if (len) {
261  PUP(out) = PUP(from);
262  if (len > 1)
263  PUP(out) = PUP(from);
264  }
265  }
266  else {
267  from = out - dist; /* copy direct from output */
268  do { /* minimum length is three */
269  PUP(out) = PUP(from);
270  PUP(out) = PUP(from);
271  PUP(out) = PUP(from);
272  len -= 3;
273  } while (len > 2);
274  if (len) {
275  PUP(out) = PUP(from);
276  if (len > 1)
277  PUP(out) = PUP(from);
278  }
279  }
280  }
281  else if ((op & 64) == 0) { /* 2nd level distance code */
282  here = dcode[here.val + (hold & ((1U << op) - 1))];
283  goto dodist;
284  }
285  else {
286  strm->msg = (char *)"invalid distance code";
287  state->mode = BAD;
288  break;
289  }
290  }
291  else if ((op & 64) == 0) { /* 2nd level length code */
292  here = lcode[here.val + (hold & ((1U << op) - 1))];
293  goto dolen;
294  }
295  else if (op & 32) { /* end-of-block */
296  Tracevv((stderr, "inflate: end of block\n"));
297  state->mode = TYPE;
298  break;
299  }
300  else {
301  strm->msg = (char *)"invalid literal/length code";
302  state->mode = BAD;
303  break;
304  }
305  } while (in < last && out < end);
306 
307  /* return unused bytes (on entry, bits < 8, so in won't go too far back) */
308  len = bits >> 3;
309  in -= len;
310  bits -= len << 3;
311  hold &= (1U << bits) - 1;
312 
313  /* update state and return */
314  strm->next_in = in + OFF;
315  strm->next_out = out + OFF;
316  strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
317  strm->avail_out = (unsigned)(out < end ?
318  257 + (end - out) : 257 - (out - end));
319  state->hold = hold;
320  state->bits = bits;
321  return;
322 }
const XML_Char int len
Definition: expat.h:262
unsigned short val
Definition: inftrees.h:27
unsigned wnext
Definition: inflate.h:95
unsigned wsize
Definition: inflate.h:93
unsigned distbits
Definition: inflate.h:109
code const FAR * distcode
Definition: inflate.h:107
#define OFF
Definition: inffast.cc:28
unsigned char op
Definition: inftrees.h:25
Definition: inflate.h:32
unsigned lenbits
Definition: inflate.h:108
#define PUP(a)
Definition: inffast.cc:29
unsigned long hold
Definition: inflate.h:98
unsigned char bits
Definition: inftrees.h:26
Definition: inftrees.h:24
unsigned dmax
Definition: inflate.h:87
unsigned bits
Definition: inflate.h:99
unsigned char FAR * window
Definition: inflate.h:96
inflate_mode mode
Definition: inflate.h:82
Definition: inflate.h:50
unsigned whave
Definition: inflate.h:94
code const FAR * lencode
Definition: inflate.h:106
#define Tracevv(x)
Definition: zutil.h:233

Here is the caller graph for this function: