abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
inflate.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "misc/util/abc_global.h"
#include "zutil.h"
#include "inftrees.h"
#include "inflate.h"
#include "inffast.h"
#include "inffixed.h"

Go to the source code of this file.

Macros

#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()
 
#define REVERSE(q)
 

Functions

ABC_NAMESPACE_IMPL_START local
void fixedtables 
OF ((struct inflate_state FAR *state))
 
local int updatewindow OF ((z_streamp strm, unsigned out))
 
local unsigned syncsearch OF ((unsigned FAR *have, unsigned char FAR *buf, unsigned len))
 
int ZEXPORT inflateReset (z_streamp strm)
 
int ZEXPORT inflateReset2 (z_streamp strm, int windowBits)
 
int ZEXPORT inflateInit2_ (z_streamp strm, int windowBits, const char *version, int stream_size)
 
int ZEXPORT inflateInit_ (z_streamp strm, const char *version, int stream_size)
 
int ZEXPORT inflatePrime (z_streamp strm, int bits, int value)
 
local void fixedtables (struct inflate_state FAR *state)
 
local int updatewindow (z_streamp strm, unsigned out)
 
int ZEXPORT inflate (z_streamp strm, int flush)
 
int ZEXPORT inflateEnd (z_streamp strm)
 
int ZEXPORT inflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength)
 
int ZEXPORT inflateGetHeader (z_streamp strm, gz_headerp head)
 
local unsigned syncsearch (unsigned FAR *have, unsigned char FAR *buf, unsigned len)
 
int ZEXPORT inflateSync (z_streamp strm)
 
int ZEXPORT inflateSyncPoint (z_streamp strm)
 
int ZEXPORT inflateCopy (z_streamp dest, z_streamp source)
 
int ZEXPORT inflateUndermine (z_streamp strm, int subvert)
 
long ZEXPORT inflateMark (z_streamp strm)
 

Macro Definition Documentation

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

Definition at line 476 of file inflate.c.

#define BYTEBITS ( )
Value:
do { \
hold >>= bits & 7; \
bits -= bits & 7; \
} while (0)
unsigned long hold
Definition: inflate.h:100
static char * bits(int n)
Definition: abcSaucy.c:201

Definition at line 487 of file inflate.c.

#define CRC2 (   check,
  word 
)
Value:
do { \
hbuf[0] = (unsigned char)(word); \
hbuf[1] = (unsigned char)((word) >> 8); \
check = crc32(check, hbuf, 2); \
} while (0)
static void check(int expr)
Definition: satSolver.c:46
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf, uInt len)
Definition: crc32.c:230

Definition at line 411 of file inflate.c.

#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)
static void check(int expr)
Definition: satSolver.c:46
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf, uInt len)
Definition: crc32.c:230

Definition at line 418 of file inflate.c.

#define DROPBITS (   n)
Value:
do { \
hold >>= (n); \
bits -= (unsigned)(n); \
} while (0)
unsigned long hold
Definition: inflate.h:100
static char * bits(int n)
Definition: abcSaucy.c:201

Definition at line 480 of file inflate.c.

#define INITBITS ( )
Value:
do { \
hold = 0; \
bits = 0; \
} while (0)
unsigned long hold
Definition: inflate.h:100
static char * bits(int n)
Definition: abcSaucy.c:201

Definition at line 451 of file inflate.c.

#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)
unsigned have
Definition: inflate.h:116
code FAR * next
Definition: inflate.h:117
unsigned long hold
Definition: inflate.h:100
static char * bits(int n)
Definition: abcSaucy.c:201

Definition at line 429 of file inflate.c.

#define NEEDBITS (   n)
Value:
do { \
while (bits < (unsigned)(n)) \
} while (0)
#define PULLBYTE()
Definition: inflate.c:459
static char * bits(int n)
Definition: abcSaucy.c:201

Definition at line 469 of file inflate.c.

#define PULLBYTE ( )
Value:
do { \
if (have == 0) goto inf_leave; \
have--; \
hold += (unsigned long)(*next++) << bits; \
bits += 8; \
} while (0)
unsigned have
Definition: inflate.h:116
code FAR * next
Definition: inflate.h:117
unsigned long hold
Definition: inflate.h:100
if(last==0)
Definition: sparse_int.h:34
static char * bits(int n)
Definition: abcSaucy.c:201

Definition at line 459 of file inflate.c.

#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)
unsigned have
Definition: inflate.h:116
code FAR * next
Definition: inflate.h:117
unsigned long hold
Definition: inflate.h:100
static char * bits(int n)
Definition: abcSaucy.c:201

Definition at line 440 of file inflate.c.

#define REVERSE (   q)
Value:
((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
(((q) & 0xff00) << 8) + (((q) & 0xff) << 24))

Definition at line 494 of file inflate.c.

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

Definition at line 403 of file inflate.c.

Function Documentation

local void fixedtables ( struct inflate_state FAR state)

Definition at line 234 of file inflate.c.

235 {
236 #ifdef BUILDFIXED
237  static int virgin = 1;
238  static code *lenfix, *distfix;
239  static code fixed[544];
240 
241  /* build fixed huffman tables if first call (may not be thread safe) */
242  if (virgin) {
243  unsigned sym, bits;
244  static code *next;
245 
246  /* literal/length table */
247  sym = 0;
248  while (sym < 144) state->lens[sym++] = 8;
249  while (sym < 256) state->lens[sym++] = 9;
250  while (sym < 280) state->lens[sym++] = 7;
251  while (sym < 288) state->lens[sym++] = 8;
252  next = fixed;
253  lenfix = next;
254  bits = 9;
255  inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
256 
257  /* distance table */
258  sym = 0;
259  while (sym < 32) state->lens[sym++] = 5;
260  distfix = next;
261  bits = 5;
262  inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
263 
264  /* do this just once */
265  virgin = 0;
266  }
267 #else /* !BUILDFIXED */
268 # include "inffixed.h"
269 #endif /* BUILDFIXED */
270  state->lencode = lenfix;
271  state->lenbits = 9;
272  state->distcode = distfix;
273  state->distbits = 5;
274 }
Definition: inftrees.h:59
static const code lenfix[512]
Definition: inffixed.h:12
int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens, unsigned codes, code FAR *FAR *table, unsigned FAR *bits, unsigned short FAR *work)
Definition: inftrees.c:39
code FAR * next
Definition: inflate.h:117
static const code distfix[32]
Definition: inffixed.h:89
Definition: inftrees.h:26
Definition: inftrees.h:58
static char * bits(int n)
Definition: abcSaucy.c:201
int ZEXPORT inflate ( z_streamp  strm,
int  flush 
)

Definition at line 580 of file inflate.c.

