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

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()
 

Functions

local void fixedtables OF ((struct inflate_state FAR *state))
 
local int updatewindow OF ((z_streamp strm, const unsigned char FAR *end, unsigned copy))
 
local unsigned syncsearch OF ((unsigned FAR *have, const unsigned char FAR *buf, unsigned len))
 
int ZEXPORT inflateResetKeep (z_streamp strm)
 
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, const Bytef *end, unsigned copy)
 
int ZEXPORT inflate (z_streamp strm, int flush)
 
int ZEXPORT inflateEnd (z_streamp strm)
 
int ZEXPORT inflateGetDictionary (z_streamp strm, Bytef *dictionary, uInt *dictLength)
 
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, const 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 488 of file inflate.cc.

#define BYTEBITS ( )
Value:
do { \
hold >>= bits & 7; \
bits -= bits & 7; \
} while (0)
unsigned long hold
Definition: inflate.h:98
unsigned bits
Definition: inflate.h:99

Definition at line 499 of file inflate.cc.

#define CRC2 (   check,
  word 
)
Value:
do { \
hbuf[0] = (unsigned char)(word); \
hbuf[1] = (unsigned char)((word) >> 8); \
check = crc32(check, hbuf, 2); \
} while (0)
unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf, uInt len)
Definition: crc32.cc:202
unsigned long check
Definition: inflate.h:88

Definition at line 423 of file inflate.cc.

#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)
unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf, uInt len)
Definition: crc32.cc:202
unsigned long check
Definition: inflate.h:88

Definition at line 430 of file inflate.cc.

#define DROPBITS (   n)
Value:
do { \
hold >>= (n); \
bits -= (unsigned)(n); \
} while (0)
unsigned long hold
Definition: inflate.h:98
unsigned bits
Definition: inflate.h:99

Definition at line 492 of file inflate.cc.

#define INITBITS ( )
Value:
do { \
hold = 0; \
bits = 0; \
} while (0)
unsigned long hold
Definition: inflate.h:98
unsigned bits
Definition: inflate.h:99

Definition at line 463 of file inflate.cc.

#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:114
code FAR * next
Definition: inflate.h:115
unsigned long hold
Definition: inflate.h:98
unsigned bits
Definition: inflate.h:99

Definition at line 441 of file inflate.cc.

#define NEEDBITS (   n)
Value:
do { \
while (bits < (unsigned)(n)) \
} while (0)
unsigned bits
Definition: inflate.h:99
#define PULLBYTE()
Definition: inflate.cc:471

Definition at line 481 of file inflate.cc.

#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:114
if(nIso!=0)
code FAR * next
Definition: inflate.h:115
unsigned long hold
Definition: inflate.h:98
unsigned bits
Definition: inflate.h:99

Definition at line 471 of file inflate.cc.

#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:114
code FAR * next
Definition: inflate.h:115
unsigned long hold
Definition: inflate.h:98
unsigned bits
Definition: inflate.h:99

Definition at line 452 of file inflate.cc.

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

Definition at line 415 of file inflate.cc.

Function Documentation

local void fixedtables ( struct inflate_state FAR *  state)

Definition at line 247 of file inflate.cc.

248 {
249 #ifdef BUILDFIXED
250  static int virgin = 1;
251  static code *lenfix, *distfix;
252  static code fixed[544];
253 
254  /* build fixed huffman tables if first call (may not be thread safe) */
255  if (virgin) {
256  unsigned sym, bits;
257  static code *next;
258 
259  /* literal/length table */
260  sym = 0;
261  while (sym < 144) state->lens[sym++] = 8;
262  while (sym < 256) state->lens[sym++] = 9;
263  while (sym < 280) state->lens[sym++] = 7;
264  while (sym < 288) state->lens[sym++] = 8;
265  next = fixed;
266  lenfix = next;
267  bits = 9;
268  inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
269 
270  /* distance table */
271  sym = 0;
272  while (sym < 32) state->lens[sym++] = 5;
273  distfix = next;
274  bits = 5;
275  inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
276 
277  /* do this just once */
278  virgin = 0;
279  }
280 #else /* !BUILDFIXED */
281 # include "inffixed.h"
282 #endif /* BUILDFIXED */
283  state->lencode = lenfix;
284  state->lenbits = 9;
285  state->distcode = distfix;
286  state->distbits = 5;
287 }
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.cc:32
Definition: inftrees.h:57
static const code lenfix[512]
Definition: inffixed.h:10
code FAR * next
Definition: inflate.h:115
static const code distfix[32]
Definition: inffixed.h:87
Definition: inftrees.h:24
unsigned bits
Definition: inflate.h:99
Definition: inftrees.h:56

