ReactOS 0.4.15-dev-7842-g558ab78
infback.c File Reference
#include "zutil.h"
#include "inftrees.h"
#include "inflate.h"
#include "inffast.h"
#include "inffixed.h"
Include dependency graph for infback.c:

Go to the source code of this file.

Macros

#define LOAD()
 
#define RESTORE()
 
#define INITBITS()
 
#define PULL()
 
#define PULLBYTE()
 
#define NEEDBITS(n)
 
#define BITS(n)    ((unsigned)hold & ((1U << (n)) - 1))
 
#define DROPBITS(n)
 
#define BYTEBITS()
 
#define ROOM()
 

Functions

void fixedtables OF ((struct inflate_state FAR *state))
 
int ZEXPORT inflateBackInit_ (z_streamp strm, int windowBits, unsigned char FAR *window, const char *version, int stream_size)
 
void fixedtables (struct inflate_state FAR *state)
 
int ZEXPORT inflateBack (z_streamp strm, in_func in, void FAR *in_desc, out_func out, void FAR *out_desc)
 
int ZEXPORT inflateBackEnd (z_streamp strm)
 

Macro Definition Documentation

◆ BITS

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

Definition at line 191 of file infback.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 202 of file infback.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 195 of file infback.c.

◆ INITBITS

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

Definition at line 151 of file infback.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 129 of file infback.c.

◆ NEEDBITS

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

Definition at line 184 of file infback.c.

◆ PULL

#define PULL ( )
Value:
do { \
if (have == 0) { \
have = in(in_desc, &next); \
if (have == 0) { \
next = Z_NULL; \
goto inf_leave; \
} \
} \
} while (0)
#define Z_BUF_ERROR
Definition: zlib.h:121
#define Z_NULL
Definition: zlib.h:149
GLuint in
Definition: glext.h:9616
int ret

Definition at line 159 of file infback.c.

◆ PULLBYTE

#define PULLBYTE ( )
Value:
do { \
PULL(); \
have--; \
hold += (unsigned long)(*next++) << bits; \
bits += 8; \
} while (0)
#define bits
Definition: infblock.c:15
#define long
Definition: qsort.c:33

Definition at line 173 of file infback.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)

Definition at line 140 of file infback.c.

◆ ROOM

#define ROOM ( )
Value:
do { \
if (left == 0) { \
put = state->window; \
left = state->wsize; \
state->whave = left; \
if (out(out_desc, put, left)) { \
goto inf_leave; \
} \
} \
} while (0)
static FILE * out
Definition: regtests2xml.c:44

Definition at line 211 of file infback.c.

Function Documentation

◆ fixedtables()

void fixedtables ( struct inflate_state FAR state)

Definition at line 83 of file infback.c.

85{
86#ifdef BUILDFIXED
87 static int virgin = 1;
88 static code *lenfix, *distfix;
89 static code fixed[544];
90
91 /* build fixed huffman tables if first call (may not be thread safe) */
92 if (virgin) {
93 unsigned sym, bits;
94 static code *next;
95
96 /* literal/length table */
97 sym = 0;
98 while (sym < 144) state->lens[sym++] = 8;
99 while (sym < 256) state->lens[sym++] = 9;
100 while (sym < 280) state->lens[sym++] = 7;
101 while (sym < 288) state->lens[sym++] = 8;
102 next = fixed;
103 lenfix = next;
104 bits = 9;
105 inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
106
107 /* distance table */
108 sym = 0;
109 while (sym < 32) state->lens[sym++] = 5;
110 distfix = next;
111 bits = 5;
112 inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
113
114 /* do this just once */
115 virgin = 0;
116 }
117#else /* !BUILDFIXED */
118# include "inffixed.h"
119#endif /* BUILDFIXED */
120 state->lencode = lenfix;
121 state->lenbits = 9;
122 state->distcode = distfix;
123 state->distbits = 5;
124}
ios_base &_STLP_CALL fixed(ios_base &__s)
Definition: _ios_base.h:332
@ LENS
Definition: inflate.c:152
@ DISTS
Definition: inflate.c:153
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
Definition: inflate.c:139
static const code distfix[32]
Definition: inffixed.h:87
static const code lenfix[512]
Definition: inffixed.h:10

Referenced by inflateBack().

◆ inflateBack()