581 {
582  struct inflate_state FAR *state;
583  unsigned char FAR *next; /* next input */
584  unsigned char FAR *put; /* next output */
585  unsigned have, left; /* available input and output */
586  unsigned long hold; /* bit buffer */
587  unsigned bits; /* bits in bit buffer */
588  unsigned in, out; /* save starting available input and output */
589  unsigned copy; /* number of stored or match bytes to copy */
590  unsigned char FAR *from; /* where to copy match bytes from */
591  code here; /* current decoding table entry */
592  code last; /* parent table entry */
593  unsigned len; /* length to copy for repeats, bits to drop */
594  int ret; /* return code */
595 #ifdef GUNZIP
596  unsigned char hbuf[4]; /* buffer for gzip header crc calculation */
597 #endif
598  static const unsigned short order[19] = /* permutation of code lengths */
599  {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
600 
601  if (strm == Z_NULL || strm->state == Z_NULL || strm->next_out == Z_NULL ||
602  (strm->next_in == Z_NULL && strm->avail_in != 0))
603  return Z_STREAM_ERROR;
604 
605  state = (struct inflate_state FAR *)strm->state;
606  if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */
607  LOAD();
608  in = have;
609  out = left;
610  ret = Z_OK;
611  for (;;)
612  switch (state->mode) {
613  case HEAD:
614  if (state->wrap == 0) {
615  state->mode = TYPEDO;
616  break;
617  }
618  NEEDBITS(16);
619 #ifdef GUNZIP
620  if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */
621  state->check = crc32(0L, Z_NULL, 0);
622  CRC2(state->check, hold);
623  INITBITS();
624  state->mode = FLAGS;
625  break;
626  }
627  state->flags = 0; /* expect zlib header */
628  if (state->head != Z_NULL)
629  state->head->done = -1;
630  if (!(state->wrap & 1) || /* check if zlib header allowed */
631 #else
632  if (
633 #endif
634  ((BITS(8) << 8) + (hold >> 8)) % 31) {
635  strm->msg = (char *)"incorrect header check";
636  state->mode = BAD;
637  break;
638  }
639  if (BITS(4) != Z_DEFLATED) {
640  strm->msg = (char *)"unknown compression method";
641  state->mode = BAD;
642  break;
643  }
644  DROPBITS(4);
645  len = BITS(4) + 8;
646  if (state->wbits == 0)
647  state->wbits = len;
648  else if (len > state->wbits) {
649  strm->msg = (char *)"invalid window size";
650  state->mode = BAD;
651  break;
652  }
653  state->dmax = 1U << len;
654  Tracev((stderr, "inflate: zlib header ok\n"));
655  strm->adler = state->check = adler32(0L, Z_NULL, 0);
656  state->mode = hold & 0x200 ? DICTID : TYPE;
657  INITBITS();
658  break;
659 #ifdef GUNZIP
660  case FLAGS:
661  NEEDBITS(16);
662  state->flags = (int)(hold);
663  if ((state->flags & 0xff) != Z_DEFLATED) {
664  strm->msg = (char *)"unknown compression method";
665  state->mode = BAD;
666  break;
667  }
668  if (state->flags & 0xe000) {
669  strm->msg = (char *)"unknown header flags set";
670  state->mode = BAD;
671  break;
672  }
673  if (state->head != Z_NULL)
674  state->head->text = (int)((hold >> 8) & 1);
675  if (state->flags & 0x0200) CRC2(state->check, hold);
676  INITBITS();
677  state->mode = TIME;
678  case TIME:
679  NEEDBITS(32);
680  if (state->head != Z_NULL)
681  state->head->time = hold;
682  if (state->flags & 0x0200) CRC4(state->check, hold);
683  INITBITS();
684  state->mode = OS;
685  case OS:
686  NEEDBITS(16);
687  if (state->head != Z_NULL) {
688  state->head->xflags = (int)(hold & 0xff);
689  state->head->os = (int)(hold >> 8);
690  }
691  if (state->flags & 0x0200) CRC2(state->check, hold);
692  INITBITS();
693  state->mode = EXLEN;
694  case EXLEN:
695  if (state->flags & 0x0400) {
696  NEEDBITS(16);
697  state->length = (unsigned)(hold);
698  if (state->head != Z_NULL)
699  state->head->extra_len = (unsigned)hold;
700  if (state->flags & 0x0200) CRC2(state->check, hold);
701  INITBITS();
702  }
703  else if (state->head != Z_NULL)
704  state->head->extra = Z_NULL;
705  state->mode = EXTRA;
706  case EXTRA:
707  if (state->flags & 0x0400) {
708  copy = state->length;
709  if (copy > have) copy = have;
710  if (copy) {
711  if (state->head != Z_NULL &&
712  state->head->extra != Z_NULL) {
713  len = state->head->extra_len - state->length;
714  zmemcpy(state->head->extra + len, next,
715  len + copy > state->head->extra_max ?
716  state->head->extra_max - len : copy);
717  }
718  if (state->flags & 0x0200)
719  state->check = crc32(state->check, next, copy);
720  have -= copy;
721  next += copy;
722  state->length -= copy;
723  }
724  if (state->length) goto inf_leave;
725  }
726  state->length = 0;
727  state->mode = NAME;
728  case NAME:
729  if (state->flags & 0x0800) {
730  if (have == 0) goto inf_leave;
731  copy = 0;
732  do {
733  len = (unsigned)(next[copy++]);
734  if (state->head != Z_NULL &&
735  state->head->name != Z_NULL &&
736  state->length < state->head->name_max)
737  state->head->name[state->length++] = len;
738  } while (len && copy < have);
739  if (state->flags & 0x0200)
740  state->check = crc32(state->check, next, copy);
741  have -= copy;
742  next += copy;
743  if (len) goto inf_leave;
744  }
745  else if (state->head != Z_NULL)
746  state->head->name = Z_NULL;
747  state->length = 0;
748  state->mode = COMMENT;
749  case COMMENT:
750  if (state->flags & 0x1000) {
751  if (have == 0) goto inf_leave;
752  copy = 0;
753  do {
754  len = (unsigned)(next[copy++]);
755  if (state->head != Z_NULL &&
756  state->head->comment != Z_NULL &&
757  state->length < state->head->comm_max)
758  state->head->comment[state->length++] = len;
759  } while (len && copy < have);
760  if (state->flags & 0x0200)
761  state->check = crc32(state->check, next, copy);
762  have -= copy;
763  next += copy;
764  if (len) goto inf_leave;
765  }
766  else if (state->head != Z_NULL)
767  state->head->comment = Z_NULL;
768  state->mode = HCRC;
769  case HCRC:
770  if (state->flags & 0x0200) {
771  NEEDBITS(16);
772  if (hold != (state->check & 0xffff)) {
773  strm->msg = (char *)"header crc mismatch";
774  state->mode = BAD;
775  break;
776  }
777  INITBITS();
778  }
779  if (state->head != Z_NULL) {
780  state->head->hcrc = (int)((state->flags >> 9) & 1);
781  state->head->done = 1;
782  }
783  strm->adler = state->check = crc32(0L, Z_NULL, 0);
784  state->mode = TYPE;
785  break;
786 #endif
787  case DICTID:
788  NEEDBITS(32);
789  strm->adler = state->check = REVERSE(hold);
790  INITBITS();
791  state->mode = DICT;
792  case DICT:
793  if (state->havedict == 0) {
794  RESTORE();
795  return Z_NEED_DICT;
796  }
797  strm->adler = state->check = adler32(0L, Z_NULL, 0);
798  state->mode = TYPE;
799  case TYPE:
800  if (flush == Z_BLOCK || flush == Z_TREES) goto inf_leave;
801  case TYPEDO:
802  if (state->last) {
803  BYTEBITS();
804  state->mode = CHECK;
805  break;
806  }
807  NEEDBITS(3);
808  state->last = BITS(1);
809  DROPBITS(1);
810  switch (BITS(2)) {
811  case 0: /* stored block */
812  Tracev((stderr, "inflate: stored block%s\n",
813  state->last ? " (last)" : ""));
814  state->mode = STORED;
815  break;
816  case 1: /* fixed block */
817  fixedtables(state);
818  Tracev((stderr, "inflate: fixed codes block%s\n",
819  state->last ? " (last)" : ""));
820  state->mode = LEN_; /* decode codes */
821  if (flush == Z_TREES) {
822  DROPBITS(2);
823  goto inf_leave;
824  }
825  break;
826  case 2: /* dynamic block */
827  Tracev((stderr, "inflate: dynamic codes block%s\n",
828  state->last ? " (last)" : ""));
829  state->mode = TABLE;
830  break;
831  case 3:
832  strm->msg = (char *)"invalid block type";
833  state->mode = BAD;
834  }
835  DROPBITS(2);
836  break;
837  case STORED:
838  BYTEBITS(); /* go to byte boundary */
839  NEEDBITS(32);
840  if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
841  strm->msg = (char *)"invalid stored block lengths";
842  state->mode = BAD;
843  break;
844  }
845  state->length = (unsigned)hold & 0xffff;
846  Tracev((stderr, "inflate: stored length %u\n",
847  state->length));
848  INITBITS();
849  state->mode = COPY_;
850  if (flush == Z_TREES) goto inf_leave;
851  case COPY_:
852  state->mode = COPY;
853  case COPY:
854  copy = state->length;
855  if (copy) {
856  if (copy > have) copy = have;
857  if (copy > left) copy = left;
858  if (copy == 0) goto inf_leave;
859  zmemcpy(put, next, copy);
860  have -= copy;
861  next += copy;
862  left -= copy;
863  put += copy;
864  state->length -= copy;
865  break;
866  }
867  Tracev((stderr, "inflate: stored end\n"));
868  state->mode = TYPE;
869  break;
870  case TABLE:
871  NEEDBITS(14);
872  state->nlen = BITS(5) + 257;
873  DROPBITS(5);
874  state->ndist = BITS(5) + 1;
875  DROPBITS(5);
876  state->ncode = BITS(4) + 4;
877  DROPBITS(4);
878 #ifndef PKZIP_BUG_WORKAROUND
879  if (state->nlen > 286 || state->ndist > 30) {
880  strm->msg = (char *)"too many length or distance symbols";
881  state->mode = BAD;
882  break;
883  }
884 #endif
885  Tracev((stderr, "inflate: table sizes ok\n"));
886  state->have = 0;
887  state->mode = LENLENS;
888  case LENLENS:
889  while (state->have < state->ncode) {
890  NEEDBITS(3);
891  state->lens[order[state->have++]] = (unsigned short)BITS(3);
892  DROPBITS(3);
893  }
894  while (state->have < 19)
895  state->lens[order[state->have++]] = 0;
896  state->next = state->codes;
897  state->lencode = (code const FAR *)(state->next);
898  state->lenbits = 7;
899  ret = inflate_table(CODES, state->lens, 19, &(state->next),
900  &(state->lenbits), state->work);
901  if (ret) {
902  strm->msg = (char *)"invalid code lengths set";
903  state->mode = BAD;
904  break;
905  }
906  Tracev((stderr, "inflate: code lengths ok\n"));
907  state->have = 0;
908  state->mode = CODELENS;
909  case CODELENS:
910  while (state->have < state->nlen + state->ndist) {
911  for (;;) {
912  here = state->lencode[BITS(state->lenbits)];
913  if ((unsigned)(here.bits) <= bits) break;
914  PULLBYTE();
915  }
916  if (here.val < 16) {
917  NEEDBITS(here.bits);
918  DROPBITS(here.bits);
919  state->lens[state->have++] = here.val;
920  }
921  else {
922  if (here.val == 16) {
923  NEEDBITS(here.bits + 2);
924  DROPBITS(here.bits);
925  if (state->have == 0) {
926  strm->msg = (char *)"invalid bit length repeat";
927  state->mode = BAD;
928  break;
929  }
930  len = state->lens[state->have - 1];
931  copy = 3 + BITS(2);
932  DROPBITS(2);
933  }
934  else if (here.val == 17) {
935  NEEDBITS(here.bits + 3);
936  DROPBITS(here.bits);
937  len = 0;
938  copy = 3 + BITS(3);
939  DROPBITS(3);
940  }
941  else {
942  NEEDBITS(here.bits + 7);
943  DROPBITS(here.bits);
944  len = 0;
945  copy = 11 + BITS(7);
946  DROPBITS(7);
947  }
948  if (state->have + copy > state->nlen + state->ndist) {
949  strm->msg = (char *)"invalid bit length repeat";
950  state->mode = BAD;
951  break;
952  }
953  while (copy--)
954  state->lens[state->have++] = (unsigned short)len;
955  }
956  }
957 
958  /* handle error breaks in while */
959  if (state->mode == BAD) break;
960 
961  /* check for end-of-block code (better have one) */
962  if (state->lens[256] == 0) {
963  strm->msg = (char *)"invalid code -- missing end-of-block";
964  state->mode = BAD;
965  break;
966  }
967 
968  /* build code tables -- note: do not change the lenbits or distbits
969  values here (9 and 6) without reading the comments in inftrees.h
970  concerning the ENOUGH constants, which depend on those values */
971  state->next = state->codes;
972  state->lencode = (code const FAR *)(state->next);
973  state->lenbits = 9;
974  ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
975  &(state->lenbits), state->work);
976  if (ret) {
977  strm->msg = (char *)"invalid literal/lengths set";
978  state->mode = BAD;
979  break;
980  }
981  state->distcode = (code const FAR *)(state->next);
982  state->distbits = 6;
983  ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
984  &(state->next), &(state->distbits), state->work);
985  if (ret) {
986  strm->msg = (char *)"invalid distances set";
987  state->mode = BAD;
988  break;
989  }
990  Tracev((stderr, "inflate: codes ok\n"));
991  state->mode = LEN_;
992  if (flush == Z_TREES) goto inf_leave;
993  case LEN_:
994  state->mode = LEN;
995  case LEN:
996  if (have >= 6 && left >= 258) {
997  RESTORE();
998  inflate_fast(strm, out);
999  LOAD();
1000  if (state->mode == TYPE)
1001  state->back = -1;
1002  break;
1003  }
1004  state->back = 0;
1005  for (;;) {
1006  here = state->lencode[BITS(state->lenbits)];
1007  if ((unsigned)(here.bits) <= bits) break;
1008  PULLBYTE();
1009  }
1010  if (here.op && (here.op & 0xf0) == 0) {
1011  last = here;
1012  for (;;) {
1013  here = state->lencode[last.val +
1014  (BITS(last.bits + last.op) >> last.bits)];
1015  if ((unsigned)(last.bits + here.bits) <= bits) break;
1016  PULLBYTE();
1017  }
1018  DROPBITS(last.bits);
1019  state->back += last.bits;
1020  }
1021  DROPBITS(here.bits);
1022  state->back += here.bits;
1023  state->length = (unsigned)here.val;
1024  if ((int)(here.op) == 0) {
1025  Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
1026  "inflate: literal '%c'\n" :
1027  "inflate: literal 0x%02x\n", here.val));
1028  state->mode = LIT;
1029  break;
1030  }
1031  if (here.op & 32) {
1032  Tracevv((stderr, "inflate: end of block\n"));
1033  state->back = -1;
1034  state->mode = TYPE;
1035  break;
1036  }
1037  if (here.op & 64) {
1038  strm->msg = (char *)"invalid literal/length code";
1039  state->mode = BAD;
1040  break;
1041  }
1042  state->extra = (unsigned)(here.op) & 15;
1043  state->mode = LENEXT;
1044  case LENEXT:
1045  if (state->extra) {
1046  NEEDBITS(state->extra);
1047  state->length += BITS(state->extra);
1048  DROPBITS(state->extra);
1049  state->back += state->extra;
1050  }
1051  Tracevv((stderr, "inflate: length %u\n", state->length));
1052  state->was = state->length;
1053  state->mode = DIST;
1054  case DIST:
1055  for (;;) {
1056  here = state->distcode[BITS(state->distbits)];
1057  if ((unsigned)(here.bits) <= bits) break;
1058  PULLBYTE();
1059  }
1060  if ((here.op & 0xf0) == 0) {
1061  last = here;
1062  for (;;) {
1063  here = state->distcode[last.val +
1064  (BITS(last.bits + last.op) >> last.bits)];
1065  if ((unsigned)(last.bits + here.bits) <= bits) break;
1066  PULLBYTE();
1067  }
1068  DROPBITS(last.bits);
1069  state->back += last.bits;
1070  }
1071  DROPBITS(here.bits);
1072  state->back += here.bits;
1073  if (here.op & 64) {
1074  strm->msg = (char *)"invalid distance code";
1075  state->mode = BAD;
1076  break;
1077  }
1078  state->offset = (unsigned)here.val;
1079  state->extra = (unsigned)(here.op) & 15;
1080  state->mode = DISTEXT;
1081  case DISTEXT:
1082  if (state->extra) {
1083  NEEDBITS(state->extra);
1084  state->offset += BITS(state->extra);
1085  DROPBITS(state->extra);
1086  state->back += state->extra;
1087  }
1088 #ifdef INFLATE_STRICT
1089  if (state->offset > state->dmax) {
1090  strm->msg = (char *)"invalid distance too far back";
1091  state->mode = BAD;
1092  break;
1093  }
1094 #endif
1095  Tracevv((stderr, "inflate: distance %u\n", state->offset));
1096  state->mode = MATCH;
1097  case MATCH:
1098  if (left == 0) goto inf_leave;
1099  copy = out - left;
1100  if (state->offset > copy) { /* copy from window */
1101  copy = state->offset - copy;
1102  if (copy > state->whave) {
1103  if (state->sane) {
1104  strm->msg = (char *)"invalid distance too far back";
1105  state->mode = BAD;
1106  break;
1107  }
1108 #ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
1109  Trace((stderr, "inflate.c too far\n"));
1110  copy -= state->whave;
1111  if (copy > state->length) copy = state->length;
1112  if (copy > left) copy = left;
1113  left -= copy;
1114  state->length -= copy;
1115  do {
1116  *put++ = 0;
1117  } while (--copy);
1118  if (state->length == 0) state->mode = LEN;
1119  break;
1120 #endif
1121  }
1122  if (copy > state->wnext) {
1123  copy -= state->wnext;
1124  from = state->window + (state->wsize - copy);
1125  }
1126  else
1127  from = state->window + (state->wnext - copy);
1128  if (copy > state->length) copy = state->length;
1129  }
1130  else { /* copy from output */
1131  from = put - state->offset;
1132  copy = state->length;
1133  }
1134  if (copy > left) copy = left;
1135  left -= copy;
1136  state->length -= copy;
1137  do {
1138  *put++ = *from++;
1139  } while (--copy);
1140  if (state->length == 0) state->mode = LEN;
1141  break;
1142  case LIT:
1143  if (left == 0) goto inf_leave;
1144  *put++ = (unsigned char)(state->length);
1145  left--;
1146  state->mode = LEN;
1147  break;
1148  case CHECK:
1149  if (state->wrap) {
1150  NEEDBITS(32);
1151  out -= left;
1152  strm->total_out += out;
1153  state->total += out;
1154  if (out)
1155  strm->adler = state->check =
1156  UPDATE(state->check, put - out, out);
1157  out = left;
1158  if ((
1159 #ifdef GUNZIP
1160  state->flags ? hold :
1161 #endif
1162  REVERSE(hold)) != state->check) {
1163  strm->msg = (char *)"incorrect data check";
1164  state->mode = BAD;
1165  break;
1166  }
1167  INITBITS();
1168  Tracev((stderr, "inflate: check matches trailer\n"));
1169  }
1170 #ifdef GUNZIP
1171  state->mode = LENGTH;
1172  case LENGTH:
1173  if (state->wrap && state->flags) {
1174  NEEDBITS(32);
1175  if (hold != (state->total & 0xffffffffUL)) {
1176  strm->msg = (char *)"incorrect length check";
1177  state->mode = BAD;
1178  break;
1179  }
1180  INITBITS();
1181  Tracev((stderr, "inflate: length matches trailer\n"));
1182  }
1183 #endif
1184  state->mode = DONE;
1185  case DONE:
1186  ret = Z_STREAM_END;
1187  goto inf_leave;
1188  case BAD:
1189  ret = Z_DATA_ERROR;
1190  goto inf_leave;
1191  case MEM:
1192  return Z_MEM_ERROR;
1193  case SYNC:
1194  default:
1195  return Z_STREAM_ERROR;
1196  }
1197 
1198  /*
1199  Return from inflate(), updating the total counts and the check value.
1200  If there was no progress during the inflate() call, return a buffer
1201  error. Call updatewindow() to create and/or update the window state.
1202  Note: a memory error from inflate() is non-recoverable.
1203  */
1204  inf_leave:
1205  RESTORE();
1206  if (state->wsize || (state->mode < CHECK && out != strm->avail_out))
1207  if (updatewindow(strm, out)) {
1208  state->mode = MEM;
1209  return Z_MEM_ERROR;
1210  }
1211  in -= strm->avail_in;
1212  out -= strm->avail_out;
1213  strm->total_in += in;
1214  strm->total_out += out;
1215  state->total += out;
1216  if (state->wrap && out)
1217  strm->adler = state->check =
1218  UPDATE(state->check, strm->next_out - out, out);
1219  strm->data_type = state->bits + (state->last ? 64 : 0) +
1220  (state->mode == TYPE ? 128 : 0) +
1221  (state->mode == LEN_ || state->mode == COPY_ ? 256 : 0);
1222  if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK)
1223  ret = Z_BUF_ERROR;
1224  return ret;
1225 }
#define RESTORE()
Definition: inflate.c:440
#define Z_BLOCK
Definition: zlib.h:177
unsigned nlen
Definition: inflate.h:114
Definition: inflate.h:38
unsigned short val
Definition: inftrees.h:29
#define NEEDBITS(n)
Definition: inflate.c:469
static void copy(const T &from, T &to)
Definition: Alg.h:61
int havedict
Definition: inflate.h:87
Definition: inflate.h:36
local void fixedtables(struct inflate_state FAR *state)
Definition: inflate.c:234
unsigned wnext
Definition: inflate.h:97
unsigned ndist
Definition: inflate.h:115
unsigned long total
Definition: inflate.h:91
gz_headerp head
Definition: inflate.h:92
unsigned wsize
Definition: inflate.h:95
unsigned have
Definition: inflate.h:116
unsigned distbits
Definition: inflate.h:111
#define Z_NEED_DICT
Definition: zlib.h:183
unsigned extra
Definition: inflate.h:106
Definition: inftrees.h:59
code const FAR * distcode
Definition: inflate.h:109
#define Tracev(x)
Definition: zutil.h:270
unsigned long check
Definition: inflate.h:90
Definition: inflate.h:51
Definition: inflate.h:29
#define REVERSE(q)
Definition: inflate.c:494
unsigned char op
Definition: inftrees.h:27
Definition: inflate.h:34
Definition: inflate.h:32
Definition: inflate.h:26
#define Z_STREAM_ERROR
Definition: zlib.h:185
unsigned lenbits
Definition: inflate.h:110
unsigned short lens[320]
Definition: inflate.h:118
Definition: inflate.h:43
unsigned ncode
Definition: inflate.h:113
Definition: inflate.h:39
void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start)
Definition: inffast.c:74
#define Z_FINISH
Definition: zlib.h:176
#define CRC2(check, word)
Definition: inflate.c:411
#define BYTEBITS()
Definition: inflate.c:487
Definition: inflate.h:50
int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens, unsigned codes, code FAR *FAR *table, unsigned FAR *bits, unsigned short FAR *work)
Definition: inftrees.c:39
#define LOAD()
Definition: inflate.c:429
code FAR * next
Definition: inflate.h:117
Definition: inflate.h:54
Definition: inflate.h:28
code codes[ENOUGH]
Definition: inflate.h:120
unsigned long hold
Definition: inflate.h:100
Definition: inflate.h:49
Definition: inftrees.h:57
#define Z_DEFLATED
Definition: zlib.h:213
Definition: inflate.h:44
#define Z_DATA_ERROR
Definition: zlib.h:186
Definition: inflate.h:48
#define Z_TREES
Definition: zlib.h:178
Definition: inflate.h:25
local int updatewindow(z_streamp strm, unsigned out)
Definition: inflate.c:351
#define Z_STREAM_END
Definition: zlib.h:182
Definition: inflate.h:33
if(last==0)
Definition: sparse_int.h:34
unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf, uInt len)
Definition: crc32.c:230
#define BITS(n)
Definition: inflate.c:476
#define UPDATE(check, buf, len)
Definition: inflate.c:403
#define GUNZIP
Definition: inflate.h:18
unsigned short work[288]
Definition: inflate.h:119
Definition: inflate.h:31
Definition: inflate.h:23
void ZLIB_INTERNAL zmemcpy(Bytef *dest, const Bytef *source, uInt len)
Definition: zutil.c:157
#define Z_MEM_ERROR
Definition: zlib.h:187
unsigned char bits
Definition: inftrees.h:28
#define Trace(x)
Definition: zutil.h:269
Definition: inftrees.h:26
unsigned dmax
Definition: inflate.h:89
unsigned bits
Definition: inflate.h:101
Definition: inflate.h:47
uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len)
Definition: adler32.c:67
Definition: inflate.h:35
#define INITBITS()
Definition: inflate.c:451
#define Z_BUF_ERROR
Definition: zlib.h:188
Definition: inflate.h:27
unsigned char FAR * window
Definition: inflate.h:98
inflate_mode mode
Definition: inflate.h:84
Definition: inflate.h:42
#define Z_OK
Definition: zlib.h:181
Definition: inflate.h:37
Definition: inftrees.h:58
Definition: inflate.h:52
#define PULLBYTE()
Definition: inflate.c:459
#define CRC4(check, word)
Definition: inflate.c:418
#define Z_NULL
Definition: zlib.h:216
unsigned whave
Definition: inflate.h:96
#define FAR
Definition: zconf.h:329
unsigned offset
Definition: inflate.h:104
static char * bits(int n)
Definition: abcSaucy.c:201
Definition: inflate.h:45
unsigned was
Definition: inflate.h:123
code const FAR * lencode
Definition: inflate.h:108
Definition: inflate.h:24
unsigned wbits
Definition: inflate.h:94
Definition: inflate.h:53
#define DROPBITS(n)
Definition: inflate.c:480
#define Tracevv(x)
Definition: zutil.h:271
unsigned length
Definition: inflate.h:103
int ZEXPORT inflateCopy ( z_streamp  dest,
z_streamp  source 
)