Here is the call graph for this function:

int ZEXPORT inflate ( z_streamp  strm,
int  flush 
)

Definition at line 587 of file inflate.cc.

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

Here is the call graph for this function:

Here is the caller graph for this function:

int ZEXPORT inflateCopy ( z_streamp  dest,
z_streamp  source 
)

Definition at line 1404 of file inflate.cc.

1405 {
1406  struct inflate_state FAR *state;
1407  struct inflate_state FAR *copy;
1408  unsigned char FAR *window;
1409  unsigned wsize;
1410 
1411  /* check input */
1412  if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL ||
1413  source->zalloc == (alloc_func)0 || source->zfree == (free_func)0)
1414  return Z_STREAM_ERROR;
1415  state = (struct inflate_state FAR *)source->state;
1416 
1417  /* allocate space */
1418  copy = (struct inflate_state FAR *)
1419  ZALLOC(source, 1, sizeof(struct inflate_state));
1420  if (copy == Z_NULL) return Z_MEM_ERROR;
1421  window = Z_NULL;
1422  if (state->window != Z_NULL) {
1423  window = (unsigned char FAR *)
1424  ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
1425  if (window == Z_NULL) {
1426  ZFREE(source, copy);
1427  return Z_MEM_ERROR;
1428  }
1429  }
1430 
1431  /* copy state */
1432  zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream));
1433  zmemcpy((voidpf)copy, (voidpf)state, sizeof(struct inflate_state));
1434  if (state->lencode >= state->codes &&
1435  state->lencode <= state->codes + ENOUGH - 1) {
1436  copy->lencode = copy->codes + (state->lencode - state->codes);
1437  copy->distcode = copy->codes + (state->distcode - state->codes);
1438  }
1439  copy->next = copy->codes + (state->next - state->codes);
1440  if (window != Z_NULL) {
1441  wsize = 1U << state->wbits;
1442  zmemcpy(window, state->window, wsize);
1443  }
1444  copy->window = window;
1445  dest->state = (struct internal_state FAR *)copy;
1446  return Z_OK;
1447 }
unsigned wsize
Definition: inflate.h:93
#define ENOUGH
Definition: inftrees.h:51
void ZLIB_INTERNAL zmemcpy(Bytef *dest, const Bytef *source, uInt len)
Definition: zutil.cc:150
#define Z_STREAM_ERROR
Definition: zlib.h:177
#define ZALLOC(strm, items, size)
Definition: zutil.h:244
#define ZFREE(strm, addr)
Definition: zutil.h:246
#define Z_MEM_ERROR
Definition: zlib.h:179
unsigned char FAR * window
Definition: inflate.h:96
#define Z_OK
Definition: zlib.h:173
#define Z_NULL
Definition: zlib.h:208
unsigned wbits
Definition: inflate.h:92

Here is the call graph for this function:

int ZEXPORT inflateEnd ( z_streamp  strm)

Definition at line 1234 of file inflate.cc.

1235 {
1236  struct inflate_state FAR *state;
1237  if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
1238  return Z_STREAM_ERROR;
1239  state = (struct inflate_state FAR *)strm->state;
1240  if (state->window != Z_NULL) ZFREE(strm, state->window);
1241  ZFREE(strm, strm->state);
1242  strm->state = Z_NULL;
1243  Tracev((stderr, "inflate: end\n"));
1244  return Z_OK;
1245 }
#define Tracev(x)
Definition: zutil.h:232
if(nIso!=0)
#define Z_STREAM_ERROR
Definition: zlib.h:177
#define ZFREE(strm, addr)
Definition: zutil.h:246
unsigned char FAR * window
Definition: inflate.h:96
#define Z_OK
Definition: zlib.h:173
#define Z_NULL
Definition: zlib.h:208

