zstdlib 0.9.0-x64-mingw32 → 0.10.0-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +5 -0
  3. data/ext/zstdlib_c/extconf.rb +1 -1
  4. data/ext/zstdlib_c/{zlib-1.2.11 → zlib-1.2.12}/adler32.c +0 -0
  5. data/ext/zstdlib_c/{zlib-1.2.11 → zlib-1.2.12}/compress.c +0 -0
  6. data/ext/zstdlib_c/zlib-1.2.12/crc32.c +1116 -0
  7. data/ext/zstdlib_c/zlib-1.2.12/crc32.h +9446 -0
  8. data/ext/zstdlib_c/{zlib-1.2.11 → zlib-1.2.12}/deflate.c +78 -30
  9. data/ext/zstdlib_c/{zlib-1.2.11 → zlib-1.2.12}/deflate.h +12 -15
  10. data/ext/zstdlib_c/{zlib-1.2.11 → zlib-1.2.12}/gzclose.c +0 -0
  11. data/ext/zstdlib_c/{zlib-1.2.11 → zlib-1.2.12}/gzguts.h +3 -2
  12. data/ext/zstdlib_c/{zlib-1.2.11 → zlib-1.2.12}/gzlib.c +5 -3
  13. data/ext/zstdlib_c/{zlib-1.2.11 → zlib-1.2.12}/gzread.c +5 -7
  14. data/ext/zstdlib_c/{zlib-1.2.11 → zlib-1.2.12}/gzwrite.c +25 -13
  15. data/ext/zstdlib_c/{zlib-1.2.11 → zlib-1.2.12}/infback.c +2 -1
  16. data/ext/zstdlib_c/{zlib-1.2.11 → zlib-1.2.12}/inffast.c +14 -14
  17. data/ext/zstdlib_c/{zlib-1.2.11 → zlib-1.2.12}/inffast.h +0 -0
  18. data/ext/zstdlib_c/{zlib-1.2.11 → zlib-1.2.12}/inffixed.h +0 -0
  19. data/ext/zstdlib_c/{zlib-1.2.11 → zlib-1.2.12}/inflate.c +39 -8
  20. data/ext/zstdlib_c/{zlib-1.2.11 → zlib-1.2.12}/inflate.h +3 -2
  21. data/ext/zstdlib_c/{zlib-1.2.11 → zlib-1.2.12}/inftrees.c +3 -3
  22. data/ext/zstdlib_c/{zlib-1.2.11 → zlib-1.2.12}/inftrees.h +0 -0
  23. data/ext/zstdlib_c/{zlib-1.2.11 → zlib-1.2.12}/trees.c +27 -48
  24. data/ext/zstdlib_c/{zlib-1.2.11 → zlib-1.2.12}/trees.h +0 -0
  25. data/ext/zstdlib_c/{zlib-1.2.11 → zlib-1.2.12}/uncompr.c +0 -0
  26. data/ext/zstdlib_c/{zlib-1.2.11 → zlib-1.2.12}/zconf.h +0 -0
  27. data/ext/zstdlib_c/{zlib-1.2.11 → zlib-1.2.12}/zlib.h +123 -100
  28. data/ext/zstdlib_c/{zlib-1.2.11 → zlib-1.2.12}/zutil.c +2 -2
  29. data/ext/zstdlib_c/{zlib-1.2.11 → zlib-1.2.12}/zutil.h +12 -9
  30. data/lib/2.4/zstdlib_c.so +0 -0
  31. data/lib/2.5/zstdlib_c.so +0 -0
  32. data/lib/2.6/zstdlib_c.so +0 -0
  33. data/lib/2.7/zstdlib_c.so +0 -0
  34. data/lib/3.0/zstdlib_c.so +0 -0
  35. metadata +28 -28
  36. data/ext/zstdlib_c/zlib-1.2.11/crc32.c +0 -442
  37. data/ext/zstdlib_c/zlib-1.2.11/crc32.h +0 -441
@@ -1,5 +1,5 @@
1
1
  /* deflate.c -- compress data using the deflation algorithm
2
- * Copyright (C) 1995-2017 Jean-loup Gailly and Mark Adler
2
+ * Copyright (C) 1995-2022 Jean-loup Gailly and Mark Adler
3
3
  * For conditions of distribution and use, see copyright notice in zlib.h
4
4
  */