Definition at line 1384 of file inflate.c.

1385 {
1386  struct inflate_state FAR *state;
1387  struct inflate_state FAR *copy;
1388  unsigned char FAR *window;
1389  unsigned wsize;
1390 
1391  /* check input */
1392  if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL ||
1393  source->zalloc == (alloc_func)0 || source->zfree == (free_func)0)
1394  return Z_STREAM_ERROR;
1395  state = (struct inflate_state FAR *)source->state;
1396 
1397  /* allocate space */
1398  copy = (struct inflate_state FAR *)
1399  ZALLOC(source, 1, sizeof(struct inflate_state));
1400  if (copy == Z_NULL) return Z_MEM_ERROR;
1401  window = Z_NULL;
1402  if (state->window != Z_NULL) {
1403  window = (unsigned char FAR *)
1404  ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
1405  if (window == Z_NULL) {
1406  ZFREE(source, copy);
1407  return Z_MEM_ERROR;
1408  }
1409  }
1410 
1411  /* copy state */
1412  zmemcpy(dest, source, sizeof(z_stream));
1413  zmemcpy(copy, state, sizeof(struct inflate_state));
1414  if (state->lencode >= state->codes &&
1415  state->lencode <= state->codes + ENOUGH - 1) {
1416  copy->lencode = copy->codes + (state->lencode - state->codes);
1417  copy->distcode = copy->codes + (state->distcode - state->codes);
1418  }
1419  copy->next = copy->codes + (state->next - state->codes);
1420  if (window != Z_NULL) {
1421  wsize = 1U << state->wbits;
1422  zmemcpy(window, state->window, wsize);
1423  }
1424  copy->window = window;
1425  dest->state = (struct internal_state FAR *)copy;
1426  return Z_OK;
1427 }
static void copy(const T &from, T &to)
Definition: Alg.h:61
unsigned wsize
Definition: inflate.h:95
#define ENOUGH
Definition: inftrees.h:53
code const FAR * distcode
Definition: inflate.h:109
#define Z_STREAM_ERROR
Definition: zlib.h:185
#define ZALLOC(strm, items, size)
Definition: zutil.h:281
code FAR * next
Definition: inflate.h:117
code codes[ENOUGH]
Definition: inflate.h:120
#define ZFREE(strm, addr)
Definition: zutil.h:283
void ZLIB_INTERNAL zmemcpy(Bytef *dest, const Bytef *source, uInt len)
Definition: zutil.c:157
#define Z_MEM_ERROR
Definition: zlib.h:187
unsigned char FAR * window
Definition: inflate.h:98
#define Z_OK
Definition: zlib.h:181
#define Z_NULL
Definition: zlib.h:216
#define FAR
Definition: zconf.h:329
code const FAR * lencode
Definition: inflate.h:108
unsigned wbits
Definition: inflate.h:94
int ZEXPORT inflateEnd ( z_streamp  strm)

