wearefair-grpc 1.3.1.pre.a → 1.3.1.pre.c

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  /* infback.c -- inflate using a call-back interface
2
- * Copyright (C) 1995-2011 Mark Adler
2
+ * Copyright (C) 1995-2016 Mark Adler
3
3
  * For conditions of distribution and use, see copyright notice in zlib.h
4
4
  */
5
5
 
@@ -61,7 +61,7 @@ int stream_size;
61
61
  Tracev((stderr, "inflate: allocated\n"));
62
62
  strm->state = (struct internal_state FAR *)state;
63
63
  state->dmax = 32768U;
64
- state->wbits = windowBits;
64
+ state->wbits = (uInt)windowBits;
65
65
  state->wsize = 1U << windowBits;
66
66
  state->window = window;
67
67
  state->wnext = 0;
@@ -1,5 +1,5 @@
1
1
  /* inffast.c -- fast decoding
2
- * Copyright (C) 1995-2008, 2010, 2013 Mark Adler
2
+ * Copyright (C) 1995-2017 Mark Adler
3
3
  * For conditions of distribution and use, see copyright notice in zlib.h
4
4
  */
5
5
 
@@ -8,26 +8,9 @@
8
8
  #include "inflate.h"
9
9
  #include "inffast.h"
10
10
 
11
- #ifndef ASMINF
12
-
13
- /* Allow machine dependent optimization for post-increment or pre-increment.
14
- Based on testing to date,
15
- Pre-increment preferred for:
16
- - PowerPC G3 (Adler)
17
- - MIPS R5000 (Randers-Pehrson)
18
- Post-increment preferred for:
19
- - none
20
- No measurable difference:
21
- - Pentium III (Anderson)
22
- - M68060 (Nikl)
23
- */
24
- #ifdef POSTINC
25
- # define OFF 0
26
- # define PUP(a) *(a)++
11
+ #ifdef ASMINF
12
+ # pragma message("Assembler code may have bugs -- use at your own risk")
27
13
  #else
28
- # define OFF 1
29
- # define PUP(a) *++(a)
30
- #endif
31
14
 
32
15
  /*
33
16
  Decode literal, length, and distance codes and write out the resulting
@@ -96,9 +79,9 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
96
79
 
97
80
  /* copy state to local variables */
98
81
  state = (struct inflate_state FAR *)strm->state;
99
- in = strm->next_in - OFF;
82
+ in = strm->next_in;
100
83
  last = in + (strm->avail_in - 5);
101
- out = strm->next_out - OFF;
84
+ out = strm->next_out;
102
85
  beg = out - (start - strm->avail_out);
103
86
  end = out + (strm->avail_out - 257);
104
87
  #ifdef INFLATE_STRICT
@@ -119,9 +102,9 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
119
102
  input data or output space */
120
103
  do {
121
104
  if (bits < 15) {
122
- hold += (unsigned long)(PUP(in)) << bits;
105
+ hold += (unsigned long)(*in++) << bits;
123
106
  bits += 8;
124
- hold += (unsigned long)(PUP(in)) << bits;
107
+ hold += (unsigned long)(*in++) << bits;
125
108
  bits += 8;
126
109
  }
127
110
  here = lcode[hold & lmask];
@@ -134,14 +117,14 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
134
117
  Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
135
118
  "inflate: literal '%c'\n" :
136
119
  "inflate: literal 0x%02x\n", here.val));
137
- PUP(out) = (unsigned char)(here.val);
120
+ *out++ = (unsigned char)(here.val);
138
121
  }