5
5
 
@@ -52,7 +52,7 @@
52
52
  #include "deflate.h"
53
53
 
54
54
  const char deflate_copyright[] =
55
- " deflate 1.2.11 Copyright 1995-2017 Jean-loup Gailly and Mark Adler ";
55
+ " deflate 1.2.12 Copyright 1995-2022 Jean-loup Gailly and Mark Adler ";
56
56
  /*
57
57
  If you use the zlib library in a product, an acknowledgment is welcome
58
58
  in the documentation of your product. If for some reason you cannot
@@ -190,8 +190,11 @@ local const config configuration_table[10] = {
190
190
  * prev[] will be initialized on the fly.
191
191
  */
192
192
  #define CLEAR_HASH(s) \
193
- s->head[s->hash_size-1] = NIL; \
194
- zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head));
193
+ do { \
194
+ s->head[s->hash_size-1] = NIL; \
195
+ zmemzero((Bytef *)s->head, \
196
+ (unsigned)(s->hash_size-1)*sizeof(*s->head)); \
197
+ } while (0)
195
198
 
196
199
  /* ===========================================================================
197
200
  * Slide the hash table when sliding the window down (could be avoided with 32
@@ -252,11 +255,6 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
252
255
  int wrap = 1;
253
256
  static const char my_version[] = ZLIB_VERSION;
254
257
 
255
- ushf *overlay;
256
- /* We overlay pending_buf and d_buf+l_buf. This works since the average
257
- * output size for (length,distance) codes is <= 24 bits.
258
- */
259
-
260
258
  if (version == Z_NULL || version[0] != my_version[0] ||
261
259
  stream_size != sizeof(z_stream)) {
262
260
  return Z_VERSION_ERROR;
@@ -326,9 +324,47 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
326
324
 
327
325
  s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
328
326
 
329
- overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);
330
- s->pending_buf = (uchf *) overlay;
331
- s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L);
327
+ /* We overlay pending_buf and sym_buf. This works since the average size
328
+ * for length/distance pairs over any compressed block is assured to be 31
329
+ * bits or less.
330
+ *
331
+ * Analysis: The longest fixed codes are a length code of 8 bits plus 5
332
+ * extra bits, for lengths 131 to 257. The longest fixed distance codes are
333
+ * 5 bits plus 13 extra bits, for distances 16385 to 32768. The longest
334
+ * possible fixed-codes length/distance pair is then 31 bits total.
335
+ *
336
+ * sym_buf starts one-fourth of the way into pending_buf. So there are
337
+ * three bytes in sym_buf for every four bytes in pending_buf. Each symbol
338
+ * in sym_buf is three bytes -- two for the distance and one for the
339
+ * literal/length. As each symbol is consumed, the pointer to the next
340
+ * sym_buf value to read moves forward three bytes. From that symbol, up to
341
+ * 31 bits are written to pending_buf. The closest the written pending_buf
342
+ * bits gets to the next sym_buf symbol to read is just before the last
343
+ * code is written. At that time, 31*(n-2) bits have been written, just
344
+ * after 24*(n-2) bits have been consumed from sym_buf. sym_buf starts at
345
+ * 8*n bits into pending_buf. (Note that the symbol buffer fills when n-1
346
+ * symbols are written.) The closest the writing gets to what is unread is
347
+ * then n+14 bits. Here n is lit_bufsize, which is 16384 by default, and
348
+ * can range from 128 to 32768.
349
+ *
350
+ * Therefore, at a minimum, there are 142 bits of space between what is
351
+ * written and what is read in the overlain buffers, so the symbols cannot
352
+ * be overwritten by the compressed data. That space is actually 139 bits,
353
+ * due to the three-bit fixed-code block header.
354
+ *
355
+ * That covers the case where either Z_FIXED is specified, forcing fixed
356
+ * codes, or when the use of fixed codes is chosen, because that choice
357
+ * results in a smaller compressed block than dynamic codes. That latter
358
+ * condition then assures that the above analysis also covers all dynamic
359
+ * blocks. A dynamic-code block will only be chosen to be emitted if it has
360
+ * fewer bits than a fixed-code block would for the same set of symbols.
361
+ * Therefore its average symbol length is assured to be less than 31. So
362
+ * the compressed data for a dynamic block also cannot overwrite the
363
+ * symbols from which it is being constructed.
364
+ */
365
+
366
+ s->pending_buf = (uchf *) ZALLOC(strm, s->lit_bufsize, 4);
367
+ s->pending_buf_size = (ulg)s->lit_bufsize * 4;
332
368
 