Definition at line 1227 of file inflate.c.

1228 {
1229  struct inflate_state FAR *state;
1230  if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
1231  return Z_STREAM_ERROR;
1232  state = (struct inflate_state FAR *)strm->state;
1233  if (state->window != Z_NULL) ZFREE(strm, state->window);
1234  ZFREE(strm, strm->state);
1235  strm->state = Z_NULL;
1236  Tracev((stderr, "inflate: end\n"));
1237  return Z_OK;
1238 }
#define Tracev(x)
Definition: zutil.h:270
#define Z_STREAM_ERROR
Definition: zlib.h:185
#define ZFREE(strm, addr)
Definition: zutil.h:283
if(last==0)
Definition: sparse_int.h:34
unsigned char FAR * window
Definition: inflate.h:98
#define Z_OK
Definition: zlib.h:181
#define Z_NULL
Definition: zlib.h:216
#define FAR
Definition: zconf.h:329
int ZEXPORT inflateGetHeader ( z_streamp  strm,
gz_headerp  head 
)

Definition at line 1279 of file inflate.c.

1280 {
1281  struct inflate_state FAR *state;
1282 
1283  /* check state */
1284  if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1285  state = (struct inflate_state FAR *)strm->state;
1286  if ((state->wrap & 2) == 0) return Z_STREAM_ERROR;
1287 
1288  /* save header structure */
1289  state->head = head;
1290  head->done = 0;
1291  return Z_OK;
1292 }
gz_headerp head
Definition: inflate.h:92
#define Z_STREAM_ERROR
Definition: zlib.h:185
if(last==0)
Definition: sparse_int.h:34
#define Z_OK
Definition: zlib.h:181
#define Z_NULL
Definition: zlib.h:216
#define FAR
Definition: zconf.h:329
int ZEXPORT inflateInit2_ ( z_streamp  strm,
int  windowBits,
const char *  version,
int  stream_size 
)