Here is the call graph for this function:

Here is the caller graph for this function:

int ZEXPORT inflateGetDictionary ( z_streamp  strm,
Bytef *  dictionary,
uInt *  dictLength 
)

Definition at line 1247 of file inflate.cc.

1248 {
1249  struct inflate_state FAR *state;
1250 
1251  /* check state */
1252  if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1253  state = (struct inflate_state FAR *)strm->state;
1254 
1255  /* copy dictionary */
1256  if (state->whave && dictionary != Z_NULL) {
1257  zmemcpy(dictionary, state->window + state->wnext,
1258  state->whave - state->wnext);
1259  zmemcpy(dictionary + state->whave - state->wnext,
1260  state->window, state->wnext);
1261  }
1262  if (dictLength != Z_NULL)
1263  *dictLength = state->whave;
1264  return Z_OK;
1265 }
unsigned wnext
Definition: inflate.h:95
if(nIso!=0)
void ZLIB_INTERNAL zmemcpy(Bytef *dest, const Bytef *source, uInt len)
Definition: zutil.cc:150
#define Z_STREAM_ERROR
Definition: zlib.h:177
unsigned char FAR * window
Definition: inflate.h:96
#define Z_OK
Definition: zlib.h:173
#define Z_NULL
Definition: zlib.h:208
unsigned whave
Definition: inflate.h:94

Here is the call graph for this function:

int ZEXPORT inflateGetHeader ( z_streamp  strm,
gz_headerp  head 
)

Definition at line 1299 of file inflate.cc.

1300 {
1301  struct inflate_state FAR *state;
1302 
1303  /* check state */
1304  if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1305  state = (struct inflate_state FAR *)strm->state;
1306  if ((state->wrap & 2) == 0) return Z_STREAM_ERROR;
1307 
1308  /* save header structure */
1309  state->head = head;
1310  head->done = 0;
1311  return Z_OK;
1312 }
gz_headerp head
Definition: inflate.h:90
if(nIso!=0)
#define Z_STREAM_ERROR
Definition: zlib.h:177
#define Z_OK
Definition: zlib.h:173
#define Z_NULL
Definition: zlib.h:208

Here is the call graph for this function:

int ZEXPORT inflateInit2_ ( z_streamp  strm,
int  windowBits,
const char *  version,
int  stream_size 
)

Definition at line 176 of file inflate.cc.

177 {
178  int ret;
179  struct inflate_state FAR *state;
180 
181  if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
182  stream_size != (int)(sizeof(z_stream)))
183  return Z_VERSION_ERROR;
184  if (strm == Z_NULL) return Z_STREAM_ERROR;
185  strm->msg = Z_NULL; /* in case we return an error */
186  if (strm->zalloc == (alloc_func)0) {
187 #ifdef Z_SOLO
188  return Z_STREAM_ERROR;
189 #else
190  strm->zalloc = zcalloc;
191  strm->opaque = (voidpf)0;
192 #endif
193  }
194  if (strm->zfree == (free_func)0)
195 #ifdef Z_SOLO
196  return Z_STREAM_ERROR;
197 #else
198  strm->zfree = zcfree;
199 #endif
200  state = (struct inflate_state FAR *)
201  ZALLOC(strm, 1, sizeof(struct inflate_state));
202  if (state == Z_NULL) return Z_MEM_ERROR;
203  Tracev((stderr, "inflate: allocated\n"));
204  strm->state = (struct internal_state FAR *)state;
205  state->window = Z_NULL;
206  ret = inflateReset2(strm, windowBits);
207  if (ret != Z_OK) {
208  ZFREE(strm, state);
209  strm->state = Z_NULL;
210  }
211  return ret;
212 }
voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size)
Definition: zutil.cc:294
int ZEXPORT inflateReset2(z_streamp strm, int windowBits)
Definition: inflate.cc:140
#define Tracev(x)
Definition: zutil.h:232
#define Z_STREAM_ERROR
Definition: zlib.h:177
#define ZALLOC(strm, items, size)
Definition: zutil.h:244
z_streamp strm
Definition: deflate.h:98
#define ZFREE(strm, addr)
Definition: zutil.h:246
void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr)
Definition: zutil.cc:301
#define Z_MEM_ERROR
Definition: zlib.h:179
const XML_Char * version
Definition: expat.h:187
#define ZLIB_VERSION
Definition: zlib.h:40
#define Z_VERSION_ERROR
Definition: zlib.h:181
unsigned char FAR * window
Definition: inflate.h:96
#define Z_OK
Definition: zlib.h:173
#define Z_NULL
Definition: zlib.h:208