333
369
  if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
334
370
  s->pending_buf == Z_NULL) {
@@ -337,8 +373,12 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
337
373
  deflateEnd (strm);
338
374
  return Z_MEM_ERROR;
339
375
  }
340
- s->d_buf = overlay + s->lit_bufsize/sizeof(ush);
341
- s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize;
376
+ s->sym_buf = s->pending_buf + s->lit_bufsize;
377
+ s->sym_end = (s->lit_bufsize - 1) * 3;
378
+ /* We avoid equality with lit_bufsize*3 because of wraparound at 64K
379
+ * on 16 bit machines and because stored blocks are restricted to
380
+ * 64K-1 bytes.
381
+ */
342
382
 
343
383
  s->level = level;
344
384
  s->strategy = strategy;
@@ -488,13 +528,13 @@ int ZEXPORT deflateResetKeep (strm)
488
528
  #ifdef GZIP
489
529
  s->wrap == 2 ? GZIP_STATE :
490
530
  #endif
491
- s->wrap ? INIT_STATE : BUSY_STATE;
531
+ INIT_STATE;
492
532
  strm->adler =
493
533
  #ifdef GZIP
494
534
  s->wrap == 2 ? crc32(0L, Z_NULL, 0) :
495
535
  #endif
496
536
  adler32(0L, Z_NULL, 0);
497
- s->last_flush = Z_NO_FLUSH;
537
+ s->last_flush = -2;
498
538
 
499
539
  _tr_init(s);
500
540
 
@@ -549,7 +589,8 @@ int ZEXPORT deflatePrime (strm, bits, value)
549
589
 
550
590
  if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
551
591
  s = strm->state;
552
- if ((Bytef *)(s->d_buf) < s->pending_out + ((Buf_size + 7) >> 3))
592
+ if (bits < 0 || bits > 16 ||
593
+ s->sym_buf < s->pending_out + ((Buf_size + 7) >> 3))
553
594
  return Z_BUF_ERROR;
554
595
  do {
555
596
  put = Buf_size - s->bi_valid;
@@ -587,12 +628,12 @@ int ZEXPORT deflateParams(strm, level, strategy)
587
628
  func = configuration_table[s->level].func;
588
629
 
589
630
  if ((strategy != s->strategy || func != configuration_table[level].func) &&
590
- s->high_water) {
631
+ s->last_flush != -2) {
591
632
  /* Flush the last buffer: */
592
633
  int err = deflate(strm, Z_BLOCK);
593
634
  if (err == Z_STREAM_ERROR)
594
635
  return err;
595
- if (strm->avail_out == 0)
636
+ if (strm->avail_in || (s->strstart - s->block_start) + s->lookahead)
596
637
  return Z_BUF_ERROR;
597
638
  }
598
639
  if (s->level != level) {
@@ -811,6 +852,8 @@ int ZEXPORT deflate (strm, flush)
811
852
  }
812
853
 
813
854
  /* Write the header */
855
+ if (s->status == INIT_STATE && s->wrap == 0)
856
+ s->status = BUSY_STATE;
814
857
  if (s->status == INIT_STATE) {
815
858
  /* zlib header */
816
859
  uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8;
@@ -1108,7 +1151,6 @@ int ZEXPORT deflateCopy (dest, source)
1108
1151
  #else
1109
1152
  deflate_state *ds;
1110
1153
  deflate_state *ss;
1111
- ushf *overlay;
1112
1154
 
1113
1155
 
1114
1156
  if (deflateStateCheck(source) || dest == Z_NULL) {
@@ -1128,8 +1170,7 @@ int ZEXPORT deflateCopy (dest, source)
1128
1170
  ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
1129
1171
  ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos));
1130
1172
  ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos));
