Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Macros | Functions
inflate.cc File Reference
#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()
 

Functions

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 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, 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 488 of file inflate.cc.

Referenced by inflate().

#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.

Referenced by inflate().

#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.

Referenced by inflate().

#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.

Referenced by inflate().

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

Definition at line 492 of file inflate.cc.

Referenced by inflate().

#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.

Referenced by inflate().

#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.

Referenced by inflate().

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

Definition at line 481 of file inflate.cc.

Referenced by inflate().

#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
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.

Referenced by inflate().

#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.

Referenced by inflate().

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

Definition at line 415 of file inflate.cc.

Referenced by inflate().

Function Documentation

local void fixedtables ( struct inflate_state FAR *  state)

Definition at line 246 of file inflate.cc.

References inflate_state::bits, DISTS, inflate_table(), LENS, and inflate_state::next.

Referenced by inflate().

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

Definition at line 587 of file inflate.cc.

References adler32(), inflate_state::back, BAD, code::bits, inflate_state::bits, BITS, BYTEBITS, CHECK, inflate_state::check, CODELENS, CODES, inflate_state::codes, COMMENT, COPY, copy(), COPY_, CRC2, crc32(), CRC4, DICT, DICTID, DIST, inflate_state::distbits, inflate_state::distcode, DISTEXT, DISTS, inflate_state::dmax, DONE, DROPBITS, EXLEN, EXTRA, inflate_state::extra, fixedtables(), FLAGS, inflate_state::flags, GUNZIP, inflate_state::have, inflate_state::havedict, HCRC, HEAD, inflate_state::head, inflate_state::hold, inflate_fast(), inflate_table(), INITBITS, int(), inflate_state::last, left, LEN, LEN_, inflate_state::lenbits, inflate_state::lencode, LENEXT, LENGTH, inflate_state::length, LENLENS, LENS, inflate_state::lens, LIT, LOAD, MATCH, MEM, inflate_state::mode, NAME, inflate_state::ncode, inflate_state::ndist, NEEDBITS, inflate_state::next, inflate_state::nlen, inflate_state::offset, code::op, OS_zlib, PULLBYTE, RESTORE, inflate_state::sane, STORED, SYNC, TABLE, TIME, inflate_state::total, Trace, Tracev, Tracevv, TYPE, TYPEDO, UPDATE, updatewindow(), code::val, inflate_state::was, inflate_state::wbits, inflate_state::whave, inflate_state::window, inflate_state::wnext, inflate_state::work, inflate_state::wrap, inflate_state::wsize, Z_BLOCK, Z_BUF_ERROR, Z_DATA_ERROR, Z_DEFLATED, Z_FINISH, Z_MEM_ERROR, Z_NEED_DICT, Z_NULL, Z_OK, Z_STREAM_END, Z_STREAM_ERROR, Z_TREES, zmemcpy(), and ZSWAP32.

Referenced by gz_decomp(), and uncompress().