Here is the call graph for this function:

Here is the caller graph for this function:

int ZEXPORT inflateInit_ ( z_streamp  strm,
const char *  version,
int  stream_size 
)

Definition at line 214 of file inflate.cc.

215 {
216  return inflateInit2_(strm, DEF_WBITS, version, stream_size);
217 }
int ZEXPORT inflateInit2_(z_streamp strm, int windowBits, const char *version, int stream_size)
Definition: inflate.cc:176
#define DEF_WBITS
Definition: zutil.h:59
z_streamp strm
Definition: deflate.h:98
const XML_Char * version
Definition: expat.h:187

Here is the call graph for this function:

long ZEXPORT inflateMark ( z_streamp  strm)

Definition at line 1464 of file inflate.cc.

1465 {
1466  struct inflate_state FAR *state;
1467 
1468  if (strm == Z_NULL || strm->state == Z_NULL) return 0xffffFFFFffff0000L; // shut off clang
1469  // warning from -1L << 16;
1470  state = (struct inflate_state FAR *)strm->state;
1471  return ((long)(state->back) << 16) +
1472  (state->mode == COPY ? state->length :
1473  (state->mode == MATCH ? state->was - state->length : 0));
1474 }
Definition: inflate.h:36
Definition: inflate.h:45
inflate_mode mode
Definition: inflate.h:82
#define Z_NULL
Definition: zlib.h:208
static constexpr double L
Definition: G4SIunits.hh:124
unsigned was
Definition: inflate.h:121
unsigned length
Definition: inflate.h:101
int ZEXPORT inflatePrime ( z_streamp  strm,
int  bits,
int  value 
)

Definition at line 219 of file inflate.cc.

220 {
221  struct inflate_state FAR *state;
222 
223  if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
224  state = (struct inflate_state FAR *)strm->state;
225  if (bits < 0) {
226  state->hold = 0;
227  state->bits = 0;
228  return Z_OK;
229  }
230  if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR;
231  value &= (1L << bits) - 1;
232  state->hold += value << state->bits;
233  state->bits += bits;
234  return Z_OK;
235 }
if(nIso!=0)
#define Z_STREAM_ERROR
Definition: zlib.h:177
const XML_Char int const XML_Char * value
Definition: expat.h:331
unsigned long hold
Definition: inflate.h:98
unsigned bits
Definition: inflate.h:99
#define Z_OK
Definition: zlib.h:173
#define Z_NULL
Definition: zlib.h:208
static constexpr double L
Definition: G4SIunits.hh:124

Here is the call graph for this function:

int ZEXPORT inflateReset ( z_streamp  strm)

Definition at line 128 of file inflate.cc.

129 {
130  struct inflate_state FAR *state;
131 
132  if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
133  state = (struct inflate_state FAR *)strm->state;
134  state->wsize = 0;
135  state->whave = 0;
136  state->wnext = 0;
137  return inflateResetKeep(strm);
138 }
unsigned wnext
Definition: inflate.h:95
unsigned wsize
Definition: inflate.h:93
#define Z_STREAM_ERROR
Definition: zlib.h:177
int ZEXPORT inflateResetKeep(z_streamp strm)
Definition: inflate.cc:104
#define Z_NULL
Definition: zlib.h:208
unsigned whave
Definition: inflate.h:94

Here is the call graph for this function:

Here is the caller graph for this function:

int ZEXPORT inflateReset2 ( z_streamp  strm,
int  windowBits 
)

Definition at line 140 of file inflate.cc.