Definition at line 172 of file inflate.c.

173 {
174  int ret;
175  struct inflate_state FAR *state;
176 
177  if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
178  stream_size != (int)(sizeof(z_stream)))
179  return Z_VERSION_ERROR;
180  if (strm == Z_NULL) return Z_STREAM_ERROR;
181  strm->msg = Z_NULL; /* in case we return an error */
182  if (strm->zalloc == (alloc_func)0) {
183  strm->zalloc = zcalloc;
184  strm->opaque = (voidpf)0;
185  }
186  if (strm->zfree == (free_func)0) strm->zfree = zcfree;
187  state = (struct inflate_state FAR *)
188  ZALLOC(strm, 1, sizeof(struct inflate_state));
189  if (state == Z_NULL) return Z_MEM_ERROR;
190  Tracev((stderr, "inflate: allocated\n"));
191  strm->state = (struct internal_state FAR *)state;
192  state->window = Z_NULL;
193  ret = inflateReset2(strm, windowBits);
194  if (ret != Z_OK) {
195  ZFREE(strm, state);
196  strm->state = Z_NULL;
197  }
198  return ret;
199 }
Byte FAR * voidpf
Definition: zconf.h:355
#define Tracev(x)
Definition: zutil.h:270
#define Z_STREAM_ERROR
Definition: zlib.h:185
int ZEXPORT inflateReset2(z_streamp strm, int windowBits)
Definition: inflate.c:136
#define ZALLOC(strm, items, size)
Definition: zutil.h:281
z_streamp strm
Definition: deflate.h:97
string version
Definition: setup.py:63
#define ZFREE(strm, addr)
Definition: zutil.h:283
#define Z_MEM_ERROR
Definition: zlib.h:187
#define ZLIB_VERSION
Definition: zlib.h:48
#define Z_VERSION_ERROR
Definition: zlib.h:189
unsigned char FAR * window
Definition: inflate.h:98
#define Z_OK
Definition: zlib.h:181
#define Z_NULL
Definition: zlib.h:216
#define FAR
Definition: zconf.h:329
voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size)
Definition: zutil.c:300
void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr)
Definition: zutil.c:307
int ZEXPORT inflateInit_ ( z_streamp  strm,
const char *  version,
int  stream_size 
)