588 {
589  struct inflate_state FAR *state;
590  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 = (code const 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 = (code const 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 = (code const 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, 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 }
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
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
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
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 Tracev(x)
Definition: zutil.h:231
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:249
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
void copy(std::vector< T > &main, const std::vector< T > &data)
Definition: DicomRun.hh:91
#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
#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 Trace(x)
Definition: zutil.h:230
#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
#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
const XML_Char int len
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
unsigned was
Definition: inflate.h:121
code const FAR * lencode
Definition: inflate.h:106
local void fixedtables(struct inflate_state FAR *state)
Definition: inflate.cc:246
Definition: inflate.h:22
unsigned wbits
Definition: inflate.h:92
local int updatewindow(z_streamp strm, unsigned out)
Definition: inflate.cc:363
Definition: inflate.h:51
#define Tracevv(x)
Definition: zutil.h:232
unsigned length
Definition: inflate.h:101
int ZEXPORT inflateCopy ( z_streamp  dest,
z_streamp  source 
)

Definition at line 1392 of file inflate.cc.

References copy(), ENOUGH, inflate_state::wbits, inflate_state::window, inflate_state::wsize, Z_MEM_ERROR, Z_NULL, Z_OK, Z_STREAM_ERROR, ZALLOC, ZFREE, and zmemcpy().

1393 {
1394  struct inflate_state FAR *state;
1395  struct inflate_state FAR *copy;
1396  unsigned char FAR *window;
1397  unsigned wsize;
1398 
1399  /* check input */
1400  if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL ||
1401  source->zalloc == (alloc_func)0 || source->zfree == (free_func)0)
1402  return Z_STREAM_ERROR;
1403  state = (struct inflate_state FAR *)source->state;
1404 
1405  /* allocate space */
1406  copy = (struct inflate_state FAR *)
1407  ZALLOC(source, 1, sizeof(struct inflate_state));
1408  if (copy == Z_NULL) return Z_MEM_ERROR;
1409  window = Z_NULL;
1410  if (state->window != Z_NULL) {
1411  window = (unsigned char FAR *)
1412  ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
1413  if (window == Z_NULL) {
1414  ZFREE(source, copy);
1415  return Z_MEM_ERROR;
1416  }
1417  }
1418 
1419  /* copy state */
1420  zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream));
1421  zmemcpy((voidpf)copy, (voidpf)state, sizeof(struct inflate_state));
1422  if (state->lencode >= state->codes &&
1423  state->lencode <= state->codes + ENOUGH - 1) {
1424  copy->lencode = copy->codes + (state->lencode - state->codes);
1425  copy->distcode = copy->codes + (state->distcode - state->codes);
1426  }
1427  copy->next = copy->codes + (state->next - state->codes);
1428  if (window != Z_NULL) {
1429  wsize = 1U << state->wbits;
1430  zmemcpy(window, state->window, wsize);
1431  }
1432  copy->window = window;
1433  dest->state = (struct internal_state FAR *)copy;
1434  return Z_OK;
1435 }
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:243
void copy(std::vector< T > &main, const std::vector< T > &data)
Definition: DicomRun.hh:91
#define ZFREE(strm, addr)
Definition: zutil.h:245
#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
int ZEXPORT inflateEnd ( z_streamp  strm)

Definition at line 1234 of file inflate.cc.

References Tracev, inflate_state::window, Z_NULL, Z_OK, Z_STREAM_ERROR, and ZFREE.

Referenced by gzclose_r(), and uncompress().

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:231
#define Z_STREAM_ERROR
Definition: zlib.h:177
#define ZFREE(strm, addr)
Definition: zutil.h:245
unsigned char FAR * window
Definition: inflate.h:96
#define Z_OK
Definition: zlib.h:173
#define Z_NULL
Definition: zlib.h:208
int ZEXPORT inflateGetHeader ( z_streamp  strm,
gz_headerp  head 
)

Definition at line 1287 of file inflate.cc.

References inflate_state::head, inflate_state::wrap, Z_NULL, Z_OK, and Z_STREAM_ERROR.

1288 {
1289  struct inflate_state FAR *state;
1290 
1291  /* check state */
1292  if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1293  state = (struct inflate_state FAR *)strm->state;
1294  if ((state->wrap & 2) == 0) return Z_STREAM_ERROR;
1295 
1296  /* save header structure */
1297  state->head = head;
1298  head->done = 0;
1299  return Z_OK;
1300 }
gz_headerp head
Definition: inflate.h:90
#define Z_STREAM_ERROR
Definition: zlib.h:177
#define Z_OK
Definition: zlib.h:173
#define Z_NULL
Definition: zlib.h:208
int ZEXPORT inflateInit2_ ( z_streamp  strm,
int  windowBits,
const char *  version,
int  stream_size 
)

Definition at line 175 of file inflate.cc.

References inflateReset2(), Tracev, inflate_state::window, Z_MEM_ERROR, Z_NULL, Z_OK, Z_STREAM_ERROR, Z_VERSION_ERROR, ZALLOC, zcalloc(), zcfree(), ZFREE, and ZLIB_VERSION.

Referenced by inflateInit_().

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

Definition at line 213 of file inflate.cc.

References DEF_WBITS, and inflateInit2_().

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

Definition at line 1452 of file inflate.cc.

References inflate_state::back, COPY, inflate_state::length, MATCH, inflate_state::mode, inflate_state::was, and Z_NULL.

1453 {
1454  struct inflate_state FAR *state;
1455 
1456  if (strm == Z_NULL || strm->state == Z_NULL) return -1L << 16;
1457  state = (struct inflate_state FAR *)strm->state;
1458  return ((long)(state->back) << 16) +
1459  (state->mode == COPY ? state->length :
1460  (state->mode == MATCH ? state->was - state->length : 0));
1461 }
Definition: inflate.h:36
Definition: inflate.h:45
inflate_mode mode
Definition: inflate.h:82
#define Z_NULL
Definition: zlib.h:208
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 218 of file inflate.cc.