141 {
142  int wrap;
143  struct inflate_state FAR *state;
144 
145  /* get the state */
146  if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
147  state = (struct inflate_state FAR *)strm->state;
148 
149  /* extract wrap request from windowBits parameter */
150  if (windowBits < 0) {
151  wrap = 0;
152  windowBits = -windowBits;
153  }
154  else {
155  wrap = (windowBits >> 4) + 1;
156 #ifdef GUNZIP
157  if (windowBits < 48)
158  windowBits &= 15;
159 #endif
160  }
161 
162  /* set number of window bits, free window if different */
163  if (windowBits && (windowBits < 8 || windowBits > 15))
164  return Z_STREAM_ERROR;
165  if (state->window != Z_NULL && state->wbits != (unsigned)windowBits) {
166  ZFREE(strm, state->window);
167  state->window = Z_NULL;
168  }
169 
170  /* update state and reset the rest of it */
171  state->wrap = wrap;
172  state->wbits = (unsigned)windowBits;
173  return inflateReset(strm);
174 }
if(nIso!=0)
#define Z_STREAM_ERROR
Definition: zlib.h:177
#define ZFREE(strm, addr)
Definition: zutil.h:246
unsigned char FAR * window
Definition: inflate.h:96
#define Z_NULL
Definition: zlib.h:208
unsigned wbits
Definition: inflate.h:92
int ZEXPORT inflateReset(z_streamp strm)
Definition: inflate.cc:128

Here is the call graph for this function:

Here is the caller graph for this function:

int ZEXPORT inflateResetKeep ( z_streamp  strm)

Definition at line 104 of file inflate.cc.

105 {
106  struct inflate_state FAR *state;
107 
108  if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
109  state = (struct inflate_state FAR *)strm->state;
110  strm->total_in = strm->total_out = state->total = 0;
111  strm->msg = Z_NULL;
112  if (state->wrap) /* to support ill-conceived Java test suite */
113  strm->adler = state->wrap & 1;
114  state->mode = HEAD;
115  state->last = 0;
116  state->havedict = 0;
117  state->dmax = 32768U;
118  state->head = Z_NULL;
119  state->hold = 0;
120  state->bits = 0;
121  state->lencode = state->distcode = state->next = state->codes;
122  state->sane = 1;
123  state->back = -1;
124  Tracev((stderr, "inflate: reset\n"));
125  return Z_OK;
126 }
int havedict
Definition: inflate.h:85
unsigned long total
Definition: inflate.h:89
gz_headerp head
Definition: inflate.h:90
code const FAR * distcode
Definition: inflate.h:107
#define Tracev(x)
Definition: zutil.h:232
if(nIso!=0)
#define Z_STREAM_ERROR
Definition: zlib.h:177
code FAR * next
Definition: inflate.h:115
code codes[ENOUGH]
Definition: inflate.h:118
unsigned long hold
Definition: inflate.h:98
Definition: inflate.h:21
unsigned dmax
Definition: inflate.h:87
unsigned bits
Definition: inflate.h:99
inflate_mode mode
Definition: inflate.h:82
#define Z_OK
Definition: zlib.h:173
#define Z_NULL
Definition: zlib.h:208
code const FAR * lencode
Definition: inflate.h:106

Here is the call graph for this function:

Here is the caller graph for this function:

int ZEXPORT inflateSetDictionary ( z_streamp  strm,
const Bytef *  dictionary,
uInt  dictLength 
)

Definition at line 1267 of file inflate.cc.