Definition at line 201 of file inflate.c.

202 {
203  return inflateInit2_(strm, DEF_WBITS, version, stream_size);
204 }
#define DEF_WBITS
Definition: zutil.h:57
z_streamp strm
Definition: deflate.h:97
string version
Definition: setup.py:63
int ZEXPORT inflateInit2_(z_streamp strm, int windowBits, const char *version, int stream_size)
Definition: inflate.c:172
long ZEXPORT inflateMark ( z_streamp  strm)

Definition at line 1444 of file inflate.c.

1445 {
1446  struct inflate_state FAR *state;
1447 
1448  if (strm == Z_NULL || strm->state == Z_NULL) return -1L << 16;
1449  state = (struct inflate_state FAR *)strm->state;
1450  return ((long)(state->back) << 16) +
1451  (state->mode == COPY ? state->length :
1452  (state->mode == MATCH ? state->was - state->length : 0));
1453 }
Definition: inflate.h:38
Definition: inflate.h:47
inflate_mode mode
Definition: inflate.h:84
#define Z_NULL
Definition: zlib.h:216
#define FAR
Definition: zconf.h:329
unsigned was
Definition: inflate.h:123
unsigned length
Definition: inflate.h:103
int ZEXPORT inflatePrime ( z_streamp  strm,
int  bits,
int  value 
)