1131
- overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2);
1132
- ds->pending_buf = (uchf *) overlay;
1173
+ ds->pending_buf = (uchf *) ZALLOC(dest, ds->lit_bufsize, 4);
1133
1174
 
1134
1175
  if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL ||
1135
1176
  ds->pending_buf == Z_NULL) {
@@ -1143,8 +1184,7 @@ int ZEXPORT deflateCopy (dest, source)
1143
1184
  zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
1144
1185
 
1145
1186
  ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
1146
- ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush);
1147
- ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize;
1187
+ ds->sym_buf = ds->pending_buf + ds->lit_bufsize;
1148
1188
 
1149
1189
  ds->l_desc.dyn_tree = ds->dyn_ltree;
1150
1190
  ds->d_desc.dyn_tree = ds->dyn_dtree;
@@ -1513,6 +1553,8 @@ local void fill_window(s)
1513
1553
  s->match_start -= wsize;
1514
1554
  s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
1515
1555
  s->block_start -= (long) wsize;
1556
+ if (s->insert > s->strstart)
1557
+ s->insert = s->strstart;
1516
1558
  slide_hash(s);
1517
1559
  more += wsize;
1518
1560
  }
@@ -1742,6 +1784,7 @@ local block_state deflate_stored(s, flush)
1742
1784
  s->matches = 2; /* clear hash */
1743
1785
  zmemcpy(s->window, s->strm->next_in - s->w_size, s->w_size);
1744
1786
  s->strstart = s->w_size;
1787
+ s->insert = s->strstart;
1745
1788
  }
1746
1789
  else {
1747
1790
  if (s->window_size - s->strstart <= used) {
@@ -1750,12 +1793,14 @@ local block_state deflate_stored(s, flush)
1750
1793
  zmemcpy(s->window, s->window + s->w_size, s->strstart);
1751
1794
  if (s->matches < 2)
1752
1795
  s->matches++; /* add a pending slide_hash() */
1796
+ if (s->insert > s->strstart)
1797
+ s->insert = s->strstart;
1753
1798
  }
1754
1799
  zmemcpy(s->window + s->strstart, s->strm->next_in - used, used);
1755
1800
  s->strstart += used;
1801
+ s->insert += MIN(used, s->w_size - s->insert);
1756
1802
  }
1757
1803
  s->block_start = s->strstart;
1758
- s->insert += MIN(used, s->w_size - s->insert);
1759
1804
  }
1760
1805
  if (s->high_water < s->strstart)
1761
1806
  s->high_water = s->strstart;
@@ -1770,7 +1815,7 @@ local block_state deflate_stored(s, flush)
1770
1815
  return block_done;
1771
1816
 
1772
1817
  /* Fill the window with any remaining input. */
1773
- have = s->window_size - s->strstart - 1;
1818
+ have = s->window_size - s->strstart;
1774
1819
  if (s->strm->avail_in > have && s->block_start >= (long)s->w_size) {
1775
1820
  /* Slide the window down. */
1776
1821
  s->block_start -= s->w_size;
@@ -1779,12 +1824,15 @@ local block_state deflate_stored(s, flush)
1779
1824
  if (s->matches < 2)
1780
1825
  s->matches++; /* add a pending slide_hash() */
1781
1826
  have += s->w_size; /* more space now */
1827
+ if (s->insert > s->strstart)
1828
+ s->insert = s->strstart;
1782
1829
  }
1783
1830
  if (have > s->strm->avail_in)
1784
1831
  have = s->strm->avail_in;
1785
1832
  if (have) {
1786
1833
  read_buf(s->strm, s->window + s->strstart, have);
1787
1834
  s->strstart += have;
1835
+ s->insert += MIN(have, s->w_size - s->insert);
1788
1836
  }
1789
1837
  if (s->high_water < s->strstart)
1790
1838
  s->high_water = s->strstart;
@@ -1912,7 +1960,7 @@ local block_state deflate_fast(s, flush)
1912
1960
  FLUSH_BLOCK(s, 1);
1913
1961
  return finish_done;
1914
1962
  }
1915
- if (s->last_lit)
1963
+ if (s->sym_next)
1916
1964
  FLUSH_BLOCK(s, 0);