int ZEXPORT inflateBack ( z_streamp  strm,
in_func  in,
void FAR in_desc,
out_func  out,
void FAR out_desc 
)

Definition at line 251 of file infback.c.

257{
258 struct inflate_state FAR *state;
259 z_const unsigned char FAR *next; /* next input */
260 unsigned char FAR *put; /* next output */
261 unsigned have, left; /* available input and output */
262 unsigned long hold; /* bit buffer */
263 unsigned bits; /* bits in bit buffer */
264 unsigned copy; /* number of stored or match bytes to copy */
265 unsigned char FAR *from; /* where to copy match bytes from */
266 code here; /* current decoding table entry */
267 code last; /* parent table entry */
268 unsigned len; /* length to copy for repeats, bits to drop */
269 int ret; /* return code */
270 static const unsigned short order[19] = /* permutation of code lengths */
271 {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
272
273 /* Check that the strm exists and that the state was initialized */
274 if (strm == Z_NULL || strm->state == Z_NULL)
275 return Z_STREAM_ERROR;
276 state = (struct inflate_state FAR *)strm->state;
277
278 /* Reset the state */
279 strm->msg = Z_NULL;
280 state->mode = TYPE;
281 state->last = 0;
282 state->whave = 0;
283 next = strm->next_in;
284 have = next != Z_NULL ? strm->avail_in : 0;
285 hold = 0;
286 bits = 0;
287 put = state->window;
288 left = state->wsize;
289
290 /* Inflate until end of block marked as last */
291 for (;;)
292 switch (state->mode) {
293 case TYPE:
294 /* determine and dispatch block type */
295 if (state->last) {
296 BYTEBITS();
297 state->mode = DONE;
298 break;
299 }
300 NEEDBITS(3);
301 state->last = BITS(1);
302 DROPBITS(1);
303 switch (BITS(2)) {
304 case 0: /* stored block */
305 Tracev((stderr, "inflate: stored block%s\n",
306 state->last ? " (last)" : ""));
307 state->mode = STORED;
308 break;
309 case 1: /* fixed block */
311 Tracev((stderr, "inflate: fixed codes block%s\n",
312 state->last ? " (last)" : ""));
313 state->mode = LEN; /* decode codes */
314 break;
315 case 2: /* dynamic block */
316 Tracev((stderr, "inflate: dynamic codes block%s\n",
317 state->last ? " (last)" : ""));
318 state->mode = TABLE;
319 break;
320 case 3:
321 strm->msg = (char *)"invalid block type";
322 state->mode = BAD;
323 }
324 DROPBITS(2);
325 break;
326
327 case STORED:
328 /* get and verify stored block length */
329 BYTEBITS(); /* go to byte boundary */
330 NEEDBITS(32);
331 if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
332 strm->msg = (char *)"invalid stored block lengths";
333 state->mode = BAD;
334 break;
335 }
336 state->length = (unsigned)hold & 0xffff;
337 Tracev((stderr, "inflate: stored length %u\n",
338 state->length));
339 INITBITS();
340
341 /* copy stored block from input to output */
342 while (state->length != 0) {
343 copy = state->length;
344 PULL();
345 ROOM();
346 if (copy > have) copy = have;
347 if (copy > left) copy = left;
348 zmemcpy(put, next, copy);
349 have -= copy;
350 next += copy;
351 left -= copy;
352 put += copy;
353 state->length -= copy;
354 }
355 Tracev((stderr, "inflate: stored end\n"));
356 state->mode = TYPE;
357 break;
358
359 case TABLE:
360 /* get dynamic table entries descriptor */
361 NEEDBITS(14);
362 state->nlen = BITS(5) + 257;
363 DROPBITS(5);
364 state->ndist = BITS(5) + 1;
365 DROPBITS(5);
366 state->ncode = BITS(4) + 4;
367 DROPBITS(4);
368#ifndef PKZIP_BUG_WORKAROUND
369 if (state->nlen > 286 || state->ndist > 30) {
370 strm->msg = (char *)"too many length or distance symbols";
371 state->mode = BAD;
372 break;
373 }
374#endif
375 Tracev((stderr, "inflate: table sizes ok\n"));
376
377 /* get code length code lengths (not a typo) */
378 state->have = 0;
379 while (state->have < state->ncode) {
380 NEEDBITS(3);
381 state->lens[order[state->have++]] = (unsigned short)BITS(3);
382 DROPBITS(3);
383 }
384 while (state->have < 19)
385 state->lens[order[state->have++]] = 0;
386 state->next = state->codes;
387 state->lencode = (code const FAR *)(state->next);
388 state->lenbits = 7;
389 ret = inflate_table(CODES, state->lens, 19, &(state->next),
390 &(state->lenbits), state->work);
391 if (ret) {
392 strm->msg = (char *)"invalid code lengths set";
393 state->mode = BAD;
394 break;
395 }
396 Tracev((stderr, "inflate: code lengths ok\n"));
397
398 /* get length and distance code code lengths */
399 state->have = 0;
400 while (state->have < state->nlen + state->ndist) {
401 for (;;) {
402 here = state->lencode[BITS(state->lenbits)];
403 if ((unsigned)(here.bits) <= bits) break;
404 PULLBYTE();
405 }
406 if (here.val < 16) {
407 DROPBITS(here.bits);
408 state->lens[state->have++] = here.val;
409 }
410 else {
411 if (here.val == 16) {
412 NEEDBITS(here.bits + 2);
413 DROPBITS(here.bits);
414 if (state->have == 0) {
415 strm->msg = (char *)"invalid bit length repeat";
416 state->mode = BAD;
417 break;
418 }
419 len = (unsigned)(state->lens[state->have - 1]);
420 copy = 3 + BITS(2);
421 DROPBITS(2);
422 }
423 else if (here.val == 17) {
424 NEEDBITS(here.bits + 3);
425 DROPBITS(here.bits);
426 len = 0;
427 copy = 3 + BITS(3);
428 DROPBITS(3);
429 }
430 else {
431 NEEDBITS(here.bits + 7);
432 DROPBITS(here.bits);
433 len = 0;
434 copy = 11 + BITS(7);
435 DROPBITS(7);
436 }
437 if (state->have + copy > state->nlen + state->ndist) {
438 strm->msg = (char *)"invalid bit length repeat";
439 state->mode = BAD;
440 break;
441 }
442 while (copy--)
443 state->lens[state->have++] = (unsigned short)len;
444 }
445 }
446
447 /* handle error breaks in while */
448 if (state->mode == BAD) break;
449
450 /* check for end-of-block code (better have one) */
451 if (state->lens[256] == 0) {
452 strm->msg = (char *)"invalid code -- missing end-of-block";
453 state->mode = BAD;
454 break;
455 }
456
457 /* build code tables -- note: do not change the lenbits or distbits
458 values here (9 and 6) without reading the comments in inftrees.h
459 concerning the ENOUGH constants, which depend on those values */
460 state->next = state->codes;
461 state->lencode = (code const FAR *)(state->next);
462 state->lenbits = 9;
463 ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
464 &(state->lenbits), state->work);
465 if (ret) {
466 strm->msg = (char *)"invalid literal/lengths set";
467 state->mode = BAD;
468 break;
469 }
470 state->distcode = (code const FAR *)(state->next);
471 state->distbits = 6;
472 ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
473 &(state->next), &(state->distbits), state->work);
474 if (ret) {
475 strm->msg = (char *)"invalid distances set";
476 state->mode = BAD;
477 break;
478 }
479 Tracev((stderr, "inflate: codes ok\n"));
480 state->mode = LEN;
481 /* fallthrough */
482
483 case LEN:
484 /* use inflate_fast() if we have enough input and output */
485 if (have >= 6 && left >= 258) {
486 RESTORE();
487 if (state->whave < state->wsize)
488 state->whave = state->wsize - left;
489 inflate_fast(strm, state->wsize);
490 LOAD();
491 break;
492 }
493
494 /* get a literal, length, or end-of-block code */
495 for (;;) {
496 here = state->lencode[BITS(state->lenbits)];
497 if ((unsigned)(here.bits) <= bits) break;
498 PULLBYTE();
499 }
500 if (here.op && (here.op & 0xf0) == 0) {
501 last = here;
502 for (;;) {
503 here = state->lencode[last.val +
504 (BITS(last.bits + last.op) >> last.bits)];
505 if ((unsigned)(last.bits + here.bits) <= bits) break;
506 PULLBYTE();
507 }
508 DROPBITS(last.bits);
509 }
510 DROPBITS(here.bits);
511 state->length = (unsigned)here.val;
512
513 /* process literal */
514 if (here.op == 0) {
515 Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
516 "inflate: literal '%c'\n" :
517 "inflate: literal 0x%02x\n", here.val));
518 ROOM();
519 *put++ = (unsigned char)(state->length);
520 left--;
521 state->mode = LEN;
522 break;
523 }
524
525 /* process end of block */
526 if (here.op & 32) {
527 Tracevv((stderr, "inflate: end of block\n"));
528 state->mode = TYPE;
529 break;
530 }
531
532 /* invalid code */
533 if (here.op & 64) {
534 strm->msg = (char *)"invalid literal/length code";
535 state->mode = BAD;
536 break;
537 }
538
539 /* length code -- get extra bits, if any */
540 state->extra = (unsigned)(here.op) & 15;
541 if (state->extra != 0) {
542 NEEDBITS(state->extra);
543 state->length += BITS(state->extra);
544 DROPBITS(state->extra);
545 }
546 Tracevv((stderr, "inflate: length %u\n", state->length));
547
548 /* get distance code */
549 for (;;) {
550 here = state->distcode[BITS(state->distbits)];
551 if ((unsigned)(here.bits) <= bits) break;
552 PULLBYTE();
553 }
554 if ((here.op & 0xf0) == 0) {
555 last = here;
556 for (;;) {
557 here = state->distcode[last.val +
558 (BITS(last.bits + last.op) >> last.bits)];
559 if ((unsigned)(last.bits + here.bits) <= bits) break;
560 PULLBYTE();
561 }
562 DROPBITS(last.bits);
563 }
564 DROPBITS(here.bits);
565 if (here.op & 64) {
566 strm->msg = (char *)"invalid distance code";
567 state->mode = BAD;
568 break;
569 }
570 state->offset = (unsigned)here.val;
571
572 /* get distance extra bits, if any */
573 state->extra = (unsigned)(here.op) & 15;
574 if (state->extra != 0) {
575 NEEDBITS(state->extra);
576 state->offset += BITS(state->extra);
577 DROPBITS(state->extra);
578 }
579 if (state->offset > state->wsize - (state->whave < state->wsize ?
580 left : 0)) {
581 strm->msg = (char *)"invalid distance too far back";
582 state->mode = BAD;
583 break;
584 }
585 Tracevv((stderr, "inflate: distance %u\n", state->offset));
586
587 /* copy match from window to output */
588 do {
589 ROOM();
590 copy = state->wsize - state->offset;
591 if (copy < left) {
592 from = put + copy;
593 copy = left - copy;
594 }
595 else {
596 from = put - state->offset;
597 copy = left;
598 }
599 if (copy > state->length) copy = state->length;
600 state->length -= copy;
601 left -= copy;
602 do {
603 *put++ = *from++;
604 } while (--copy);
605 } while (state->length != 0);
606 break;
607
608 case DONE:
609 /* inflate stream terminated properly */
611 goto inf_leave;
612
613 case BAD:
615 goto inf_leave;
616
617 default:
618 /* can't happen, but makes compilers happy */
620 goto inf_leave;
621 }
622
623 /* Write leftover output and return unused input */
624 inf_leave:
625 if (left < state->wsize) {
626 if (out(out_desc, state->window, state->wsize - left) &&
627 ret == Z_STREAM_END)
629 }
630 strm->next_in = next;
631 strm->avail_in = have;
632 return ret;
633}
INT copy(TCHAR source[MAX_PATH], TCHAR dest[MAX_PATH], INT append, DWORD lpdwFlags, BOOL bTouch)
Definition: copy.c:51
@ CODES
Definition: inflate.c:151
@ TABLE
Definition: inflate.c:174
@ STORED
Definition: inflate.c:171
#define zmemcpy
Definition: inflate.c:38
static void inflate_fast(z_streamp strm, unsigned start)
Definition: inflate.c:274
#define Tracev(x)
Definition: inflate.c:43
#define Tracevv(x)
Definition: inflate.c:44
#define Z_STREAM_END
Definition: zlib.h:115
#define z_const
Definition: zlib.h:35
#define Z_DATA_ERROR
Definition: zlib.h:119
#define Z_STREAM_ERROR
Definition: zlib.h:118
#define FAR
Definition: zlib.h:34
unsigned char
Definition: typeof.h:29
unsigned short(__cdecl typeof(TIFFCurrentDirectory))(struct tiff *)
Definition: typeof.h:94
TYPE
Definition: eventcreate.c:652
GLuint GLdouble GLdouble GLint GLint order
Definition: glext.h:11194
GLenum GLsizei len
Definition: glext.h:6722
#define stderr
Definition: stdio.h:100
#define LOAD()
Definition: infback.c:129
void fixedtables(struct inflate_state FAR *state)
Definition: infback.c:83
#define PULL()
Definition: infback.c:159
#define INITBITS()
Definition: infback.c:151
#define BITS(n)
Definition: infback.c:191
#define DROPBITS(n)
Definition: infback.c:195
#define BYTEBITS()
Definition: infback.c:202
#define ROOM()
Definition: infback.c:211
#define NEEDBITS(n)
Definition: infback.c:184
#define PULLBYTE()
Definition: infback.c:173
#define RESTORE()
Definition: infback.c:140
if(dx< 0)
Definition: linetemp.h:194
#define for
Definition: utility.h:88
static UINT UINT last
Definition: font.c:45
#define LEN
Definition: rtl.c:127
#define DONE
Definition: rnr20lib.h:14
#define BAD
Definition: inflate.c:10
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
unsigned wsize
Definition: inflate.c:208