Definition at line 206 of file inflate.c.

207 {
208  struct inflate_state FAR *state;
209 
210  if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
211  state = (struct inflate_state FAR *)strm->state;
212  if (bits < 0) {
213  state->hold = 0;
214  state->bits = 0;
215  return Z_OK;
216  }
217  if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR;
218  value &= (1L << bits) - 1;
219  state->hold += value << state->bits;
220  state->bits += bits;
221  return Z_OK;
222 }
#define Z_STREAM_ERROR
Definition: zlib.h:185
unsigned long hold
Definition: inflate.h:100
if(last==0)
Definition: sparse_int.h:34
unsigned bits
Definition: inflate.h:101
#define Z_OK
Definition: zlib.h:181
int value
#define Z_NULL
Definition: zlib.h:216
#define FAR
Definition: zconf.h:329
static char * bits(int n)
Definition: abcSaucy.c:201
int ZEXPORT inflateReset ( z_streamp  strm)

Definition at line 110 of file inflate.c.

111 {
112  struct inflate_state FAR *state;
113 
114  if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
115  state = (struct inflate_state FAR *)strm->state;
116  strm->total_in = strm->total_out = state->total = 0;
117  strm->msg = Z_NULL;
118  strm->adler = 1; /* to support ill-conceived Java test suite */
119  state->mode = HEAD;
120  state->last = 0;
121  state->havedict = 0;
122  state->dmax = 32768U;
123  state->head = Z_NULL;
124  state->wsize = 0;
125  state->whave = 0;
126  state->wnext = 0;
127  state->hold = 0;
128  state->bits = 0;
129  state->lencode = state->distcode = state->next = state->codes;
130  state->sane = 1;
131  state->back = -1;
132  Tracev((stderr, "inflate: reset\n"));
133  return Z_OK;
134 }
int havedict
Definition: inflate.h:87
unsigned wnext
Definition: inflate.h:97
unsigned long total
Definition: inflate.h:91
gz_headerp head
Definition: inflate.h:92
unsigned wsize
Definition: inflate.h:95
code const FAR * distcode
Definition: inflate.h:109
#define Tracev(x)
Definition: zutil.h:270
#define Z_STREAM_ERROR
Definition: zlib.h:185
code FAR * next
Definition: inflate.h:117
code codes[ENOUGH]
Definition: inflate.h:120
unsigned long hold
Definition: inflate.h:100
Definition: inflate.h:23
unsigned dmax
Definition: inflate.h:89
unsigned bits
Definition: inflate.h:101
inflate_mode mode
Definition: inflate.h:84
#define Z_OK
Definition: zlib.h:181
#define Z_NULL
Definition: zlib.h:216
unsigned whave
Definition: inflate.h:96
#define FAR
Definition: zconf.h:329
code const FAR * lencode
Definition: inflate.h:108
int ZEXPORT inflateReset2 ( z_streamp  strm,
int  windowBits 
)

Definition at line 136 of file inflate.c.

137 {
138  int wrap;
139  struct inflate_state FAR *state;
140 
141  /* get the state */
142  if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
143  state = (struct inflate_state FAR *)strm->state;
144 
145  /* extract wrap request from windowBits parameter */
146  if (windowBits < 0) {
147  wrap = 0;
148  windowBits = -windowBits;
149  }
150  else {
151  wrap = (windowBits >> 4) + 1;
152 #ifdef GUNZIP
153  if (windowBits < 48)
154  windowBits &= 15;
155 #endif
156  }
157 
158  /* set number of window bits, free window if different */
159  if (windowBits && (windowBits < 8 || windowBits > 15))
160  return Z_STREAM_ERROR;
161  if (state->window != Z_NULL && state->wbits != (unsigned)windowBits) {
162  ZFREE(strm, state->window);
163  state->window = Z_NULL;
164  }
165 
166  /* update state and reset the rest of it */
167  state->wrap = wrap;
168  state->wbits = (unsigned)windowBits;
169  return inflateReset(strm);
170 }
int ZEXPORT inflateReset(z_streamp strm)
Definition: inflate.c:110
#define Z_STREAM_ERROR
Definition: zlib.h:185
#define ZFREE(strm, addr)
Definition: zutil.h:283
if(last==0)
Definition: sparse_int.h:34
unsigned char FAR * window
Definition: inflate.h:98
#define Z_NULL
Definition: zlib.h:216
#define FAR
Definition: zconf.h:329
unsigned wbits
Definition: inflate.h:94
int ZEXPORT inflateSetDictionary ( z_streamp  strm,
const Bytef dictionary,
uInt  dictLength 
)

Definition at line 1240 of file inflate.c.

1241 {
1242  struct inflate_state FAR *state;
1243  unsigned long id;
1244 
1245  /* check state */
1246  if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1247  state = (struct inflate_state FAR *)strm->state;
1248  if (state->wrap != 0 && state->mode != DICT)
1249  return Z_STREAM_ERROR;
1250 
1251  /* check for correct dictionary id */
1252  if (state->mode == DICT) {
1253  id = adler32(0L, Z_NULL, 0);
1254  id = adler32(id, dictionary, dictLength);
1255  if (id != state->check)
1256  return Z_DATA_ERROR;
1257  }
1258 
1259  /* copy dictionary to window */
1260  if (updatewindow(strm, strm->avail_out)) {
1261  state->mode = MEM;
1262  return Z_MEM_ERROR;
1263  }
1264  if (dictLength > state->wsize) {
1265  zmemcpy(state->window, dictionary + dictLength - state->wsize,
1266  state->wsize);
1267  state->whave = state->wsize;
1268  }
1269  else {
1270  zmemcpy(state->window + state->wsize - dictLength, dictionary,
1271  dictLength);
1272  state->whave = dictLength;
1273  }
1274  state->havedict = 1;
1275  Tracev((stderr, "inflate: dictionary set\n"));
1276  return Z_OK;
1277 }
int havedict
Definition: inflate.h:87
unsigned wsize
Definition: inflate.h:95
#define Tracev(x)
Definition: zutil.h:270
unsigned long check
Definition: inflate.h:90
#define Z_STREAM_ERROR
Definition: zlib.h:185
#define Z_DATA_ERROR
Definition: zlib.h:186
local int updatewindow(z_streamp strm, unsigned out)
Definition: inflate.c:351
Definition: inflate.h:33
if(last==0)
Definition: sparse_int.h:34
void ZLIB_INTERNAL zmemcpy(Bytef *dest, const Bytef *source, uInt len)
Definition: zutil.c:157
#define Z_MEM_ERROR
Definition: zlib.h:187
uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len)
Definition: adler32.c:67
unsigned char FAR * window
Definition: inflate.h:98
inflate_mode mode
Definition: inflate.h:84
#define Z_OK
Definition: zlib.h:181
#define Z_NULL
Definition: zlib.h:216
unsigned whave
Definition: inflate.h:96
#define FAR
Definition: zconf.h:329
Definition: inflate.h:53
int ZEXPORT inflateSync ( z_streamp  strm)