1917
1965
  return block_done;
1918
1966
  }
@@ -2043,7 +2091,7 @@ local block_state deflate_slow(s, flush)
2043
2091
  FLUSH_BLOCK(s, 1);
2044
2092
  return finish_done;
2045
2093
  }
2046
- if (s->last_lit)
2094
+ if (s->sym_next)
2047
2095
  FLUSH_BLOCK(s, 0);
2048
2096
  return block_done;
2049
2097
  }
@@ -2118,7 +2166,7 @@ local block_state deflate_rle(s, flush)
2118
2166
  FLUSH_BLOCK(s, 1);
2119
2167
  return finish_done;
2120
2168
  }
2121
- if (s->last_lit)
2169
+ if (s->sym_next)
2122
2170
  FLUSH_BLOCK(s, 0);
2123
2171
  return block_done;
2124
2172
  }
@@ -2157,7 +2205,7 @@ local block_state deflate_huff(s, flush)
2157
2205
  FLUSH_BLOCK(s, 1);
2158
2206
  return finish_done;
2159
2207
  }
2160
- if (s->last_lit)
2208
+ if (s->sym_next)
2161
2209
  FLUSH_BLOCK(s, 0);
2162
2210
  return block_done;
2163
2211
  }
@@ -1,5 +1,5 @@
1
1
  /* deflate.h -- internal compression state
2
- * Copyright (C) 1995-2016 Jean-loup Gailly
2
+ * Copyright (C) 1995-2018 Jean-loup Gailly
3
3
  * For conditions of distribution and use, see copyright notice in zlib.h
4
4
  */
5
5
 
