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
  /* deflate.h -- internal compression state
2
- * Copyright (C) 1995-2012 Jean-loup Gailly
2
+ * Copyright (C) 1995-2016 Jean-loup Gailly
3
3
  * For conditions of distribution and use, see copyright notice in zlib.h
4
4
  */
5
5
 
@@ -51,13 +51,16 @@
51
51
  #define Buf_size 16
52
52
  /* size of bit buffer in bi_buf */
53
53
 
54
- #define INIT_STATE 42
55
- #define EXTRA_STATE 69
56
- #define NAME_STATE 73
57
- #define COMMENT_STATE 91
58
- #define HCRC_STATE 103
59
- #define BUSY_STATE 113
60
- #define FINISH_STATE 666
54
+ #define INIT_STATE 42 /* zlib header -> BUSY_STATE */
55
+ #ifdef GZIP
56
+ # define GZIP_STATE 57 /* gzip header -> BUSY_STATE | EXTRA_STATE */
57
+ #endif
58
+ #define EXTRA_STATE 69 /* gzip extra block -> NAME_STATE */
59
+ #define NAME_STATE 73 /* gzip file name -> COMMENT_STATE */
60
+ #define COMMENT_STATE 91 /* gzip comment -> HCRC_STATE */
61
+ #define HCRC_STATE 103 /* gzip header CRC -> BUSY_STATE */
62
+ #define BUSY_STATE 113 /* deflate -> FINISH_STATE */
63
+ #define FINISH_STATE 666 /* stream complete */
61
64
  /* Stream status */
62
65
 
63
66
 
@@ -83,7 +86,7 @@ typedef struct static_tree_desc_s static_tree_desc;
83
86
  typedef struct tree_desc_s {
84
87
  ct_data *dyn_tree; /* the dynamic tree */
85
88
  int max_code; /* largest code with non zero frequency */
86
- static_tree_desc *stat_desc; /* the corresponding static tree */
89
+ const static_tree_desc *stat_desc; /* the corresponding static tree */
87
90
  } FAR tree_desc;
88
91
 
89
92
  typedef ush Pos;