139
122
  else if (op & 16) { /* length base */
140
123
  len = (unsigned)(here.val);
141
124
  op &= 15; /* number of extra bits */
142
125
  if (op) {
143
126
  if (bits < op) {
144
- hold += (unsigned long)(PUP(in)) << bits;
127
+ hold += (unsigned long)(*in++) << bits;
145
128
  bits += 8;
146
129
  }
147
130
  len += (unsigned)hold & ((1U << op) - 1);
@@ -150,9 +133,9 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
150
133
  }
151
134
  Tracevv((stderr, "inflate: length %u\n", len));
152
135
  if (bits < 15) {
153
- hold += (unsigned long)(PUP(in)) << bits;
136
+ hold += (unsigned long)(*in++) << bits;
154
137
  bits += 8;
155
- hold += (unsigned long)(PUP(in)) << bits;
138
+ hold += (unsigned long)(*in++) << bits;
156
139
  bits += 8;
157
140
  }
158
141
  here = dcode[hold & dmask];
@@ -165,10 +148,10 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
165
148
  dist = (unsigned)(here.val);
166
149
  op &= 15; /* number of extra bits */
167
150
  if (bits < op) {
168
- hold += (unsigned long)(PUP(in)) << bits;
151
+ hold += (unsigned long)(*in++) << bits;
169
152
  bits += 8;
170
153
  if (bits < op) {
171
- hold += (unsigned long)(PUP(in)) << bits;
154
+ hold += (unsigned long)(*in++) << bits;
172
155
  bits += 8;
173
156
  }
174
157
  }
@@ -196,30 +179,30 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
196
179
  #ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
197
180
  if (len <= op - whave) {
198
181
  do {
199
- PUP(out) = 0;
182
+ *out++ = 0;
200
183
  } while (--len);
201
184
  continue;
202
185
  }
203
186
  len -= op - whave;
204
187
  do {
205
- PUP(out) = 0;
188
+ *out++ = 0;
206
189
  } while (--op > whave);
207
190
  if (op == 0) {
208
191
  from = out - dist;
209
192
  do {
210
- PUP(out) = PUP(from);
193
+ *out++ = *from++;
211
194
  } while (--len);
212
195
  continue;
213
196
  }
214
197
  #endif
215
198
  }
216
- from = window - OFF;
199
+ from = window;
217
200
  if (wnext == 0) { /* very common case */
218
201
  from += wsize - op;
219
202
  if (op < len) { /* some from window */
220
203
  len -= op;
221
204
  do {
222
- PUP(out) = PUP(from);
205
+ *out++ = *from++;
223
206
  } while (--op);
224
207
  from = out - dist; /* rest from output */
225
208
  }
@@ -230,14 +213,14 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
230
213
  if (op < len) { /* some from end of window */
231
214
  len -= op;
232
215
  do {
233
- PUP(out) = PUP(from);
216
+ *out++ = *from++;
234
217
  } while (--op);
235
- from = window - OFF;
218
+ from = window;
236
219
  if (wnext < len) { /* some from start of window */
237
220
  op = wnext;
238
221
  len -= op;
239
222
  do {
240
- PUP(out) = PUP(from);
223
+ *out++ = *from++;
241
224
  } while (--op);
242
225
  from = out - dist; /* rest from output */
243
226
  }
@@ -248,35 +231,35 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
248
231
  if (op < len) { /* some from window */
249
232
  len -= op;
250
233
  do {
251
- PUP(out) = PUP(from);
234
+ *out++ = *from++;
252
235
  } while (--op);
253
236
  from = out - dist; /* rest from output */
254
237
  }
255
238
  }
256
239
  while (len > 2) {
257
- PUP(out) = PUP(from);
258
- PUP(out) = PUP(from);
259
- PUP(out) = PUP(from);
240
+ *out++ = *from++;
241
+ *out++ = *from++;
242
+ *out++ = *from++;
260
243
  len -= 3;
261
244
  }
262
245
  if (len) {
263
- PUP(out) = PUP(from);
246
+ *out++ = *from++;
264
247
  if (len > 1)
265
- PUP(out) = PUP(from);
248
+ *out++ = *from++;
266
249
  }
267
250
  }
268
251
  else {
269
252
  from = out - dist; /* copy direct from output */
270
253
  do { /* minimum length is three */
271
- PUP(out) = PUP(from);
272
- PUP(out) = PUP(from);
273
- PUP(out) = PUP(from);
254
+ *out++ = *from++;
255
+ *out++ = *from++;
256
+ *out++ = *from++;
274
257
  len -= 3;
275
258
  } while (len > 2);
276
259
  if (len) {
277
- PUP(out) = PUP(from);
260
+ *out++ = *from++;
278
261
  if (len > 1)
279
- PUP(out) = PUP(from);
262
+ *out++ = *from++;
280
263
  }
281
264
  }