@@ -217,7 +217,7 @@ typedef struct internal_state {
217
217
  /* Depth of each subtree used as tie breaker for trees of equal frequency
218
218
  */
219
219
 
220
- uchf *l_buf; /* buffer for literals or lengths */
220
+ uchf *sym_buf; /* buffer for distances and literals/lengths */
221
221
 
222
222
  uInt lit_bufsize;
223
223
  /* Size of match buffer for literals/lengths. There are 4 reasons for
@@ -239,13 +239,8 @@ typedef struct internal_state {
239
239
  * - I can't count above 4
240
240
  */
241
241
 
242
- uInt last_lit; /* running index in l_buf */
243
-
244
- ushf *d_buf;
245
- /* Buffer for distances. To simplify the code, d_buf and l_buf have
246
- * the same number of elements. To use different lengths, an extra flag
247
- * array would be necessary.
248
- */
242
+ uInt sym_next; /* running index in sym_buf */
243
+ uInt sym_end; /* symbol table full when sym_next reaches this */
249
244
 
250
245
  ulg opt_len; /* bit length of current block with optimal trees */
251
246
  ulg static_len; /* bit length of current block with static trees */
@@ -325,20 +320,22 @@ void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf,
325
320
 
326
321
  # define _tr_tally_lit(s, c, flush) \
327
322
  { uch cc = (c); \
328
- s->d_buf[s->last_lit] = 0; \
329
- s->l_buf[s->last_lit++] = cc; \
323
+ s->sym_buf[s->sym_next++] = 0; \
324
+ s->sym_buf[s->sym_next++] = 0; \
325
+ s->sym_buf[s->sym_next++] = cc; \
330
326
  s->dyn_ltree[cc].Freq++; \
331
- flush = (s->last_lit == s->lit_bufsize-1); \
327
+ flush = (s->sym_next == s->sym_end); \
332
328
  }
333
329
  # define _tr_tally_dist(s, distance, length, flush) \
334
330
  { uch len = (uch)(length); \
335
331
  ush dist = (ush)(distance); \
336
- s->d_buf[s->last_lit] = dist; \
337
- s->l_buf[s->last_lit++] = len; \
332
+ s->sym_buf[s->sym_next++] = dist; \
333
+ s->sym_buf[s->sym_next++] = dist >> 8; \
334
+ s->sym_buf[s->sym_next++] = len; \
338
335
  dist--; \
339
336
  s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
340
337
  s->dyn_dtree[d_code(dist)].Freq++; \
341
- flush = (s->last_lit == s->lit_bufsize-1); \
338
+ flush = (s->sym_next == s->sym_end); \
342
339
  }
343
340
  #else
344
341
  # define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
@@ -1,5 +1,5 @@
1
1
  /* gzguts.h -- zlib internal header definitions for gz* operations
2
- * Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013, 2016 Mark Adler
2
+ * Copyright (C) 2004-2019 Mark Adler
3
3
  * For conditions of distribution and use, see copyright notice in zlib.h
4
4
  */
5
5
 
@@ -39,7 +39,7 @@
39
39
  # include <io.h>
40
40
  #endif
41
41
 
42
- #if defined(_WIN32) || defined(__CYGWIN__)
42
+ #if defined(_WIN32)
43
43
  # define WIDECHAR
44
44
  #endif
45
45
 
@@ -190,6 +190,7 @@ typedef struct {
190
190
  /* just for writing */
191
191
  int level; /* compression level */
192
192
  int strategy; /* compression strategy */
193
+ int reset; /* true if a reset is pending after a Z_FINISH */
193
194
  /* seek request */
194
195
  z_off64_t skip; /* amount to skip (already rewound if backwards) */
195
196
  int seek; /* true if seek request pending */
@@ -1,11 +1,11 @@
1
1
  /* gzlib.c -- zlib functions common to reading and writing gzip files
2
- * Copyright (C) 2004-2017 Mark Adler
2
+ * Copyright (C) 2004-2019 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__) && !defined(__MINGW32__)
8
+ #if defined(_WIN32) && !defined(__BORLANDC__)
9
9
  # define LSEEK _lseeki64
10
10
  #else
11
11
  #if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
@@ -81,6 +81,8 @@ local void gz_reset(state)
81
81
  state->past = 0; /* have not read past end yet */
82
82
  state->how = LOOK; /* look for gzip header */
83
83
  }
84
+ else /* for writing ... */
85
+ state->reset = 0; /* no deflateReset pending */
84
86
  state->seek = 0; /* no seek request pending */
85
87
  gz_error(state, Z_OK, NULL); /* clear error */
86
88
  state->x.pos = 0; /* no uncompressed data yet */
@@ -397,7 +399,7 @@ z_off64_t ZEXPORT gzseek64(file, offset, whence)
397
399
  /* if within raw area while reading, just go there */
398
400
  if (state->mode == GZ_READ && state->how == COPY &&
399
401
  state->x.pos + offset >= 0) {
400
- ret = LSEEK(state->fd, offset - state->x.have, SEEK_CUR);
402
+ ret = LSEEK(state->fd, offset - (z_off64_t)state->x.have, SEEK_CUR);
401
403
  if (ret == -1)
402
404
  return -1;
403
405
  state->x.have = 0;
@@ -1,5 +1,5 @@
1
1
  /* gzread.c -- zlib functions for reading gzip files
2
- * Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013, 2016 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
 
@@ -314,9 +314,9 @@ local z_size_t gz_read(state, buf, len)
314
314
  got = 0;
315
315
  do {
316
316
  /* set n to the maximum amount of len that fits in an unsigned int */
317
- n = -1;
317
+ n = (unsigned)-1;
318
318
  if (n > len)
319
- n = len;
319
+ n = (unsigned)len;
320
320
 
321
321
  /* first just try copying data from the output buffer */
322
322
  if (state->x.have) {
@@ -397,7 +397,7 @@ int ZEXPORT gzread(file, buf, len)
397
397
  }
398
398
 
399
399
  /* read len or fewer bytes to buf */
400
- len = gz_read(state, buf, len);
400
+ len = (unsigned)gz_read(state, buf, len);
401
401
 
402
402
  /* check for an error */
403
403
  if (len == 0 && state->err != Z_OK && state->err != Z_BUF_ERROR)
@@ -447,7 +447,6 @@ z_size_t ZEXPORT gzfread(buf, size, nitems, file)
447
447
  int ZEXPORT gzgetc(file)
448
448
  gzFile file;
449
449
  {
450
- int ret;
451
450
  unsigned char buf[1];
452
451
  gz_statep state;
453
452
 
@@ -469,8 +468,7 @@ int ZEXPORT gzgetc(file)
469
468
  }
470
469
 
471
470
  /* nothing there -- try gz_read() */
472
- ret = gz_read(state, buf, 1);
473
- return ret < 1 ? -1 : buf[0];
471
+ return gz_read(state, buf, 1) < 1 ? -1 : buf[0];
474
472
  }
475
473
 
476
474
  int ZEXPORT gzgetc_(file)
@@ -1,5 +1,5 @@
1
1
  /* gzwrite.c -- zlib functions for writing gzip files
2
- * Copyright (C) 2004-2017 Mark Adler
2
+ * Copyright (C) 2004-2019 Mark Adler
3
3
  * For conditions of distribution and use, see copyright notice in zlib.h
4
4
  */
5
5
 
@@ -97,6 +97,15 @@ local int gz_comp(state, flush)
97
97
  return 0;
98
98
  }