◆ inflateBackEnd()

int ZEXPORT inflateBackEnd ( z_streamp  strm)

Definition at line 635 of file infback.c.

637{
638 if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
639 return Z_STREAM_ERROR;
640 ZFREE(strm, strm->state);
641 strm->state = Z_NULL;
642 Tracev((stderr, "inflate: end\n"));
643 return Z_OK;
644}
#define ZFREE(strm, addr)
Definition: inflate.c:51
void(* free_func)(voidpf opaque, voidpf address)
Definition: zlib.h:54
#define Z_OK
Definition: zlib.h:114

◆ inflateBackInit_()

int ZEXPORT inflateBackInit_ ( z_streamp  strm,
int  windowBits,
unsigned char FAR window,
const char version,
int  stream_size 
)

Definition at line 28 of file infback.c.

34{
35 struct inflate_state FAR *state;
36
37 if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
38 stream_size != (int)(sizeof(z_stream)))
39 return Z_VERSION_ERROR;
40 if (strm == Z_NULL || window == Z_NULL ||
41 windowBits < 8 || windowBits > 15)
42 return Z_STREAM_ERROR;
43 strm->msg = Z_NULL; /* in case we return an error */
44 if (strm->zalloc == (alloc_func)0) {
45#ifdef Z_SOLO
46 return Z_STREAM_ERROR;
47#else
48 strm->zalloc = zcalloc;
49 strm->opaque = (voidpf)0;
50#endif
51 }
52 if (strm->zfree == (free_func)0)
53#ifdef Z_SOLO
54 return Z_STREAM_ERROR;
55#else
56 strm->zfree = zcfree;
57#endif
58 state = (struct inflate_state FAR *)ZALLOC(strm, 1,
59 sizeof(struct inflate_state));
60 if (state == Z_NULL) return Z_MEM_ERROR;
61 Tracev((stderr, "inflate: allocated\n"));
62 strm->state = (struct internal_state FAR *)state;
63 state->dmax = 32768U;
64 state->wbits = (uInt)windowBits;
65 state->wsize = 1U << windowBits;
66 state->window = window;
67 state->wnext = 0;
68 state->whave = 0;
69 state->sane = 1;
70 return Z_OK;
71}
#define Z_SOLO
Definition: cabinet.c:15
#define ZALLOC(strm, items, size)
Definition: inflate.c:49
voidpf(* alloc_func)(voidpf opaque, uInt items, uInt size)
Definition: zlib.h:53
#define Z_VERSION_ERROR
Definition: zlib.h:122
void FAR * voidpf
Definition: zlib.h:42
unsigned int uInt
Definition: zlib.h:38
#define Z_MEM_ERROR
Definition: zlib.h:120
static const WCHAR version[]
Definition: asmname.c:66
void zcfree(voidpf opaque, voidpf ptr)
Definition: zutil.c:173
voidpf zcalloc(voidpf opaque, unsigned items, unsigned size)
Definition: zutil.c:164
static IHTMLWindow2 * window
Definition: events.c:77
#define ZLIB_VERSION
Definition: zlib.h:40
int const char int stream_size
Definition: zlib.h:814
int windowBits
Definition: zlib.h:813

◆ OF()