Definition at line 1325 of file inflate.c.

1326 {
1327  unsigned len; /* number of bytes to look at or looked at */
1328  unsigned long in, out; /* temporary to save total_in and total_out */
1329  unsigned char buf[4]; /* to restore bit buffer to byte string */
1330  struct inflate_state FAR *state;
1331 
1332  /* check parameters */
1333  if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1334  state = (struct inflate_state FAR *)strm->state;
1335  if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;
1336 
1337  /* if first time, start search in bit buffer */
1338  if (state->mode != SYNC) {
1339  state->mode = SYNC;
1340  state->hold <<= state->bits & 7;
1341  state->bits -= state->bits & 7;
1342  len = 0;
1343  while (state->bits >= 8) {
1344  buf[len++] = (unsigned char)(state->hold);
1345  state->hold >>= 8;
1346  state->bits -= 8;
1347  }
1348  state->have = 0;
1349  syncsearch(&(state->have), buf, len);
1350  }
1351 
1352  /* search available input */
1353  len = syncsearch(&(state->have), strm->next_in, strm->avail_in);
1354  strm->avail_in -= len;
1355  strm->next_in += len;
1356  strm->total_in += len;
1357 
1358  /* return no joy or set up to restart inflate() on a new block */
1359  if (state->have != 4) return Z_DATA_ERROR;
1360  in = strm->total_in; out = strm->total_out;
1361  inflateReset(strm);
1362  strm->total_in = in; strm->total_out = out;
1363  state->mode = TYPE;
1364  return Z_OK;
1365 }
local unsigned syncsearch(unsigned FAR *have, unsigned char FAR *buf, unsigned len)
Definition: inflate.c:1305
int ZEXPORT inflateReset(z_streamp strm)
Definition: inflate.c:110
unsigned have
Definition: inflate.h:116
Definition: inflate.h:34
#define Z_STREAM_ERROR
Definition: zlib.h:185
Definition: inflate.h:54
unsigned long hold
Definition: inflate.h:100
#define Z_DATA_ERROR
Definition: zlib.h:186
if(last==0)
Definition: sparse_int.h:34
unsigned bits
Definition: inflate.h:101
#define Z_BUF_ERROR
Definition: zlib.h:188
inflate_mode mode
Definition: inflate.h:84
#define Z_OK
Definition: zlib.h:181
#define Z_NULL
Definition: zlib.h:216
#define FAR
Definition: zconf.h:329
int ZEXPORT inflateSyncPoint ( z_streamp  strm)

Definition at line 1375 of file inflate.c.

1376 {
1377  struct inflate_state FAR *state;
1378 
1379  if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1380  state = (struct inflate_state FAR *)strm->state;
1381  return state->mode == STORED && state->bits == 0;
1382 }
Definition: inflate.h:36
#define Z_STREAM_ERROR
Definition: zlib.h:185
unsigned bits
Definition: inflate.h:101
inflate_mode mode
Definition: inflate.h:84
#define Z_NULL
Definition: zlib.h:216
#define FAR
Definition: zconf.h:329
int ZEXPORT inflateUndermine ( z_streamp  strm,
int  subvert 
)

Definition at line 1429 of file inflate.c.

1430 {
1431  struct inflate_state FAR *state;
1432 
1433  if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1434  state = (struct inflate_state FAR *)strm->state;
1435  state->sane = !subvert;
1436 #ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
1437  return Z_OK;
1438 #else
1439  state->sane = 1;
1440  return Z_DATA_ERROR;
1441 #endif
1442 }
#define Z_STREAM_ERROR
Definition: zlib.h:185
#define Z_DATA_ERROR
Definition: zlib.h:186
#define Z_OK
Definition: zlib.h:181
#define Z_NULL
Definition: zlib.h:216
#define FAR
Definition: zconf.h:329
local int updatewindow OF ( (z_streamp strm, unsigned out)  )
local unsigned syncsearch OF ( (unsigned FAR *have, unsigned char FAR *buf, unsigned len)  )
local unsigned syncsearch ( unsigned FAR have,
unsigned char FAR buf,
unsigned  len 
)

Definition at line 1305 of file inflate.c.

1306 {
1307  unsigned got;
1308  unsigned next;
1309 
1310  got = *have;
1311  next = 0;
1312  while (next < len && got < 4) {
1313  if ((int)(buf[next]) == (got < 2 ? 0 : 0xff))
1314  got++;
1315  else if (buf[next])
1316  got = 0;
1317  else
1318  got = 4 - got;
1319  next++;
1320  }
1321  *have = got;
1322  return next;
1323 }
unsigned have
Definition: inflate.h:116
code FAR * next
Definition: inflate.h:117
local int updatewindow ( z_streamp  strm,
unsigned  out 
)

Definition at line 351 of file inflate.c.

352 {
353  struct inflate_state FAR *state;
354  unsigned copy, dist;
355 
356  state = (struct inflate_state FAR *)strm->state;
357 
358  /* if it hasn't been done already, allocate space for the window */
359  if (state->window == Z_NULL) {
360  state->window = (unsigned char FAR *)
361  ZALLOC(strm, 1U << state->wbits,
362  sizeof(unsigned char));
363  if (state->window == Z_NULL) return 1;
364  }
365 
366  /* if window not in use yet, initialize */
367  if (state->wsize == 0) {
368  state->wsize = 1U << state->wbits;
369  state->wnext = 0;
370  state->whave = 0;
371  }
372 
373  /* copy state->wsize or less output bytes into the circular window */
374  copy = out - strm->avail_out;
375  if (copy >= state->wsize) {
376  zmemcpy(state->window, strm->next_out - state->wsize, state->wsize);
377  state->wnext = 0;
378  state->whave = state->wsize;
379  }
380  else {
381  dist = state->wsize - state->wnext;
382  if (dist > copy) dist = copy;
383  zmemcpy(state->window + state->wnext, strm->next_out - copy, dist);
384  copy -= dist;
385  if (copy) {
386  zmemcpy(state->window, strm->next_out - copy, copy);
387  state->wnext = copy;
388  state->whave = state->wsize;
389  }
390  else {
391  state->wnext += dist;
392  if (state->wnext == state->wsize) state->wnext = 0;
393  if (state->whave < state->wsize) state->whave += dist;
394  }
395  }
396  return 0;
397 }
static void copy(const T &from, T &to)
Definition: Alg.h:61
unsigned wnext
Definition: inflate.h:97
unsigned wsize
Definition: inflate.h:95
#define ZALLOC(strm, items, size)
Definition: zutil.h:281
if(last==0)
Definition: sparse_int.h:34
void ZLIB_INTERNAL zmemcpy(Bytef *dest, const Bytef *source, uInt len)
Definition: zutil.c:157
unsigned char FAR * window
Definition: inflate.h:98
#define Z_NULL
Definition: zlib.h:216
unsigned whave
Definition: inflate.h:96
#define FAR
Definition: zconf.h:329
unsigned wbits
Definition: inflate.h:94