References inflate_state::bits, inflate_state::hold, Z_NULL, Z_OK, and Z_STREAM_ERROR.

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

Definition at line 127 of file inflate.cc.

References inflateResetKeep(), inflate_state::whave, inflate_state::wnext, inflate_state::wsize, Z_NULL, and Z_STREAM_ERROR.

Referenced by gz_look(), inflateReset2(), and inflateSync().

128 {
129  struct inflate_state FAR *state;
130 
131  if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
132  state = (struct inflate_state FAR *)strm->state;
133  state->wsize = 0;
134  state->whave = 0;
135  state->wnext = 0;
136  return inflateResetKeep(strm);
137 }
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:103
#define Z_NULL
Definition: zlib.h:208
unsigned whave
Definition: inflate.h:94
int ZEXPORT inflateReset2 ( z_streamp  strm,
int  windowBits 
)

Definition at line 139 of file inflate.cc.

References inflateReset(), inflate_state::wbits, inflate_state::window, inflate_state::wrap, G4INCL::String::wrap(), Z_NULL, Z_STREAM_ERROR, and ZFREE.

Referenced by inflateInit2_().

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

Definition at line 103 of file inflate.cc.

References inflate_state::back, inflate_state::bits, inflate_state::codes, inflate_state::distcode, inflate_state::dmax, inflate_state::havedict, HEAD, inflate_state::head, inflate_state::hold, inflate_state::last, inflate_state::lencode, inflate_state::mode, inflate_state::next, inflate_state::sane, inflate_state::total, Tracev, inflate_state::wrap, Z_NULL, Z_OK, and Z_STREAM_ERROR.

Referenced by inflateReset().

104 {
105  struct inflate_state FAR *state;
106 
107  if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
108  state = (struct inflate_state FAR *)strm->state;
109  strm->total_in = strm->total_out = state->total = 0;
110  strm->msg = Z_NULL;
111  if (state->wrap) /* to support ill-conceived Java test suite */
112  strm->adler = state->wrap & 1;
113  state->mode = HEAD;
114  state->last = 0;
115  state->havedict = 0;
116  state->dmax = 32768U;
117  state->head = Z_NULL;
118  state->hold = 0;
119  state->bits = 0;
120  state->lencode = state->distcode = state->next = state->codes;
121  state->sane = 1;
122  state->back = -1;
123  Tracev((stderr, "inflate: reset\n"));
124  return Z_OK;
125 }
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:231
#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
int ZEXPORT inflateSetDictionary ( z_streamp  strm,
const Bytef *  dictionary,
uInt  dictLength 
)

Definition at line 1247 of file inflate.cc.

References adler32(), inflate_state::check, DICT, inflate_state::havedict, MEM, inflate_state::mode, inflate_state::next, Tracev, updatewindow(), inflate_state::wrap, Z_DATA_ERROR, Z_MEM_ERROR, Z_NULL, Z_OK, and Z_STREAM_ERROR.

1248 {
1249  struct inflate_state FAR *state;
1250  unsigned long dictid;
1251  unsigned char *next;
1252  unsigned avail;
1253  int ret;
1254 
1255  /* check state */
1256  if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1257  state = (struct inflate_state FAR *)strm->state;
1258  if (state->wrap != 0 && state->mode != DICT)
1259  return Z_STREAM_ERROR;
1260 
1261  /* check for correct dictionary identifier */
1262  if (state->mode == DICT) {
1263  dictid = adler32(0L, Z_NULL, 0);
1264  dictid = adler32(dictid, dictionary, dictLength);
1265  if (dictid != state->check)
1266  return Z_DATA_ERROR;
1267  }
1268 
1269  /* copy dictionary to window using updatewindow(), which will amend the
1270  existing dictionary if appropriate */
1271  next = strm->next_out;
1272  avail = strm->avail_out;
1273  strm->next_out = (Bytef *)dictionary + dictLength;
1274  strm->avail_out = 0;
1275  ret = updatewindow(strm, dictLength);
1276  strm->avail_out = avail;
1277  strm->next_out = next;
1278  if (ret) {
1279  state->mode = MEM;
1280  return Z_MEM_ERROR;
1281  }
1282  state->havedict = 1;
1283  Tracev((stderr, "inflate: dictionary set\n"));
1284  return Z_OK;
1285 }
int havedict
Definition: inflate.h:85
#define Tracev(x)
Definition: zutil.h:231
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
code FAR * next
Definition: inflate.h:115
#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
local int updatewindow(z_streamp strm, unsigned out)
Definition: inflate.cc:363
Definition: inflate.h:51
int ZEXPORT inflateSync ( z_streamp  strm)