1268 {
1269  struct inflate_state FAR *state;
1270  unsigned long dictid;
1271  int ret;
1272 
1273  /* check state */
1274  if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1275  state = (struct inflate_state FAR *)strm->state;
1276  if (state->wrap != 0 && state->mode != DICT)
1277  return Z_STREAM_ERROR;
1278 
1279  /* check for correct dictionary identifier */
1280  if (state->mode == DICT) {
1281  dictid = adler32(0L, Z_NULL, 0);
1282  dictid = adler32(dictid, dictionary, dictLength);
1283  if (dictid != state->check)
1284  return Z_DATA_ERROR;
1285  }
1286 
1287  /* copy dictionary to window using updatewindow(), which will amend the
1288  existing dictionary if appropriate */
1289  ret = updatewindow(strm, dictionary + dictLength, dictLength);
1290  if (ret) {
1291  state->mode = MEM;
1292  return Z_MEM_ERROR;
1293  }
1294  state->havedict = 1;
1295  Tracev((stderr, "inflate: dictionary set\n"));
1296  return Z_OK;
1297 }
int havedict
Definition: inflate.h:85
local int updatewindow(z_streamp strm, const Bytef *end, unsigned copy)
Definition: inflate.cc:364
#define Tracev(x)
Definition: zutil.h:232
if(nIso!=0)
unsigned long check
Definition: inflate.h:88
uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len)
Definition: adler32.cc:65
#define Z_STREAM_ERROR
Definition: zlib.h:177
#define Z_DATA_ERROR
Definition: zlib.h:178
Definition: inflate.h:31
#define Z_MEM_ERROR
Definition: zlib.h:179
inflate_mode mode
Definition: inflate.h:82
#define Z_OK
Definition: zlib.h:173
#define Z_NULL
Definition: zlib.h:208
static constexpr double L
Definition: G4SIunits.hh:124
Definition: inflate.h:51

Here is the call graph for this function:

int ZEXPORT inflateSync ( z_streamp  strm)

Definition at line 1345 of file inflate.cc.

1346 {
1347  unsigned len; /* number of bytes to look at or looked at */
1348  unsigned long in, out; /* temporary to save total_in and total_out */
1349  unsigned char buf[4]; /* to restore bit buffer to byte string */
1350  struct inflate_state FAR *state;
1351 
1352  /* check parameters */
1353  if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1354  state = (struct inflate_state FAR *)strm->state;
1355  if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;
1356 
1357  /* if first time, start search in bit buffer */
1358  if (state->mode != SYNC) {
1359  state->mode = SYNC;
1360  state->hold <<= state->bits & 7;
1361  state->bits -= state->bits & 7;
1362  len = 0;
1363  while (state->bits >= 8) {
1364  buf[len++] = (unsigned char)(state->hold);
1365  state->hold >>= 8;
1366  state->bits -= 8;
1367  }
1368  state->have = 0;
1369  syncsearch(&(state->have), buf, len);
1370  }
1371 
1372  /* search available input */
1373  len = syncsearch(&(state->have), strm->next_in, strm->avail_in);
1374  strm->avail_in -= len;
1375  strm->next_in += len;
1376  strm->total_in += len;
1377 
1378  /* return no joy or set up to restart inflate() on a new block */
1379  if (state->have != 4) return Z_DATA_ERROR;
1380  in = strm->total_in; out = strm->total_out;
1381  inflateReset(strm);
1382  strm->total_in = in; strm->total_out = out;
1383  state->mode = TYPE;
1384  return Z_OK;
1385 }
const XML_Char int len
Definition: expat.h:262
unsigned have
Definition: inflate.h:114
local unsigned syncsearch(unsigned FAR *have, const unsigned char FAR *buf, unsigned len)
Definition: inflate.cc:1325
if(nIso!=0)
Definition: inflate.h:32
#define Z_STREAM_ERROR
Definition: zlib.h:177
Definition: inflate.h:52
unsigned long hold
Definition: inflate.h:98
#define Z_DATA_ERROR
Definition: zlib.h:178
unsigned bits
Definition: inflate.h:99
#define Z_BUF_ERROR
Definition: zlib.h:180
inflate_mode mode
Definition: inflate.h:82
#define Z_OK
Definition: zlib.h:173
#define Z_NULL
Definition: zlib.h:208
int ZEXPORT inflateReset(z_streamp strm)
Definition: inflate.cc:128

Here is the call graph for this function:

int ZEXPORT inflateSyncPoint ( z_streamp  strm)

Definition at line 1395 of file inflate.cc.