@@ -100,10 +103,10 @@ typedef struct internal_state {
100
103
  Bytef *pending_buf; /* output still pending */
101
104
  ulg pending_buf_size; /* size of pending_buf */
102
105
  Bytef *pending_out; /* next pending byte to output to the stream */
103
- uInt pending; /* nb of bytes in the pending buffer */
106
+ ulg pending; /* nb of bytes in the pending buffer */
104
107
  int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
105
108
  gz_headerp gzhead; /* gzip header information to write */
106
- uInt gzindex; /* where in extra, name, or comment */
109
+ ulg gzindex; /* where in extra, name, or comment */
107
110
  Byte method; /* can only be DEFLATED */
108
111
  int last_flush; /* value of flush param for previous deflate call */
109
112
 
@@ -249,7 +252,7 @@ typedef struct internal_state {
249
252
  uInt matches; /* number of string matches in current block */
250
253
  uInt insert; /* bytes at end of window left to insert */
251
254
 
252
- #ifdef DEBUG
255
+ #ifdef ZLIB_DEBUG
253
256
  ulg compressed_len; /* total bit length of compressed file mod 2^32 */
254
257
  ulg bits_sent; /* bit length of compressed data sent mod 2^32 */
255
258
  #endif
@@ -275,7 +278,7 @@ typedef struct internal_state {
275
278
  /* Output a byte on the stream.
276
279
  * IN assertion: there is enough room in pending_buf.
277
280
  */
278
- #define put_byte(s, c) {s->pending_buf[s->pending++] = (c);}
281
+ #define put_byte(s, c) {s->pending_buf[s->pending++] = (Bytef)(c);}
279
282
 
280
283
 
281
284
  #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
@@ -309,7 +312,7 @@ void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf,
309
312
  * used.
310
313
  */
311
314
 
312
- #ifndef DEBUG
315
+ #ifndef ZLIB_DEBUG
313
316
  /* Inline versions of _tr_tally for speed: */
314
317
 
315
318
  #if defined(GEN_TREES_H) || !defined(STDC)
@@ -328,8 +331,8 @@ void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf,
328
331
  flush = (s->last_lit == s->lit_bufsize-1); \
329
332
  }
330
333
  # define _tr_tally_dist(s, distance, length, flush) \
331
- { uch len = (length); \
332
- ush dist = (distance); \
334
+ { uch len = (uch)(length); \
335
+ ush dist = (ush)(distance); \
333
336
  s->d_buf[s->last_lit] = dist; \
334
337
  s->l_buf[s->last_lit++] = len; \
335
338
  dist--; \
@@ -1,5 +1,5 @@
1
1
  /* gzguts.h -- zlib internal header definitions for gz* operations
2
- * Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013 Mark Adler
2
+ * Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013, 2016 Mark Adler
3
3
  * For conditions of distribution and use, see copyright notice in zlib.h
4
4
  */
5
5
 
@@ -25,6 +25,10 @@
25
25
  # include <stdlib.h>
26
26
  # include <limits.h>
27
27
  #endif
28
+
29
+ #ifndef _POSIX_SOURCE
30
+ # define _POSIX_SOURCE
31
+ #endif
28
32
  #include <fcntl.h>
29
33
 
30
34
  #ifdef _WIN32
@@ -35,6 +39,10 @@
35
39
  # include <io.h>
36
40
  #endif
37
41
 
42
+ #if defined(_WIN32) || defined(__CYGWIN__)
43
+ # define WIDECHAR
44
+ #endif
45
+
38
46
  #ifdef WINAPI_FAMILY
39
47
  # define open _open
40
48
  # define read _read
@@ -95,18 +103,19 @@
95
103
  # endif
96
104
  #endif
97
105
 
98
- /* unlike snprintf (which is required in C99, yet still not supported by
99
- Microsoft more than a decade later!), _snprintf does not guarantee null
100
- termination of the result -- however this is only used in gzlib.c where
106
+ /* unlike snprintf (which is required in C99), _snprintf does not guarantee
107
+ null termination of the result -- however this is only used in gzlib.c where
101
108
  the result is assured to fit in the space provided */
102
- #ifdef _MSC_VER
109
+ #if defined(_MSC_VER) && _MSC_VER < 1900
103
110
  # define snprintf _snprintf
104
111
  #endif
105
112
 
106
113
  #ifndef local
107
114
  # define local static
108
115
  #endif
109
- /* compile with -Dlocal if your debugger can't find static symbols */
116
+ /* since "static" is used to mean two completely different things in C, we
117
+ define "local" for the non-static meaning of "static", for readability
118
+ (compile with -Dlocal if your debugger can't find static symbols) */
110
119
 
111
120
  /* gz* functions always use library allocation functions */
112
121
  #ifndef STDC
@@ -170,7 +179,7 @@ typedef struct {
170
179
  char *path; /* path or fd for error messages */
171
180
  unsigned size; /* buffer size, zero if not allocated yet */
172
181
  unsigned want; /* requested buffer size, default is GZBUFSIZE */
173
- unsigned char *in; /* input buffer */
182
+ unsigned char *in; /* input buffer (double-sized when writing) */
174
183
  unsigned char *out; /* output buffer (double-sized when reading) */
175
184
  int direct; /* 0 if processing gzip, 1 if transparent */
176
185
  /* just for reading */
@@ -1,11 +1,11 @@
1
1
  /* gzlib.c -- zlib functions common to reading and writing gzip files
2
- * Copyright (C) 2004, 2010, 2011, 2012, 2013 Mark Adler
2
+ * Copyright (C) 2004-2017 Mark Adler
3
3
  * For conditions of distribution and use, see copyright notice in zlib.h
4
4
  */
5
5
 
6
6
  #include "gzguts.h"
7
7
 
8
- #if defined(_WIN32) && !defined(__BORLANDC__)
8
+ #if defined(_WIN32) && !defined(__BORLANDC__) && !defined(__MINGW32__)
9
9
  # define LSEEK _lseeki64
10
10
  #else
11
11
  #if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
@@ -94,7 +94,7 @@ local gzFile gz_open(path, fd, mode)
94
94
  const char *mode;
95
95
  {
96
96
  gz_statep state;
97
- size_t len;
97
+ z_size_t len;
98
98
  int oflag;
99
99
  #ifdef O_CLOEXEC
100
100
  int cloexec = 0;
@@ -188,10 +188,10 @@ local gzFile gz_open(path, fd, mode)
188
188
  }
189
189
 
190
190
  /* save the path name for error messages */
191
- #ifdef _WIN32
191
+ #ifdef WIDECHAR
192
192
  if (fd == -2) {
193
193
  len = wcstombs(NULL, path, 0);
194
- if (len == (size_t)-1)
194
+ if (len == (z_size_t)-1)
195
195
  len = 0;
196
196
  }
197
197
  else
@@ -202,7 +202,7 @@ local gzFile gz_open(path, fd, mode)
202
202
  free(state);
203
203
  return NULL;
204
204
  }
205
- #ifdef _WIN32
205
+ #ifdef WIDECHAR
206
206
  if (fd == -2)
207
207
  if (len)
208
208
  wcstombs(state->path, path, len + 1);
@@ -211,7 +211,7 @@ local gzFile gz_open(path, fd, mode)
211
211
  else
212
212
  #endif
213
213
  #if !defined(NO_snprintf) && !defined(NO_vsnprintf)
214
- snprintf(state->path, len + 1, "%s", (const char *)path);
214
+ (void)snprintf(state->path, len + 1, "%s", (const char *)path);
215
215
  #else
216
216
  strcpy(state->path, path);
217
217
  #endif
@@ -239,7 +239,7 @@ local gzFile gz_open(path, fd, mode)
239
239
 
240
240
  /* open the file with the appropriate flags (or just use fd) */
241
241
  state->fd = fd > -1 ? fd : (
242
- #ifdef _WIN32
242
+ #ifdef WIDECHAR
243
243
  fd == -2 ? _wopen(path, oflag, 0666) :
244
244
  #endif
245
245
  open((const char *)path, oflag, 0666));
@@ -248,8 +248,10 @@ local gzFile gz_open(path, fd, mode)
248
248
  free(state);
249
249
  return NULL;
250
250
  }
251
- if (state->mode == GZ_APPEND)
251
+ if (state->mode == GZ_APPEND) {
252
+ LSEEK(state->fd, 0, SEEK_END); /* so gzoffset() is correct */
252
253
  state->mode = GZ_WRITE; /* simplify later checks */
254
+ }
253
255
 
254
256
  /* save the current position for rewinding (only if reading) */
255
257
  if (state->mode == GZ_READ) {
@@ -291,7 +293,7 @@ gzFile ZEXPORT gzdopen(fd, mode)
291
293
  if (fd == -1 || (path = (char *)malloc(7 + 3 * sizeof(int))) == NULL)
292
294
  return NULL;
293
295
  #if !defined(NO_snprintf) && !defined(NO_vsnprintf)
294
- snprintf(path, 7 + 3 * sizeof(int), "<fd:%d>", fd); /* for debugging */
296
+ (void)snprintf(path, 7 + 3 * sizeof(int), "<fd:%d>", fd);
295
297
  #else
296
298
  sprintf(path, "<fd:%d>", fd); /* for debugging */
297
299
  #endif
@@ -301,7 +303,7 @@ gzFile ZEXPORT gzdopen(fd, mode)
301
303
  }
302
304
 
303
305
  /* -- see zlib.h -- */
304
- #ifdef _WIN32
306
+ #ifdef WIDECHAR
305
307
  gzFile ZEXPORT gzopen_w(path, mode)
306
308
  const wchar_t *path;
307
309
  const char *mode;
@@ -329,6 +331,8 @@ int ZEXPORT gzbuffer(file, size)
329
331
  return -1;
330
332
 
331
333
  /* check and set requested size */
334
+ if ((size << 1) < size)
335
+ return -1; /* need to be able to double it */
332
336
  if (size < 2)
333
337
  size = 2; /* need two bytes to check magic header */
334
338
  state->want = size;
@@ -604,14 +608,13 @@ void ZLIB_INTERNAL gz_error(state, err, msg)
604
608
  return;
605
609
  }
606
610
  #if !defined(NO_snprintf) && !defined(NO_vsnprintf)
607
- snprintf(state->msg, strlen(state->path) + strlen(msg) + 3,
608
- "%s%s%s", state->path, ": ", msg);
611
+ (void)snprintf(state->msg, strlen(state->path) + strlen(msg) + 3,
612
+ "%s%s%s", state->path, ": ", msg);
609
613
  #else
610
614
  strcpy(state->msg, state->path);
611
615
  strcat(state->msg, ": ");
612
616
  strcat(state->msg, msg);
613
617
  #endif
614
- return;
615
618
  }
616
619
 
617
620
  #ifndef INT_MAX
@@ -1,5 +1,5 @@
1
1
  /* gzread.c -- zlib functions for reading gzip files
2
- * Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013 Mark Adler
2
+ * Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013, 2016 Mark Adler
3
3
  * For conditions of distribution and use, see copyright notice in zlib.h
4
4
  */
5
5
 
@@ -12,6 +12,7 @@ local int gz_look OF((gz_statep));
12
12
  local int gz_decomp OF((gz_statep));
13
13
  local int gz_fetch OF((gz_statep));
14
14
  local int gz_skip OF((gz_statep, z_off64_t));
15
+ local z_size_t gz_read OF((gz_statep, voidp, z_size_t));
15
16
 
16
17
  /* Use read() to load a buffer -- return -1 on error, otherwise 0. Read from
17
18
  state->fd, and update state->eof, state->err, and state->msg as appropriate.
@@ -24,13 +25,17 @@ local int gz_load(state, buf, len, have)
24
25
  unsigned *have;
25
26
  {
26
27
  int ret;
28
+ unsigned get, max = ((unsigned)-1 >> 2) + 1;
27
29
 
28
30
  *have = 0;
29
31
  do {
30
- ret = read(state->fd, buf + *have, len - *have);
32
+ get = len - *have;
33
+ if (get > max)
34
+ get = max;
35
+ ret = read(state->fd, buf + *have, get);
31
36
  if (ret <= 0)
32
37
  break;
33
- *have += ret;
38
+ *have += (unsigned)ret;
34
39
  } while (*have < len);
35
40
  if (ret < 0) {
36
41
  gz_error(state, Z_ERRNO, zstrerror());
@@ -94,10 +99,8 @@ local int gz_look(state)
94
99
  state->in = (unsigned char *)malloc(state->want);
95
100
  state->out = (unsigned char *)malloc(state->want << 1);
96
101
  if (state->in == NULL || state->out == NULL) {
97
- if (state->out != NULL)
98
- free(state->out);
99
- if (state->in != NULL)
100
- free(state->in);
102
+ free(state->out);
103
+ free(state->in);
101
104
  gz_error(state, Z_MEM_ERROR, "out of memory");
102
105
  return -1;
103
106
  }
@@ -284,33 +287,17 @@ local int gz_skip(state, len)
284
287
  return 0;
285
288
  }
286
289
 
287
- /* -- see zlib.h -- */
288
- int ZEXPORT gzread(file, buf, len)
289
- gzFile file;
290
+ /* Read len bytes into buf from file, or less than len up to the end of the
291
+ input. Return the number of bytes read. If zero is returned, either the
292
+ end of file was reached, or there was an error. state->err must be
293
+ consulted in that case to determine which. */
294
+ local z_size_t gz_read(state, buf, len)
295
+ gz_statep state;
290
296
  voidp buf;
291
- unsigned len;
297
+ z_size_t len;
292
298
  {
293
- unsigned got, n;
294
- gz_statep state;
295
- z_streamp strm;
296
-
297
- /* get internal structure */
298
- if (file == NULL)
299
- return -1;
300
- state = (gz_statep)file;
301
- strm = &(state->strm);
302
-
303
- /* check that we're reading and that there's no (serious) error */
304
- if (state->mode != GZ_READ ||
305
- (state->err != Z_OK && state->err != Z_BUF_ERROR))
306
- return -1;
307
-
308
- /* since an int is returned, make sure len fits in one, otherwise return
309
- with an error (this avoids the flaw in the interface) */
310
- if ((int)len < 0) {
311
- gz_error(state, Z_DATA_ERROR, "requested length does not fit in int");
312
- return -1;
313
- }
299
+ z_size_t got;
300
+ unsigned n;
314
301
 
315
302
  /* if len is zero, avoid unnecessary operations */
316
303
  if (len == 0)
@@ -320,32 +307,38 @@ int ZEXPORT gzread(file, buf, len)
320
307
  if (state->seek) {
321
308
  state->seek = 0;
322
309
  if (gz_skip(state, state->skip) == -1)
323
- return -1;
310
+ return 0;
324
311
  }
325
312
 
326
313
  /* get len bytes to buf, or less than len if at the end */
327
314
  got = 0;
328
315
  do {
316
+ /* set n to the maximum amount of len that fits in an unsigned int */
317
+ n = -1;
318
+ if (n > len)
319
+ n = len;
320
+
329
321
  /* first just try copying data from the output buffer */
330
322
  if (state->x.have) {
331
- n = state->x.have > len ? len : state->x.have;
323
+ if (state->x.have < n)
324
+ n = state->x.have;
332
325
  memcpy(buf, state->x.next, n);
333
326
  state->x.next += n;
334
327
  state->x.have -= n;
335
328
  }
336
329
 
337
330
  /* output buffer empty -- return if we're at the end of the input */
338
- else if (state->eof && strm->avail_in == 0) {
331
+ else if (state->eof && state->strm.avail_in == 0) {
339
332
  state->past = 1; /* tried to read past end */
340
333
  break;
341
334
  }
342
335
 
343
336
  /* need output data -- for small len or new stream load up our output
344
337
  buffer */
345
- else if (state->how == LOOK || len < (state->size << 1)) {
338
+ else if (state->how == LOOK || n < (state->size << 1)) {
346
339
  /* get more output, looking for header if required */
347
340
  if (gz_fetch(state) == -1)
348
- return -1;
341
+ return 0;
349
342
  continue; /* no progress yet -- go back to copy above */
350
343
  /* the copy above assures that we will leave with space in the
351
344
  output buffer, allowing at least one gzungetc() to succeed */
@@ -353,16 +346,16 @@ int ZEXPORT gzread(file, buf, len)
353
346
 
354
347
  /* large len -- read directly into user buffer */
355
348
  else if (state->how == COPY) { /* read directly */
356
- if (gz_load(state, (unsigned char *)buf, len, &n) == -1)
357
- return -1;
349
+ if (gz_load(state, (unsigned char *)buf, n, &n) == -1)
350
+ return 0;
358
351
  }
359
352
 
360
353
  /* large len -- decompress directly into user buffer */
361
354
  else { /* state->how == GZIP */
362
- strm->avail_out = len;
363
- strm->next_out = (unsigned char *)buf;
355
+ state->strm.avail_out = n;
356
+ state->strm.next_out = (unsigned char *)buf;
364
357
  if (gz_decomp(state) == -1)
365
- return -1;
358
+ return 0;
366
359
  n = state->x.have;
367
360
  state->x.have = 0;
368
361
  }
@@ -374,8 +367,75 @@ int ZEXPORT gzread(file, buf, len)
374
367
  state->x.pos += n;
375
368
  } while (len);
376
369
 
377
- /* return number of bytes read into user buffer (will fit in int) */
378
- return (int)got;
370
+ /* return number of bytes read into user buffer */
371
+ return got;
372
+ }
373
+
374
+ /* -- see zlib.h -- */
375
+ int ZEXPORT gzread(file, buf, len)
376
+ gzFile file;
377
+ voidp buf;
378
+ unsigned len;
379
+ {
380
+ gz_statep state;
381
+
382
+ /* get internal structure */
383
+ if (file == NULL)
384
+ return -1;
385
+ state = (gz_statep)file;
386
+
387
+ /* check that we're reading and that there's no (serious) error */
388
+ if (state->mode != GZ_READ ||
389
+ (state->err != Z_OK && state->err != Z_BUF_ERROR))
390
+ return -1;
391
+
392
+ /* since an int is returned, make sure len fits in one, otherwise return
393
+ with an error (this avoids a flaw in the interface) */
394
+ if ((int)len < 0) {
395
+ gz_error(state, Z_STREAM_ERROR, "request does not fit in an int");
396
+ return -1;
397
+ }
398
+
399
+ /* read len or fewer bytes to buf */
400
+ len = gz_read(state, buf, len);
401
+
402
+ /* check for an error */
403
+ if (len == 0 && state->err != Z_OK && state->err != Z_BUF_ERROR)
404
+ return -1;
405
+
406
+ /* return the number of bytes read (this is assured to fit in an int) */
407
+ return (int)len;
408
+ }
409
+
410
+ /* -- see zlib.h -- */
411
+ z_size_t ZEXPORT gzfread(buf, size, nitems, file)
412
+ voidp buf;
413
+ z_size_t size;
414
+ z_size_t nitems;
415
+ gzFile file;
416
+ {
417
+ z_size_t len;
418
+ gz_statep state;
419
+
420
+ /* get internal structure */
421
+ if (file == NULL)
422
+ return 0;
423
+ state = (gz_statep)file;
424
+
425
+ /* check that we're reading and that there's no (serious) error */
426
+ if (state->mode != GZ_READ ||
427
+ (state->err != Z_OK && state->err != Z_BUF_ERROR))
428
+ return 0;
429
+
430
+ /* compute bytes to read -- error on overflow */
431
+ len = nitems * size;
432
+ if (size && len / size != nitems) {
433
+ gz_error(state, Z_STREAM_ERROR, "request does not fit in a size_t");
434
+ return 0;
435
+ }
436
+
437
+ /* read len or fewer bytes to buf, return the number of full items read */
438
+ return len ? gz_read(state, buf, len) / size : 0;
379
439
  }
380
440
 
381
441
  /* -- see zlib.h -- */
@@ -408,8 +468,8 @@ int ZEXPORT gzgetc(file)
408
468
  return *(state->x.next)++;
409
469
  }
410
470
 
411
- /* nothing there -- try gzread() */
412
- ret = gzread(file, buf, 1);
471
+ /* nothing there -- try gz_read() */
472
+ ret = gz_read(state, buf, 1);
413
473
  return ret < 1 ? -1 : buf[0];
414
474
  }
415
475
 
@@ -451,7 +511,7 @@ int ZEXPORT gzungetc(c, file)
451
511
  if (state->x.have == 0) {
452
512
  state->x.have = 1;
453
513
  state->x.next = state->out + (state->size << 1) - 1;
454
- state->x.next[0] = c;
514
+ state->x.next[0] = (unsigned char)c;
455
515
  state->x.pos--;
456
516
  state->past = 0;
457
517
  return c;
@@ -473,7 +533,7 @@ int ZEXPORT gzungetc(c, file)
473
533
  }
474
534
  state->x.have++;
475
535
  state->x.next--;
476
- state->x.next[0] = c;
536
+ state->x.next[0] = (unsigned char)c;
477
537
  state->x.pos--;
478
538
  state->past = 0;
479
539
  return c;