99
99
 
100
+ /* check for a pending reset */
101
+ if (state->reset) {
102
+ /* don't start a new gzip member unless there is data to write */
103
+ if (strm->avail_in == 0)
104
+ return 0;
105
+ deflateReset(strm);
106
+ state->reset = 0;
107
+ }
108
+
100
109
  /* run deflate() on provided input until it produces no more output */
101
110
  ret = Z_OK;
102
111
  do {
@@ -134,7 +143,7 @@ local int gz_comp(state, flush)
134
143
 
135
144
  /* if that completed a deflate stream, allow another to start */
136
145
  if (flush == Z_FINISH)
137
- deflateReset(strm);
146
+ state->reset = 1;
138
147
 
139
148
  /* all done, no errors */
140
149
  return 0;
@@ -209,7 +218,7 @@ local z_size_t gz_write(state, buf, len)
209
218
  state->in);
210
219
  copy = state->size - have;
211
220
  if (copy > len)
212
- copy = len;
221
+ copy = (unsigned)len;
213
222
  memcpy(state->in + have, buf, copy);
214
223
  state->strm.avail_in += copy;
215
224
  state->x.pos += copy;
@@ -229,7 +238,7 @@ local z_size_t gz_write(state, buf, len)
229
238
  do {
230
239
  unsigned n = (unsigned)-1;
231
240
  if (n > len)
232
- n = len;
241
+ n = (unsigned)len;
233
242
  state->strm.avail_in = n;
234
243
  state->x.pos += n;
235
244
  if (gz_comp(state, Z_NO_FLUSH) == -1)
@@ -349,12 +358,11 @@ int ZEXPORT gzputc(file, c)
349
358
  }
350
359
 
351
360
  /* -- see zlib.h -- */
352
- int ZEXPORT gzputs(file, str)
361
+ int ZEXPORT gzputs(file, s)
353
362
  gzFile file;
354
- const char *str;
363
+ const char *s;
355
364
  {
356
- int ret;
357
- z_size_t len;
365
+ z_size_t len, put;
358
366
  gz_statep state;
359
367
 
360
368
  /* get internal structure */
@@ -367,9 +375,13 @@ int ZEXPORT gzputs(file, str)
367
375
  return -1;
368
376
 
369
377
  /* write string */
370
- len = strlen(str);
371
- ret = gz_write(state, str, len);
372
- return ret == 0 && len != 0 ? -1 : ret;
378
+ len = strlen(s);
379
+ if ((int)len < 0 || (unsigned)len != len) {
380
+ gz_error(state, Z_STREAM_ERROR, "string length does not fit in int");
381
+ return -1;
382
+ }
383
+ put = gz_write(state, s, len);
384
+ return put < len ? -1 : (int)len;
373
385
  }
374
386
 
375
387
  #if defined(STDC) || defined(Z_HAVE_STDARG_H)
@@ -441,7 +453,7 @@ int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va)
441
453
  strm->avail_in = state->size;
442
454
  if (gz_comp(state, Z_NO_FLUSH) == -1)
443
455
  return state->err;
444
- memcpy(state->in, state->in + state->size, left);
456
+ memmove(state->in, state->in + state->size, left);
445
457
  strm->next_in = state->in;
446
458
  strm->avail_in = left;
447
459
  }
@@ -540,7 +552,7 @@ int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
540
552
  strm->avail_in = state->size;
541
553
  if (gz_comp(state, Z_NO_FLUSH) == -1)
542
554
  return state->err;
543
- memcpy(state->in, state->in + state->size, left);
555
+ memmove(state->in, state->in + state->size, left);
544
556
  strm->next_in = state->in;
545
557
  strm->avail_in = left;
546
558
  }
@@ -1,5 +1,5 @@
1
1
  /* infback.c -- inflate using a call-back interface
2
- * Copyright (C) 1995-2016 Mark Adler
2
+ * Copyright (C) 1995-2022 Mark Adler
3
3
  * For conditions of distribution and use, see copyright notice in zlib.h
4
4
  */
5
5
 
@@ -477,6 +477,7 @@ void FAR *out_desc;
477
477
  }
478
478
  Tracev((stderr, "inflate: codes ok\n"));
479
479
  state->mode = LEN;
480
+ /* fallthrough */
480
481
 
481
482
  case LEN:
482
483
  /* use inflate_fast() if we have enough input and output */
@@ -70,7 +70,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
70
70
  code const FAR *dcode; /* local strm->distcode */
71
71
  unsigned lmask; /* mask for first level of length codes */
72
72
  unsigned dmask; /* mask for first level of distance codes */
73
- code here; /* retrieved table entry */
73
+ code const *here; /* retrieved table entry */
74
74
  unsigned op; /* code bits, operation, extra bits, or */
75
75
  /* window position, window bytes to copy */
76
76
  unsigned len; /* match length, unused bytes */
@@ -107,20 +107,20 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
107
107
  hold += (unsigned long)(*in++) << bits;
108
108
  bits += 8;
109
109
  }
110
- here = lcode[hold & lmask];
110
+ here = lcode + (hold & lmask);
111
111
  dolen:
112
- op = (unsigned)(here.bits);
112
+ op = (unsigned)(here->bits);
113
113
  hold >>= op;
114
114
  bits -= op;
115
- op = (unsigned)(here.op);
115
+ op = (unsigned)(here->op);
116
116
  if (op == 0) { /* literal */
117
- Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
117
+ Tracevv((stderr, here->val >= 0x20 && here->val < 0x7f ?
118
118
  "inflate: literal '%c'\n" :
119
- "inflate: literal 0x%02x\n", here.val));
120
- *out++ = (unsigned char)(here.val);
119
+ "inflate: literal 0x%02x\n", here->val));
120
+ *out++ = (unsigned char)(here->val);
121
121
  }
122
122
  else if (op & 16) { /* length base */
123
- len = (unsigned)(here.val);
123
+ len = (unsigned)(here->val);
124
124
  op &= 15; /* number of extra bits */
125
125
  if (op) {
126
126
  if (bits < op) {
@@ -138,14 +138,14 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
138
138
  hold += (unsigned long)(*in++) << bits;
139
139
  bits += 8;
140
140
  }
141
- here = dcode[hold & dmask];
141
+ here = dcode + (hold & dmask);
142
142
  dodist:
143
- op = (unsigned)(here.bits);
143
+ op = (unsigned)(here->bits);
144
144
  hold >>= op;
145
145
  bits -= op;
146
- op = (unsigned)(here.op);
146
+ op = (unsigned)(here->op);
147
147
  if (op & 16) { /* distance base */
148
- dist = (unsigned)(here.val);
148
+ dist = (unsigned)(here->val);
149
149
  op &= 15; /* number of extra bits */
150
150
  if (bits < op) {
151
151
  hold += (unsigned long)(*in++) << bits;
@@ -264,7 +264,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
264
264
  }
265
265
  }
266
266
  else if ((op & 64) == 0) { /* 2nd level distance code */
267
- here = dcode[here.val + (hold & ((1U << op) - 1))];
267
+ here = dcode + here->val + (hold & ((1U << op) - 1));
268
268
  goto dodist;
269
269
  }
270
270
  else {
@@ -274,7 +274,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
274
274
  }
275
275
  }
276
276
  else if ((op & 64) == 0) { /* 2nd level length code */
277
- here = lcode[here.val + (hold & ((1U << op) - 1))];
277
+ here = lcode + here->val + (hold & ((1U << op) - 1));
278
278
  goto dolen;
279
279
  }
280
280
  else if (op & 32) { /* end-of-block */