282
265
  }
@@ -313,8 +296,8 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
313
296
  hold &= (1U << bits) - 1;
314
297
 
315
298
  /* update state and return */
316
- strm->next_in = in + OFF;
317
- strm->next_out = out + OFF;
299
+ strm->next_in = in;
300
+ strm->next_out = out;
318
301
  strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
319
302
  strm->avail_out = (unsigned)(out < end ?
320
303
  257 + (end - out) : 257 - (out - end));
@@ -1,5 +1,5 @@
1
1
  /* inflate.c -- zlib decompression
2
- * Copyright (C) 1995-2012 Mark Adler
2
+ * Copyright (C) 1995-2016 Mark Adler
3
3
  * For conditions of distribution and use, see copyright notice in zlib.h
4
4
  */
5
5
 
@@ -92,6 +92,7 @@
92
92
  #endif
93
93
 
94
94
  /* function prototypes */
95
+ local int inflateStateCheck OF((z_streamp strm));
95
96
  local void fixedtables OF((struct inflate_state FAR *state));
96
97
  local int updatewindow OF((z_streamp strm, const unsigned char FAR *end,
97
98
  unsigned copy));
@@ -101,12 +102,26 @@ local int updatewindow OF((z_streamp strm, const unsigned char FAR *end,
101
102
  local unsigned syncsearch OF((unsigned FAR *have, const unsigned char FAR *buf,
102
103
  unsigned len));
103
104
 
105
+ local int inflateStateCheck(strm)
106
+ z_streamp strm;
107
+ {
108
+ struct inflate_state FAR *state;
109
+ if (strm == Z_NULL ||
110
+ strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0)
111
+ return 1;
112
+ state = (struct inflate_state FAR *)strm->state;
113
+ if (state == Z_NULL || state->strm != strm ||
114
+ state->mode < HEAD || state->mode > SYNC)
115
+ return 1;
116
+ return 0;
117
+ }
118
+
104
119
  int ZEXPORT inflateResetKeep(strm)
105
120
  z_streamp strm;
106
121
  {
107
122
  struct inflate_state FAR *state;
108
123
 
109
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
124
+ if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
110
125
  state = (struct inflate_state FAR *)strm->state;
111
126
  strm->total_in = strm->total_out = state->total = 0;
112
127
  strm->msg = Z_NULL;
@@ -131,7 +146,7 @@ z_streamp strm;
131
146
  {
132
147
  struct inflate_state FAR *state;
133
148
 
134
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
149
+ if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
135
150
  state = (struct inflate_state FAR *)strm->state;
136
151
  state->wsize = 0;
137
152
  state->whave = 0;
@@ -147,7 +162,7 @@ int windowBits;
147
162
  struct inflate_state FAR *state;
148
163
 
149
164
  /* get the state */
150
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
165
+ if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
151
166
  state = (struct inflate_state FAR *)strm->state;
152
167
 
153
168
  /* extract wrap request from windowBits parameter */
@@ -156,7 +171,7 @@ int windowBits;
156
171
  windowBits = -windowBits;
157
172
  }
158
173
  else {
159
- wrap = (windowBits >> 4) + 1;
174
+ wrap = (windowBits >> 4) + 5;
160
175
  #ifdef GUNZIP
161
176
  if (windowBits < 48)
162
177
  windowBits &= 15;
@@ -210,7 +225,9 @@ int stream_size;
210
225
  if (state == Z_NULL) return Z_MEM_ERROR;
211
226
  Tracev((stderr, "inflate: allocated\n"));
212
227
  strm->state = (struct internal_state FAR *)state;
228
+ state->strm = strm;
213
229
  state->window = Z_NULL;
230
+ state->mode = HEAD; /* to pass state test in inflateReset2() */
214
231
  ret = inflateReset2(strm, windowBits);
215
232
  if (ret != Z_OK) {
216
233
  ZFREE(strm, state);
@@ -234,17 +251,17 @@ int value;
234
251
  {
235
252
  struct inflate_state FAR *state;
236
253
 
237
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
254
+ if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
238
255
  state = (struct inflate_state FAR *)strm->state;
239
256
  if (bits < 0) {
240
257
  state->hold = 0;
241
258
  state->bits = 0;
242
259
  return Z_OK;
243
260
  }
244
- if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR;
261
+ if (bits > 16 || state->bits + (uInt)bits > 32) return Z_STREAM_ERROR;
245
262
  value &= (1L << bits) - 1;
246
- state->hold += value << state->bits;
247
- state->bits += bits;
263
+ state->hold += (unsigned)value << state->bits;
264
+ state->bits += (uInt)bits;
248
265
  return Z_OK;
249
266
  }
250
267
 
@@ -625,7 +642,7 @@ int flush;
625
642
  static const unsigned short order[19] = /* permutation of code lengths */
626
643
  {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
627
644
 
628
- if (strm == Z_NULL || strm->state == Z_NULL || strm->next_out == Z_NULL ||
645
+ if (inflateStateCheck(strm) || strm->next_out == Z_NULL ||
629
646
  (strm->next_in == Z_NULL && strm->avail_in != 0))
630
647
  return Z_STREAM_ERROR;
631
648
 
@@ -645,6 +662,8 @@ int flush;
645
662
  NEEDBITS(16);
646
663
  #ifdef GUNZIP
647
664
  if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */
665
+ if (state->wbits == 0)
666
+ state->wbits = 15;
648
667
  state->check = crc32(0L, Z_NULL, 0);
649
668
  CRC2(state->check, hold);
650
669
  INITBITS();
@@ -672,7 +691,7 @@ int flush;
672
691
  len = BITS(4) + 8;
673
692
  if (state->wbits == 0)
674
693
  state->wbits = len;
675
- else if (len > state->wbits) {
694
+ if (len > 15 || len > state->wbits) {
676
695
  strm->msg = (char *)"invalid window size";
677
696
  state->mode = BAD;
678
697
  break;
@@ -699,14 +718,16 @@ int flush;
699
718
  }
700
719
  if (state->head != Z_NULL)
701
720
  state->head->text = (int)((hold >> 8) & 1);
702
- if (state->flags & 0x0200) CRC2(state->check, hold);
721
+ if ((state->flags & 0x0200) && (state->wrap & 4))
722
+ CRC2(state->check, hold);
703
723
  INITBITS();
704
724
  state->mode = TIME;
705
725
  case TIME:
706
726
  NEEDBITS(32);
707
727
  if (state->head != Z_NULL)
708
728
  state->head->time = hold;
709
- if (state->flags & 0x0200) CRC4(state->check, hold);
729
+ if ((state->flags & 0x0200) && (state->wrap & 4))
730
+ CRC4(state->check, hold);
710
731
  INITBITS();
711
732
  state->mode = OS;
712
733
  case OS:
@@ -715,7 +736,8 @@ int flush;
715
736
  state->head->xflags = (int)(hold & 0xff);
716
737
  state->head->os = (int)(hold >> 8);
717
738
  }
718
- if (state->flags & 0x0200) CRC2(state->check, hold);
739
+ if ((state->flags & 0x0200) && (state->wrap & 4))
740
+ CRC2(state->check, hold);
719
741
  INITBITS();
720
742
  state->mode = EXLEN;
721
743
  case EXLEN:
@@ -724,7 +746,8 @@ int flush;
724
746
  state->length = (unsigned)(hold);
725
747
  if (state->head != Z_NULL)
726
748
  state->head->extra_len = (unsigned)hold;
727
- if (state->flags & 0x0200) CRC2(state->check, hold);
749
+ if ((state->flags & 0x0200) && (state->wrap & 4))
750
+ CRC2(state->check, hold);
728
751
  INITBITS();
729
752
  }
730
753
  else if (state->head != Z_NULL)
@@ -742,7 +765,7 @@ int flush;
742
765
  len + copy > state->head->extra_max ?
743
766
  state->head->extra_max - len : copy);
744
767
  }
745
- if (state->flags & 0x0200)
768
+ if ((state->flags & 0x0200) && (state->wrap & 4))
746
769
  state->check = crc32(state->check, next, copy);
747
770
  have -= copy;
748
771
  next += copy;
@@ -761,9 +784,9 @@ int flush;
761
784
  if (state->head != Z_NULL &&
762
785
  state->head->name != Z_NULL &&
763
786
  state->length < state->head->name_max)
764
- state->head->name[state->length++] = len;
787
+ state->head->name[state->length++] = (Bytef)len;
765
788
  } while (len && copy < have);
766
- if (state->flags & 0x0200)
789
+ if ((state->flags & 0x0200) && (state->wrap & 4))
767
790
  state->check = crc32(state->check, next, copy);
768
791
  have -= copy;
769
792
  next += copy;
@@ -782,9 +805,9 @@ int flush;
782
805
  if (state->head != Z_NULL &&
783
806
  state->head->comment != Z_NULL &&
784
807
  state->length < state->head->comm_max)
785
- state->head->comment[state->length++] = len;
808
+ state->head->comment[state->length++] = (Bytef)len;
786
809
  } while (len && copy < have);
787
- if (state->flags & 0x0200)
810
+ if ((state->flags & 0x0200) && (state->wrap & 4))
788
811
  state->check = crc32(state->check, next, copy);
789
812
  have -= copy;
790
813
  next += copy;
@@ -796,7 +819,7 @@ int flush;
796
819
  case HCRC:
797
820
  if (state->flags & 0x0200) {
798
821
  NEEDBITS(16);
799
- if (hold != (state->check & 0xffff)) {
822
+ if ((state->wrap & 4) && hold != (state->check & 0xffff)) {
800
823
  strm->msg = (char *)"header crc mismatch";
801
824
  state->mode = BAD;
802
825
  break;
@@ -1177,11 +1200,11 @@ int flush;
1177
1200
  out -= left;
1178
1201
  strm->total_out += out;
1179
1202
  state->total += out;
1180
- if (out)
1203
+ if ((state->wrap & 4) && out)
1181
1204
  strm->adler = state->check =
1182
1205
  UPDATE(state->check, put - out, out);
1183
1206
  out = left;
1184
- if ((
1207
+ if ((state->wrap & 4) && (
1185
1208
  #ifdef GUNZIP
1186
1209
  state->flags ? hold :
1187
1210
  #endif
@@ -1240,10 +1263,10 @@ int flush;
1240
1263
  strm->total_in += in;
1241
1264
  strm->total_out += out;
1242
1265
  state->total += out;
1243
- if (state->wrap && out)
1266
+ if ((state->wrap & 4) && out)
1244
1267
  strm->adler = state->check =
1245
1268
  UPDATE(state->check, strm->next_out - out, out);
1246
- strm->data_type = state->bits + (state->last ? 64 : 0) +
1269
+ strm->data_type = (int)state->bits + (state->last ? 64 : 0) +
1247
1270
  (state->mode == TYPE ? 128 : 0) +
1248
1271
  (state->mode == LEN_ || state->mode == COPY_ ? 256 : 0);
1249
1272
  if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK)
@@ -1255,7 +1278,7 @@ int ZEXPORT inflateEnd(strm)
1255
1278
  z_streamp strm;
1256
1279
  {
1257
1280
  struct inflate_state FAR *state;
1258
- if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
1281
+ if (inflateStateCheck(strm))
1259
1282
  return Z_STREAM_ERROR;
1260
1283
  state = (struct inflate_state FAR *)strm->state;
1261
1284
  if (state->window != Z_NULL) ZFREE(strm, state->window);
@@ -1273,7 +1296,7 @@ uInt *dictLength;
1273
1296
  struct inflate_state FAR *state;
1274
1297
 
1275
1298
  /* check state */
1276
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1299
+ if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
1277
1300
  state = (struct inflate_state FAR *)strm->state;
1278
1301
 
1279
1302
  /* copy dictionary */
@@ -1298,7 +1321,7 @@ uInt dictLength;
1298
1321
  int ret;
1299
1322
 
1300
1323
  /* check state */
1301
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1324
+ if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
1302
1325
  state = (struct inflate_state FAR *)strm->state;
1303
1326
  if (state->wrap != 0 && state->mode != DICT)
1304
1327
  return Z_STREAM_ERROR;
@@ -1330,7 +1353,7 @@ gz_headerp head;
1330
1353
  struct inflate_state FAR *state;
1331
1354
 
1332
1355
  /* check state */
1333
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1356
+ if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
1334
1357
  state = (struct inflate_state FAR *)strm->state;
1335
1358
  if ((state->wrap & 2) == 0) return Z_STREAM_ERROR;
1336
1359
 
@@ -1383,7 +1406,7 @@ z_streamp strm;
1383
1406
  struct inflate_state FAR *state;
1384
1407
 
1385
1408
  /* check parameters */
1386
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1409
+ if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
1387
1410
  state = (struct inflate_state FAR *)strm->state;
1388
1411
  if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;
1389
1412
 
@@ -1430,7 +1453,7 @@ z_streamp strm;
1430
1453
  {
1431
1454
  struct inflate_state FAR *state;
1432
1455
 
1433
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1456
+ if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
1434
1457
  state = (struct inflate_state FAR *)strm->state;
1435
1458
  return state->mode == STORED && state->bits == 0;
1436
1459
  }
@@ -1445,8 +1468,7 @@ z_streamp source;
1445
1468
  unsigned wsize;
1446
1469
 
1447
1470
  /* check input */
1448
- if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL ||
1449
- source->zalloc == (alloc_func)0 || source->zfree == (free_func)0)
1471
+ if (inflateStateCheck(source) || dest == Z_NULL)
1450
1472
  return Z_STREAM_ERROR;
1451
1473
  state = (struct inflate_state FAR *)source->state;
1452
1474
 
@@ -1467,6 +1489,7 @@ z_streamp source;
1467
1489
  /* copy state */
1468
1490
  zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream));
1469
1491
  zmemcpy((voidpf)copy, (voidpf)state, sizeof(struct inflate_state));
1492
+ copy->strm = dest;
1470
1493
  if (state->lencode >= state->codes &&
1471
1494
  state->lencode <= state->codes + ENOUGH - 1) {
1472
1495
  copy->lencode = copy->codes + (state->lencode - state->codes);
@@ -1488,25 +1511,51 @@ int subvert;
1488
1511
  {
1489
1512
  struct inflate_state FAR *state;
1490
1513
 
1491
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1514
+ if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
1492
1515
  state = (struct inflate_state FAR *)strm->state;
1493
- state->sane = !subvert;
1494
1516
  #ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
1517
+ state->sane = !subvert;
1495
1518
  return Z_OK;
1496
1519
  #else
1520
+ (void)subvert;
1497
1521
  state->sane = 1;
1498
1522
  return Z_DATA_ERROR;
1499
1523
  #endif
1500
1524
  }
1501
1525
 
1526
+ int ZEXPORT inflateValidate(strm, check)
1527
+ z_streamp strm;
1528
+ int check;
1529
+ {
1530
+ struct inflate_state FAR *state;
1531
+
1532
+ if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
1533
+ state = (struct inflate_state FAR *)strm->state;
1534
+ if (check)
1535
+ state->wrap |= 4;
1536
+ else
1537
+ state->wrap &= ~4;
1538
+ return Z_OK;
1539
+ }
1540
+
1502
1541
  long ZEXPORT inflateMark(strm)
1503
1542
  z_streamp strm;
1504
1543
  {
1505
1544
  struct inflate_state FAR *state;
1506
1545
 
1507
- if (strm == Z_NULL || strm->state == Z_NULL) return -1L << 16;
1546
+ if (inflateStateCheck(strm))
1547
+ return -(1L << 16);
1508
1548
  state = (struct inflate_state FAR *)strm->state;
1509
- return ((long)(state->back) << 16) +
1549
+ return (long)(((unsigned long)((long)state->back)) << 16) +
1510
1550
  (state->mode == COPY ? state->length :
1511
1551
  (state->mode == MATCH ? state->was - state->length : 0));
1512
1552
  }
1553
+
1554
+ unsigned long ZEXPORT inflateCodesUsed(strm)
1555
+ z_streamp strm;
1556
+ {
1557
+ struct inflate_state FAR *state;
1558
+ if (inflateStateCheck(strm)) return (unsigned long)-1;
1559
+ state = (struct inflate_state FAR *)strm->state;
1560
+ return (unsigned long)(state->next - state->codes);
1561
+ }