1396 {
1397  struct inflate_state FAR *state;
1398 
1399  if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1400  state = (struct inflate_state FAR *)strm->state;
1401  return state->mode == STORED && state->bits == 0;
1402 }
Definition: inflate.h:34
#define Z_STREAM_ERROR
Definition: zlib.h:177
unsigned bits
Definition: inflate.h:99
inflate_mode mode
Definition: inflate.h:82
#define Z_NULL
Definition: zlib.h:208
int ZEXPORT inflateUndermine ( z_streamp  strm,
int  subvert 
)

Definition at line 1449 of file inflate.cc.

1450 {
1451  struct inflate_state FAR *state;
1452 
1453  if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1454  state = (struct inflate_state FAR *)strm->state;
1455  state->sane = !subvert;
1456 #ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
1457  return Z_OK;
1458 #else
1459  state->sane = 1;
1460  return Z_DATA_ERROR;
1461 #endif
1462 }
#define Z_STREAM_ERROR
Definition: zlib.h:177
#define Z_DATA_ERROR
Definition: zlib.h:178
#define Z_OK
Definition: zlib.h:173
#define Z_NULL
Definition: zlib.h:208
local void fixedtables OF ( (struct inflate_state FAR *state)  )
local int updatewindow OF ( (z_streamp strm, const unsigned char FAR *end, unsigned copy)  )
local unsigned syncsearch OF ( (unsigned FAR *have, const unsigned char FAR *buf, unsigned len )
local unsigned syncsearch ( unsigned FAR *  have,
const unsigned char FAR *  buf,
unsigned  len 
)

Definition at line 1325 of file inflate.cc.

1326 {
1327  unsigned got;
1328  unsigned next;
1329 
1330  got = *have;
1331  next = 0;
1332  while (next < len && got < 4) {
1333  if ((int)(buf[next]) == (got < 2 ? 0 : 0xff))
1334  got++;
1335  else if (buf[next])
1336  got = 0;
1337  else
1338  got = 4 - got;
1339  next++;
1340  }
1341  *have = got;
1342  return next;
1343 }
const XML_Char int len
Definition: expat.h:262
unsigned have
Definition: inflate.h:114
code FAR * next
Definition: inflate.h:115

Here is the caller graph for this function:

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

Definition at line 364 of file inflate.cc.

365 {
366  struct inflate_state FAR *state;
367  unsigned dist;
368 
369  state = (struct inflate_state FAR *)strm->state;
370 
371  /* if it hasn't been done already, allocate space for the window */
372  if (state->window == Z_NULL) {
373  state->window = (unsigned char FAR *)
374  ZALLOC(strm, 1U << state->wbits,
375  sizeof(unsigned char));
376  if (state->window == Z_NULL) return 1;
377  }
378 
379  /* if window not in use yet, initialize */
380  if (state->wsize == 0) {
381  state->wsize = 1U << state->wbits;
382  state->wnext = 0;
383  state->whave = 0;
384  }
385 
386  /* copy state->wsize or less output bytes into the circular window */
387 
388  if (copy >= state->wsize) {
389  zmemcpy(state->window, end - state->wsize, state->wsize);
390  state->wnext = 0;
391  state->whave = state->wsize;
392  }
393  else {
394  dist = state->wsize - state->wnext;
395  if (dist > copy) dist = copy;
396  zmemcpy(state->window + state->wnext, end - copy, dist);
397  copy -= dist;
398  if (copy) {
399  zmemcpy(state->window, end - copy, copy);
400  state->wnext = copy;
401  state->whave = state->wsize;
402  }
403  else {
404  state->wnext += dist;
405  if (state->wnext == state->wsize) state->wnext = 0;
406  if (state->whave < state->wsize) state->whave += dist;
407  }
408  }
409  return 0;
410 }
unsigned wnext
Definition: inflate.h:95
unsigned wsize
Definition: inflate.h:93
if(nIso!=0)
void ZLIB_INTERNAL zmemcpy(Bytef *dest, const Bytef *source, uInt len)
Definition: zutil.cc:150
#define ZALLOC(strm, items, size)
Definition: zutil.h:244
unsigned char FAR * window
Definition: inflate.h:96
#define Z_NULL
Definition: zlib.h:208
unsigned whave
Definition: inflate.h:94
unsigned wbits
Definition: inflate.h:92

Here is the call graph for this function:

Here is the caller graph for this function: