extzstd 0.3.1 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +28 -14
  3. data/contrib/zstd/CHANGELOG +301 -56
  4. data/contrib/zstd/CONTRIBUTING.md +169 -72
  5. data/contrib/zstd/LICENSE +4 -4
  6. data/contrib/zstd/Makefile +116 -87
  7. data/contrib/zstd/Package.swift +36 -0
  8. data/contrib/zstd/README.md +62 -32
  9. data/contrib/zstd/TESTING.md +2 -3
  10. data/contrib/zstd/appveyor.yml +52 -136
  11. data/contrib/zstd/lib/BUCK +5 -7
  12. data/contrib/zstd/lib/Makefile +225 -222
  13. data/contrib/zstd/lib/README.md +51 -6
  14. data/contrib/zstd/lib/common/allocations.h +55 -0
  15. data/contrib/zstd/lib/common/bits.h +200 -0
  16. data/contrib/zstd/lib/common/bitstream.h +45 -62
  17. data/contrib/zstd/lib/common/compiler.h +205 -22
  18. data/contrib/zstd/lib/common/cpu.h +1 -3
  19. data/contrib/zstd/lib/common/debug.c +1 -1
  20. data/contrib/zstd/lib/common/debug.h +12 -19
  21. data/contrib/zstd/lib/common/entropy_common.c +172 -48
  22. data/contrib/zstd/lib/common/error_private.c +10 -2
  23. data/contrib/zstd/lib/common/error_private.h +82 -3
  24. data/contrib/zstd/lib/common/fse.h +37 -86
  25. data/contrib/zstd/lib/common/fse_decompress.c +117 -92
  26. data/contrib/zstd/lib/common/huf.h +99 -166
  27. data/contrib/zstd/lib/common/mem.h +124 -142
  28. data/contrib/zstd/lib/common/pool.c +54 -27
  29. data/contrib/zstd/lib/common/pool.h +10 -4
  30. data/contrib/zstd/lib/common/portability_macros.h +156 -0
  31. data/contrib/zstd/lib/common/threading.c +74 -19
  32. data/contrib/zstd/lib/common/threading.h +5 -10
  33. data/contrib/zstd/lib/common/xxhash.c +7 -847
  34. data/contrib/zstd/lib/common/xxhash.h +5568 -167
  35. data/contrib/zstd/lib/common/zstd_common.c +2 -37
  36. data/contrib/zstd/lib/common/zstd_deps.h +111 -0
  37. data/contrib/zstd/lib/common/zstd_internal.h +132 -187
  38. data/contrib/zstd/lib/common/zstd_trace.h +163 -0
  39. data/contrib/zstd/lib/compress/clevels.h +134 -0
  40. data/contrib/zstd/lib/compress/fse_compress.c +83 -157
  41. data/contrib/zstd/lib/compress/hist.c +27 -29
  42. data/contrib/zstd/lib/compress/hist.h +2 -2
  43. data/contrib/zstd/lib/compress/huf_compress.c +916 -279
  44. data/contrib/zstd/lib/compress/zstd_compress.c +3773 -1019
  45. data/contrib/zstd/lib/compress/zstd_compress_internal.h +610 -203
  46. data/contrib/zstd/lib/compress/zstd_compress_literals.c +119 -42
  47. data/contrib/zstd/lib/compress/zstd_compress_literals.h +16 -6
  48. data/contrib/zstd/lib/compress/zstd_compress_sequences.c +42 -19
  49. data/contrib/zstd/lib/compress/zstd_compress_sequences.h +1 -1
  50. data/contrib/zstd/lib/compress/zstd_compress_superblock.c +49 -317
  51. data/contrib/zstd/lib/compress/zstd_compress_superblock.h +1 -1
  52. data/contrib/zstd/lib/compress/zstd_cwksp.h +320 -103
  53. data/contrib/zstd/lib/compress/zstd_double_fast.c +388 -151
  54. data/contrib/zstd/lib/compress/zstd_double_fast.h +3 -2
  55. data/contrib/zstd/lib/compress/zstd_fast.c +729 -265
  56. data/contrib/zstd/lib/compress/zstd_fast.h +3 -2
  57. data/contrib/zstd/lib/compress/zstd_lazy.c +1270 -251
  58. data/contrib/zstd/lib/compress/zstd_lazy.h +61 -1
  59. data/contrib/zstd/lib/compress/zstd_ldm.c +324 -219
  60. data/contrib/zstd/lib/compress/zstd_ldm.h +9 -2
  61. data/contrib/zstd/lib/compress/zstd_ldm_geartab.h +106 -0
  62. data/contrib/zstd/lib/compress/zstd_opt.c +481 -209
  63. data/contrib/zstd/lib/compress/zstd_opt.h +1 -1
  64. data/contrib/zstd/lib/compress/zstdmt_compress.c +181 -457
  65. data/contrib/zstd/lib/compress/zstdmt_compress.h +34 -113
  66. data/contrib/zstd/lib/decompress/huf_decompress.c +1199 -565
  67. data/contrib/zstd/lib/decompress/huf_decompress_amd64.S +576 -0
  68. data/contrib/zstd/lib/decompress/zstd_ddict.c +12 -12
  69. data/contrib/zstd/lib/decompress/zstd_ddict.h +2 -2
  70. data/contrib/zstd/lib/decompress/zstd_decompress.c +627 -157
  71. data/contrib/zstd/lib/decompress/zstd_decompress_block.c +1086 -326
  72. data/contrib/zstd/lib/decompress/zstd_decompress_block.h +19 -5
  73. data/contrib/zstd/lib/decompress/zstd_decompress_internal.h +62 -13
  74. data/contrib/zstd/lib/deprecated/zbuff.h +1 -1
  75. data/contrib/zstd/lib/deprecated/zbuff_common.c +1 -1
  76. data/contrib/zstd/lib/deprecated/zbuff_compress.c +24 -4
  77. data/contrib/zstd/lib/deprecated/zbuff_decompress.c +3 -1
  78. data/contrib/zstd/lib/dictBuilder/cover.c +73 -52
  79. data/contrib/zstd/lib/dictBuilder/cover.h +7 -6
  80. data/contrib/zstd/lib/dictBuilder/divsufsort.c +1 -1
  81. data/contrib/zstd/lib/dictBuilder/fastcover.c +44 -35
  82. data/contrib/zstd/lib/dictBuilder/zdict.c +103 -111
  83. data/contrib/zstd/lib/legacy/zstd_legacy.h +8 -1
  84. data/contrib/zstd/lib/legacy/zstd_v01.c +21 -54
  85. data/contrib/zstd/lib/legacy/zstd_v01.h +1 -1
  86. data/contrib/zstd/lib/legacy/zstd_v02.c +29 -70
  87. data/contrib/zstd/lib/legacy/zstd_v02.h +1 -1
  88. data/contrib/zstd/lib/legacy/zstd_v03.c +30 -73
  89. data/contrib/zstd/lib/legacy/zstd_v03.h +1 -1
  90. data/contrib/zstd/lib/legacy/zstd_v04.c +29 -71
  91. data/contrib/zstd/lib/legacy/zstd_v04.h +1 -1
  92. data/contrib/zstd/lib/legacy/zstd_v05.c +40 -86
  93. data/contrib/zstd/lib/legacy/zstd_v05.h +1 -1
  94. data/contrib/zstd/lib/legacy/zstd_v06.c +47 -88
  95. data/contrib/zstd/lib/legacy/zstd_v06.h +1 -1
  96. data/contrib/zstd/lib/legacy/zstd_v07.c +40 -83
  97. data/contrib/zstd/lib/legacy/zstd_v07.h +1 -1
  98. data/contrib/zstd/lib/libzstd.mk +214 -0
  99. data/contrib/zstd/lib/libzstd.pc.in +7 -6
  100. data/contrib/zstd/lib/module.modulemap +35 -0
  101. data/contrib/zstd/lib/{dictBuilder/zdict.h → zdict.h} +203 -34
  102. data/contrib/zstd/lib/zstd.h +1217 -287
  103. data/contrib/zstd/lib/{common/zstd_errors.h → zstd_errors.h} +28 -8
  104. data/ext/extconf.rb +7 -6
  105. data/ext/extzstd.c +19 -10
  106. data/ext/extzstd.h +6 -0
  107. data/ext/libzstd_conf.h +0 -1
  108. data/ext/zstd_decompress_asm.S +1 -0
  109. data/gemstub.rb +3 -21
  110. data/lib/extzstd/version.rb +6 -1
  111. data/lib/extzstd.rb +0 -2
  112. data/test/test_basic.rb +0 -5
  113. metadata +18 -6
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2016-2020, Yann Collet, Facebook, Inc.
2
+ * Copyright (c) Yann Collet, Meta Platforms, Inc. and affiliates.
3
3
  * All rights reserved.
4
4
  *
5
5
  * This source code is licensed under both the BSD-style license (found in the
@@ -23,7 +23,7 @@
23
23
  low-level memory access routines
24
24
  Copyright (C) 2013-2015, Yann Collet.
25
25
 
26
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
26
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
27
27
 
28
28
  Redistribution and use in source and binary forms, with or without
29
29
  modification, are permitted provided that the following conditions are
@@ -82,7 +82,11 @@ extern "C" {
82
82
  * Basic Types
83
83
  *****************************************************************/
84
84
  #if !defined (__VMS) && (defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) )
85
- # include <stdint.h>
85
+ # if defined(_AIX)
86
+ # include <inttypes.h>
87
+ # else
88
+ # include <stdint.h> /* intptr_t */
89
+ # endif
86
90
  typedef uint8_t BYTE;
87
91
  typedef uint16_t U16;
88
92
  typedef int16_t S16;
@@ -104,27 +108,6 @@ extern "C" {
104
108
  /*-**************************************************************
105
109
  * Memory I/O
106
110
  *****************************************************************/
107
- /* MEM_FORCE_MEMORY_ACCESS :
108
- * By default, access to unaligned memory is controlled by `memcpy()`, which is safe and portable.
109
- * Unfortunately, on some target/compiler combinations, the generated assembly is sub-optimal.
110
- * The below switch allow to select different access method for improved performance.
111
- * Method 0 (default) : use `memcpy()`. Safe and portable.
112
- * Method 1 : `__packed` statement. It depends on compiler extension (ie, not portable).
113
- * This method is safe if your compiler supports it, and *generally* as fast or faster than `memcpy`.
114
- * Method 2 : direct access. This method is portable but violate C standard.
115
- * It can generate buggy code on targets depending on alignment.
116
- * In some circumstances, it's the only known way to get the most performance (ie GCC + ARMv6)
117
- * See http://fastcompression.blogspot.fr/2015/08/accessing-unaligned-memory.html for details.
118
- * Prefer these methods in priority order (0 > 1 > 2)
119
- */
120
- #ifndef MEM_FORCE_MEMORY_ACCESS /* can be defined externally, on command line for example */
121
- # if defined(__GNUC__) && ( defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) )
122
- # define MEM_FORCE_MEMORY_ACCESS 2
123
- # elif (defined(__INTEL_COMPILER) && !defined(WIN32)) || \
124
- (defined(__GNUC__) && ( defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__) ))
125
- # define MEM_FORCE_MEMORY_ACCESS 1
126
- # endif
127
- #endif
128
111
 
129
112
  MEM_STATIC unsigned MEM_32bits(void) { return sizeof(size_t)==4; }
130
113
  MEM_STATIC unsigned MEM_64bits(void) { return sizeof(size_t)==8; }
@@ -135,33 +118,6 @@ MEM_STATIC unsigned MEM_isLittleEndian(void)
135
118
  return one.c[0];
136
119
  }
137
120
 
138
- #if defined(MEM_FORCE_MEMORY_ACCESS) && (MEM_FORCE_MEMORY_ACCESS==2)
139
-
140
- /* violates C standard, by lying on structure alignment.
141
- Only use if no other choice to achieve best performance on target platform */
142
- MEM_STATIC U16 MEM_read16(const void* memPtr) { return *(const U16*) memPtr; }
143
- MEM_STATIC U32 MEM_read32(const void* memPtr) { return *(const U32*) memPtr; }
144
- MEM_STATIC U64 MEM_read64(const void* memPtr) { return *(const U64*) memPtr; }
145
-
146
- MEM_STATIC void MEM_write16(void* memPtr, U16 value) { *(U16*)memPtr = value; }
147
-
148
- #elif defined(MEM_FORCE_MEMORY_ACCESS) && (MEM_FORCE_MEMORY_ACCESS==1)
149
-
150
- /* __pack instructions are safer, but compiler specific, hence potentially problematic for some compilers */
151
- /* currently only defined for gcc and icc */
152
- typedef union { U16 u16; U32 u32; U64 u64; size_t st; } __attribute__((packed)) unalign;
153
-
154
- MEM_STATIC U16 MEM_read16(const void* ptr) { return ((const unalign*)ptr)->u16; }
155
- MEM_STATIC U32 MEM_read32(const void* ptr) { return ((const unalign*)ptr)->u32; }
156
- MEM_STATIC U64 MEM_read64(const void* ptr) { return ((const unalign*)ptr)->u64; }
157
-
158
- MEM_STATIC void MEM_write16(void* memPtr, U16 value) { ((unalign*)memPtr)->u16 = value; }
159
-
160
- #else
161
-
162
- /* default method, safe and standard.
163
- can sometimes prove slower */
164
-
165
121
  MEM_STATIC U16 MEM_read16(const void* memPtr)
166
122
  {
167
123
  U16 val; memcpy(&val, memPtr, sizeof(val)); return val;
@@ -182,9 +138,6 @@ MEM_STATIC void MEM_write16(void* memPtr, U16 value)
182
138
  memcpy(memPtr, &value, sizeof(value));
183
139
  }
184
140
 
185
-
186
- #endif /* MEM_FORCE_MEMORY_ACCESS */
187
-
188
141
  MEM_STATIC U32 MEM_swap32(U32 in)
189
142
  {
190
143
  #if defined(_MSC_VER) /* Visual Studio */
@@ -280,7 +233,7 @@ MEM_STATIC size_t MEM_readLEST(const void* memPtr)
280
233
  Header File for static linking only
281
234
  Copyright (C) 2014-2016, Yann Collet.
282
235
 
283
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
236
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
284
237
 
285
238
  Redistribution and use in source and binary forms, with or without
286
239
  modification, are permitted provided that the following conditions are
@@ -304,7 +257,7 @@ MEM_STATIC size_t MEM_readLEST(const void* memPtr)
304
257
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
305
258
 
306
259
  You can contact the author at :
307
- - zstd homepage : http://www.zstd.net
260
+ - zstd homepage : https://facebook.github.io/zstd
308
261
  */
309
262
  #ifndef ZSTDv06_STATIC_H
310
263
  #define ZSTDv06_STATIC_H
@@ -411,7 +364,7 @@ ZSTDLIBv06_API size_t ZSTDv06_decompressBlock(ZSTDv06_DCtx* dctx, void* dst, siz
411
364
  Header File for include
412
365
  Copyright (C) 2014-2016, Yann Collet.
413
366
 
414
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
367
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
415
368
 
416
369
  Redistribution and use in source and binary forms, with or without
417
370
  modification, are permitted provided that the following conditions are
@@ -478,7 +431,7 @@ typedef enum { bt_compressed, bt_raw, bt_rle, bt_end } blockType_t;
478
431
  #define MIN_SEQUENCES_SIZE 1 /* nbSeq==0 */
479
432
  #define MIN_CBLOCK_SIZE (1 /*litCSize*/ + 1 /* RLE or RAW */ + MIN_SEQUENCES_SIZE /* nbSeq==0 */) /* for a non-null block */
480
433
 
481
- #define HufLog 12
434
+ #define ZSTD_HUFFDTABLE_CAPACITY_LOG 12
482
435
 
483
436
  #define IS_HUF 0
484
437
  #define IS_PCH 1
@@ -618,7 +571,7 @@ void ZSTDv06_seqToCodes(const seqStore_t* seqStorePtr, size_t const nbSeq);
618
571
  Public Prototypes declaration
619
572
  Copyright (C) 2013-2016, Yann Collet.
620
573
 
621
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
574
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
622
575
 
623
576
  Redistribution and use in source and binary forms, with or without
624
577
  modification, are permitted provided that the following conditions are
@@ -766,7 +719,7 @@ If there is an error, the function will return an error code, which can be teste
766
719
  header file (to include)
767
720
  Copyright (C) 2013-2016, Yann Collet.
768
721
 
769
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
722
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
770
723
 
771
724
  Redistribution and use in source and binary forms, with or without
772
725
  modification, are permitted provided that the following conditions are
@@ -856,9 +809,8 @@ MEM_STATIC size_t BITv06_readBitsFast(BITv06_DStream_t* bitD, unsigned nbBits);
856
809
  MEM_STATIC unsigned BITv06_highbit32 ( U32 val)
857
810
  {
858
811
  # if defined(_MSC_VER) /* Visual */
859
- unsigned long r=0;
860
- _BitScanReverse ( &r, val );
861
- return (unsigned) r;
812
+ unsigned long r;
813
+ return _BitScanReverse(&r, val) ? (unsigned)r : 0;
862
814
  # elif defined(__GNUC__) && (__GNUC__ >= 3) /* Use GCC Intrinsic */
863
815
  return __builtin_clz (val) ^ 31;
864
816
  # else /* Software version */
@@ -928,7 +880,7 @@ MEM_STATIC size_t BITv06_initDStream(BITv06_DStream_t* bitD, const void* srcBuff
928
880
  }
929
881
 
930
882
  /*! BITv06_lookBitsFast() :
931
- * unsafe version; only works only if nbBits >= 1 */
883
+ * unsafe version; only works if nbBits >= 1 */
932
884
  MEM_STATIC size_t BITv06_lookBitsFast(const BITv06_DStream_t* bitD, U32 nbBits)
933
885
  {
934
886
  U32 const bitMask = sizeof(bitD->bitContainer)*8 - 1;
@@ -948,7 +900,7 @@ MEM_STATIC size_t BITv06_readBits(BITv06_DStream_t* bitD, U32 nbBits)
948
900
  }
949
901
 
950
902
  /*! BITv06_readBitsFast() :
951
- * unsafe version; only works only if nbBits >= 1 */
903
+ * unsafe version; only works if nbBits >= 1 */
952
904
  MEM_STATIC size_t BITv06_readBitsFast(BITv06_DStream_t* bitD, U32 nbBits)
953
905
  {
954
906
  size_t const value = BITv06_lookBitsFast(bitD, nbBits);
@@ -1002,7 +954,7 @@ MEM_STATIC unsigned BITv06_endOfDStream(const BITv06_DStream_t* DStream)
1002
954
  header file for static linking (only)
1003
955
  Copyright (C) 2013-2015, Yann Collet
1004
956
 
1005
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
957
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
1006
958
 
1007
959
  Redistribution and use in source and binary forms, with or without
1008
960
  modification, are permitted provided that the following conditions are
@@ -1210,7 +1162,7 @@ MEM_STATIC BYTE FSEv06_decodeSymbolFast(FSEv06_DState_t* DStatePtr, BITv06_DStre
1210
1162
  Common functions of New Generation Entropy library
1211
1163
  Copyright (C) 2016, Yann Collet.
1212
1164
 
1213
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
1165
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
1214
1166
 
1215
1167
  Redistribution and use in source and binary forms, with or without
1216
1168
  modification, are permitted provided that the following conditions are
@@ -1355,7 +1307,7 @@ size_t FSEv06_readNCount (short* normalizedCounter, unsigned* maxSVPtr, unsigned
1355
1307
  FSE : Finite State Entropy decoder
1356
1308
  Copyright (C) 2013-2015, Yann Collet.
1357
1309
 
1358
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
1310
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
1359
1311
 
1360
1312
  Redistribution and use in source and binary forms, with or without
1361
1313
  modification, are permitted provided that the following conditions are
@@ -1679,7 +1631,7 @@ size_t FSEv06_decompress(void* dst, size_t maxDstSize, const void* cSrc, size_t
1679
1631
  header file
1680
1632
  Copyright (C) 2013-2016, Yann Collet.
1681
1633
 
1682
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
1634
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
1683
1635
 
1684
1636
  Redistribution and use in source and binary forms, with or without
1685
1637
  modification, are permitted provided that the following conditions are
@@ -1749,7 +1701,7 @@ size_t HUFv06_compressBound(size_t size); /**< maximum compressed size */
1749
1701
  header file, for static linking only
1750
1702
  Copyright (C) 2013-2016, Yann Collet
1751
1703
 
1752
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
1704
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
1753
1705
 
1754
1706
  Redistribution and use in source and binary forms, with or without
1755
1707
  modification, are permitted provided that the following conditions are
@@ -1931,7 +1883,7 @@ MEM_STATIC size_t HUFv06_readStats(BYTE* huffWeight, size_t hwSize, U32* rankSta
1931
1883
  Huffman decoder, part of New Generation Entropy library
1932
1884
  Copyright (C) 2013-2016, Yann Collet.
1933
1885
 
1934
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
1886
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
1935
1887
 
1936
1888
  Redistribution and use in source and binary forms, with or without
1937
1889
  modification, are permitted provided that the following conditions are
@@ -2676,7 +2628,7 @@ size_t HUFv06_decompress (void* dst, size_t dstSize, const void* cSrc, size_t cS
2676
2628
  Common functions of Zstd compression library
2677
2629
  Copyright (C) 2015-2016, Yann Collet.
2678
2630
 
2679
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
2631
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
2680
2632
 
2681
2633
  Redistribution and use in source and binary forms, with or without
2682
2634
  modification, are permitted provided that the following conditions are
@@ -2700,7 +2652,7 @@ size_t HUFv06_decompress (void* dst, size_t dstSize, const void* cSrc, size_t cS
2700
2652
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2701
2653
 
2702
2654
  You can contact the author at :
2703
- - zstd homepage : http://www.zstd.net/
2655
+ - zstd homepage : https://facebook.github.io/zstd/
2704
2656
  */
2705
2657
 
2706
2658
 
@@ -2730,7 +2682,7 @@ const char* ZBUFFv06_getErrorName(size_t errorCode) { return ERR_getErrorName(er
2730
2682
  zstd - standard compression library
2731
2683
  Copyright (C) 2014-2016, Yann Collet.
2732
2684
 
2733
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
2685
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
2734
2686
 
2735
2687
  Redistribution and use in source and binary forms, with or without
2736
2688
  modification, are permitted provided that the following conditions are
@@ -2754,7 +2706,7 @@ const char* ZBUFFv06_getErrorName(size_t errorCode) { return ERR_getErrorName(er
2754
2706
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2755
2707
 
2756
2708
  You can contact the author at :
2757
- - zstd homepage : http://www.zstd.net
2709
+ - zstd homepage : https://facebook.github.io/zstd
2758
2710
  */
2759
2711
 
2760
2712
  /* ***************************************************************
@@ -2806,7 +2758,7 @@ struct ZSTDv06_DCtx_s
2806
2758
  FSEv06_DTable LLTable[FSEv06_DTABLE_SIZE_U32(LLFSELog)];
2807
2759
  FSEv06_DTable OffTable[FSEv06_DTABLE_SIZE_U32(OffFSELog)];
2808
2760
  FSEv06_DTable MLTable[FSEv06_DTABLE_SIZE_U32(MLFSELog)];
2809
- unsigned hufTableX4[HUFv06_DTABLE_SIZE(HufLog)];
2761
+ unsigned hufTableX4[HUFv06_DTABLE_SIZE(ZSTD_HUFFDTABLE_CAPACITY_LOG)];
2810
2762
  const void* previousDstEnd;
2811
2763
  const void* base;
2812
2764
  const void* vBase;
@@ -2834,7 +2786,7 @@ size_t ZSTDv06_decompressBegin(ZSTDv06_DCtx* dctx)
2834
2786
  dctx->base = NULL;
2835
2787
  dctx->vBase = NULL;
2836
2788
  dctx->dictEnd = NULL;
2837
- dctx->hufTableX4[0] = HufLog;
2789
+ dctx->hufTableX4[0] = ZSTD_HUFFDTABLE_CAPACITY_LOG;
2838
2790
  dctx->flagRepeatTable = 0;
2839
2791
  return 0;
2840
2792
  }
@@ -3025,7 +2977,7 @@ typedef struct
3025
2977
  * Provides the size of compressed block from block header `src` */
3026
2978
  static size_t ZSTDv06_getcBlockSize(const void* src, size_t srcSize, blockProperties_t* bpPtr)
3027
2979
  {
3028
- const BYTE* const in = (const BYTE* const)src;
2980
+ const BYTE* const in = (const BYTE*)src;
3029
2981
  U32 cSize;
3030
2982
 
3031
2983
  if (srcSize < ZSTDv06_blockHeaderSize) return ERROR(srcSize_wrong);
@@ -3219,7 +3171,7 @@ static size_t ZSTDv06_decodeSeqHeaders(int* nbSeqPtr,
3219
3171
  FSEv06_DTable* DTableLL, FSEv06_DTable* DTableML, FSEv06_DTable* DTableOffb, U32 flagRepeatTable,
3220
3172
  const void* src, size_t srcSize)
3221
3173
  {
3222
- const BYTE* const istart = (const BYTE* const)src;
3174
+ const BYTE* const istart = (const BYTE*)src;
3223
3175
  const BYTE* const iend = istart + srcSize;
3224
3176
  const BYTE* ip = istart;
3225
3177
 
@@ -3370,13 +3322,19 @@ static size_t ZSTDv06_execSequence(BYTE* op,
3370
3322
  const BYTE* const iLitEnd = *litPtr + sequence.litLength;
3371
3323
  const BYTE* match = oLitEnd - sequence.offset;
3372
3324
 
3373
- /* check */
3374
- if (oLitEnd > oend_8) return ERROR(dstSize_tooSmall); /* last match must start at a minimum distance of 8 from oend */
3325
+ /* checks */
3326
+ size_t const seqLength = sequence.litLength + sequence.matchLength;
3327
+
3328
+ if (seqLength > (size_t)(oend - op)) return ERROR(dstSize_tooSmall);
3329
+ if (sequence.litLength > (size_t)(litLimit - *litPtr)) return ERROR(corruption_detected);
3330
+ /* Now we know there are no overflow in literal nor match lengths, can use pointer checks */
3331
+ if (oLitEnd > oend_8) return ERROR(dstSize_tooSmall);
3332
+
3375
3333
  if (oMatchEnd > oend) return ERROR(dstSize_tooSmall); /* overwrite beyond dst buffer */
3376
- if (iLitEnd > litLimit) return ERROR(corruption_detected); /* over-read beyond lit buffer */
3334
+ if (iLitEnd > litLimit) return ERROR(corruption_detected); /* overRead beyond lit buffer */
3377
3335
 
3378
3336
  /* copy Literals */
3379
- ZSTDv06_wildcopy(op, *litPtr, sequence.litLength); /* note : oLitEnd <= oend-8 : no risk of overwrite beyond oend */
3337
+ ZSTDv06_wildcopy(op, *litPtr, (ptrdiff_t)sequence.litLength); /* note : oLitEnd <= oend-8 : no risk of overwrite beyond oend */
3380
3338
  op = oLitEnd;
3381
3339
  *litPtr = iLitEnd; /* update for next sequence */
3382
3340
 
@@ -3441,7 +3399,7 @@ static size_t ZSTDv06_decompressSequences(
3441
3399
  {
3442
3400
  const BYTE* ip = (const BYTE*)seqStart;
3443
3401
  const BYTE* const iend = ip + seqSize;
3444
- BYTE* const ostart = (BYTE* const)dst;
3402
+ BYTE* const ostart = (BYTE*)dst;
3445
3403
  BYTE* const oend = ostart + maxDstSize;
3446
3404
  BYTE* op = ostart;
3447
3405
  const BYTE* litPtr = dctx->litPtr;
@@ -3557,7 +3515,7 @@ static size_t ZSTDv06_decompressFrame(ZSTDv06_DCtx* dctx,
3557
3515
  {
3558
3516
  const BYTE* ip = (const BYTE*)src;
3559
3517
  const BYTE* const iend = ip + srcSize;
3560
- BYTE* const ostart = (BYTE* const)dst;
3518
+ BYTE* const ostart = (BYTE*)dst;
3561
3519
  BYTE* op = ostart;
3562
3520
  BYTE* const oend = ostart + dstCapacity;
3563
3521
  size_t remainingSize = srcSize;
@@ -3889,7 +3847,7 @@ size_t ZSTDv06_decompressBegin_usingDict(ZSTDv06_DCtx* dctx, const void* dict, s
3889
3847
  Buffered version of Zstd compression library
3890
3848
  Copyright (C) 2015-2016, Yann Collet.
3891
3849
 
3892
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
3850
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
3893
3851
 
3894
3852
  Redistribution and use in source and binary forms, with or without
3895
3853
  modification, are permitted provided that the following conditions are
@@ -3913,7 +3871,7 @@ size_t ZSTDv06_decompressBegin_usingDict(ZSTDv06_DCtx* dctx, const void* dict, s
3913
3871
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3914
3872
 
3915
3873
  You can contact the author at :
3916
- - zstd homepage : http://www.zstd.net/
3874
+ - zstd homepage : https://facebook.github.io/zstd/
3917
3875
  */
3918
3876
 
3919
3877
 
@@ -4035,7 +3993,8 @@ size_t ZBUFFv06_decompressContinue(ZBUFFv06_DCtx* zbd,
4035
3993
  size_t const toLoad = hSize - zbd->lhSize; /* if hSize!=0, hSize > zbd->lhSize */
4036
3994
  if (ZSTDv06_isError(hSize)) return hSize;
4037
3995
  if (toLoad > (size_t)(iend-ip)) { /* not enough input to load full header */
4038
- memcpy(zbd->headerBuffer + zbd->lhSize, ip, iend-ip);
3996
+ if (ip != NULL)
3997
+ memcpy(zbd->headerBuffer + zbd->lhSize, ip, iend-ip);
4039
3998
  zbd->lhSize += iend-ip;
4040
3999
  *dstCapacityPtr = 0;
4041
4000
  return (hSize - zbd->lhSize) + ZSTDv06_blockHeaderSize; /* remaining header bytes + next block header */
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2016-2020, Yann Collet, Facebook, Inc.
2
+ * Copyright (c) Yann Collet, Meta Platforms, Inc. and affiliates.
3
3
  * All rights reserved.
4
4
  *
5
5
  * This source code is licensed under both the BSD-style license (found in the