Definition at line 1333 of file inflate.cc.

References inflate_state::bits, inflate_state::have, inflate_state::hold, inflateReset(), inflate_state::mode, SYNC, syncsearch(), TYPE, Z_BUF_ERROR, Z_DATA_ERROR, Z_NULL, Z_OK, and Z_STREAM_ERROR.

1334 {
1335  unsigned len; /* number of bytes to look at or looked at */
1336  unsigned long in, out; /* temporary to save total_in and total_out */
1337  unsigned char buf[4]; /* to restore bit buffer to byte string */
1338  struct inflate_state FAR *state;
1339 
1340  /* check parameters */
1341  if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1342  state = (struct inflate_state FAR *)strm->state;
1343  if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;
1344 
1345  /* if first time, start search in bit buffer */
1346  if (state->mode != SYNC) {
1347  state->mode = SYNC;
1348  state->hold <<= state->bits & 7;
1349  state->bits -= state->bits & 7;
1350  len = 0;
1351  while (state->bits >= 8) {
1352  buf[len++] = (unsigned char)(state->hold);
1353  state->hold >>= 8;
1354  state->bits -= 8;
1355  }
1356  state->have = 0;
1357  syncsearch(&(state->have), buf, len);
1358  }
1359 
1360  /* search available input */
1361  len = syncsearch(&(state->have), strm->next_in, strm->avail_in);
1362  strm->avail_in -= len;
1363  strm->next_in += len;
1364  strm->total_in += len;
1365 
1366  /* return no joy or set up to restart inflate() on a new block */
1367  if (state->have != 4) return Z_DATA_ERROR;
1368  in = strm->total_in; out = strm->total_out;
1369  inflateReset(strm);
1370  strm->total_in = in; strm->total_out = out;
1371  state->mode = TYPE;
1372  return Z_OK;
1373 }
unsigned have
Definition: inflate.h:114
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
local unsigned syncsearch(unsigned FAR *have, unsigned char FAR *buf, unsigned len)
Definition: inflate.cc:1313
unsigned bits
Definition: inflate.h:99
#define Z_BUF_ERROR
Definition: zlib.h:180
inflate_mode mode
Definition: inflate.h:82
const XML_Char int len
#define Z_OK
Definition: zlib.h:173
#define Z_NULL
Definition: zlib.h:208
int ZEXPORT inflateReset(z_streamp strm)
Definition: inflate.cc:127
int ZEXPORT inflateSyncPoint ( z_streamp  strm)

Definition at line 1383 of file inflate.cc.

References inflate_state::bits, inflate_state::mode, STORED, Z_NULL, and Z_STREAM_ERROR.

1384 {
1385  struct inflate_state FAR *state;
1386 
1387  if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1388  state = (struct inflate_state FAR *)strm->state;
1389  return state->mode == STORED && state->bits == 0;
1390 }
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 1437 of file inflate.cc.

References inflate_state::sane, Z_DATA_ERROR, Z_NULL, Z_OK, and Z_STREAM_ERROR.

1438 {
1439  struct inflate_state FAR *state;
1440 
1441  if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1442  state = (struct inflate_state FAR *)strm->state;
1443  state->sane = !subvert;
1444 #ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
1445  return Z_OK;
1446 #else
1447  state->sane = 1;
1448  return Z_DATA_ERROR;
1449 #endif
1450 }
#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, 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 1313 of file inflate.cc.

References inflate_state::have, and inflate_state::next.

Referenced by inflateSync().

1314 {
1315  unsigned got;
1316  unsigned next;
1317 
1318  got = *have;
1319  next = 0;
1320  while (next < len && got < 4) {
1321  if ((int)(buf[next]) == (got < 2 ? 0 : 0xff))
1322  got++;
1323  else if (buf[next])
1324  got = 0;
1325  else
1326  got = 4 - got;
1327  next++;
1328  }
1329  *have = got;
1330  return next;
1331 }
unsigned have
Definition: inflate.h:114
code FAR * next
Definition: inflate.h:115
const XML_Char int len
local int updatewindow ( z_streamp  strm,
unsigned  out 
)

Definition at line 363 of file inflate.cc.

References copy(), inflate_state::wbits, inflate_state::whave, inflate_state::window, inflate_state::wnext, inflate_state::wsize, Z_NULL, ZALLOC, and zmemcpy().

Referenced by inflate(), and inflateSetDictionary().

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