extzstd 0.3.2 → 0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -3
  3. data/contrib/zstd/CHANGELOG +225 -1
  4. data/contrib/zstd/CONTRIBUTING.md +158 -75
  5. data/contrib/zstd/LICENSE +4 -4
  6. data/contrib/zstd/Makefile +106 -69
  7. data/contrib/zstd/Package.swift +36 -0
  8. data/contrib/zstd/README.md +64 -36
  9. data/contrib/zstd/SECURITY.md +15 -0
  10. data/contrib/zstd/TESTING.md +2 -3
  11. data/contrib/zstd/lib/BUCK +5 -7
  12. data/contrib/zstd/lib/Makefile +117 -199
  13. data/contrib/zstd/lib/README.md +37 -7
  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 +80 -86
  17. data/contrib/zstd/lib/common/compiler.h +225 -63
  18. data/contrib/zstd/lib/common/cpu.h +37 -1
  19. data/contrib/zstd/lib/common/debug.c +7 -1
  20. data/contrib/zstd/lib/common/debug.h +21 -12
  21. data/contrib/zstd/lib/common/entropy_common.c +15 -37
  22. data/contrib/zstd/lib/common/error_private.c +9 -2
  23. data/contrib/zstd/lib/common/error_private.h +93 -5
  24. data/contrib/zstd/lib/common/fse.h +12 -87
  25. data/contrib/zstd/lib/common/fse_decompress.c +37 -117
  26. data/contrib/zstd/lib/common/huf.h +97 -172
  27. data/contrib/zstd/lib/common/mem.h +58 -58
  28. data/contrib/zstd/lib/common/pool.c +38 -17
  29. data/contrib/zstd/lib/common/pool.h +10 -4
  30. data/contrib/zstd/lib/common/portability_macros.h +158 -0
  31. data/contrib/zstd/lib/common/threading.c +74 -14
  32. data/contrib/zstd/lib/common/threading.h +5 -10
  33. data/contrib/zstd/lib/common/xxhash.c +6 -814
  34. data/contrib/zstd/lib/common/xxhash.h +6930 -195
  35. data/contrib/zstd/lib/common/zstd_common.c +1 -36
  36. data/contrib/zstd/lib/common/zstd_deps.h +1 -1
  37. data/contrib/zstd/lib/common/zstd_internal.h +68 -154
  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 +75 -155
  41. data/contrib/zstd/lib/compress/hist.c +1 -1
  42. data/contrib/zstd/lib/compress/hist.h +1 -1
  43. data/contrib/zstd/lib/compress/huf_compress.c +810 -259
  44. data/contrib/zstd/lib/compress/zstd_compress.c +2864 -919
  45. data/contrib/zstd/lib/compress/zstd_compress_internal.h +523 -192
  46. data/contrib/zstd/lib/compress/zstd_compress_literals.c +117 -40
  47. data/contrib/zstd/lib/compress/zstd_compress_literals.h +16 -6
  48. data/contrib/zstd/lib/compress/zstd_compress_sequences.c +28 -19
  49. data/contrib/zstd/lib/compress/zstd_compress_sequences.h +1 -1
  50. data/contrib/zstd/lib/compress/zstd_compress_superblock.c +251 -412
  51. data/contrib/zstd/lib/compress/zstd_compress_superblock.h +1 -1
  52. data/contrib/zstd/lib/compress/zstd_cwksp.h +284 -97
  53. data/contrib/zstd/lib/compress/zstd_double_fast.c +382 -133
  54. data/contrib/zstd/lib/compress/zstd_double_fast.h +14 -2
  55. data/contrib/zstd/lib/compress/zstd_fast.c +732 -260
  56. data/contrib/zstd/lib/compress/zstd_fast.h +3 -2
  57. data/contrib/zstd/lib/compress/zstd_lazy.c +1177 -390
  58. data/contrib/zstd/lib/compress/zstd_lazy.h +129 -14
  59. data/contrib/zstd/lib/compress/zstd_ldm.c +280 -210
  60. data/contrib/zstd/lib/compress/zstd_ldm.h +3 -2
  61. data/contrib/zstd/lib/compress/zstd_ldm_geartab.h +106 -0
  62. data/contrib/zstd/lib/compress/zstd_opt.c +516 -285
  63. data/contrib/zstd/lib/compress/zstd_opt.h +32 -8
  64. data/contrib/zstd/lib/compress/zstdmt_compress.c +202 -131
  65. data/contrib/zstd/lib/compress/zstdmt_compress.h +9 -6
  66. data/contrib/zstd/lib/decompress/huf_decompress.c +1149 -555
  67. data/contrib/zstd/lib/decompress/huf_decompress_amd64.S +595 -0
  68. data/contrib/zstd/lib/decompress/zstd_ddict.c +4 -4
  69. data/contrib/zstd/lib/decompress/zstd_ddict.h +1 -1
  70. data/contrib/zstd/lib/decompress/zstd_decompress.c +583 -106
  71. data/contrib/zstd/lib/decompress/zstd_decompress_block.c +1054 -379
  72. data/contrib/zstd/lib/decompress/zstd_decompress_block.h +14 -3
  73. data/contrib/zstd/lib/decompress/zstd_decompress_internal.h +56 -6
  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 +60 -44
  79. data/contrib/zstd/lib/dictBuilder/cover.h +6 -11
  80. data/contrib/zstd/lib/dictBuilder/divsufsort.c +1 -1
  81. data/contrib/zstd/lib/dictBuilder/fastcover.c +26 -18
  82. data/contrib/zstd/lib/dictBuilder/zdict.c +100 -101
  83. data/contrib/zstd/lib/legacy/zstd_legacy.h +38 -1
  84. data/contrib/zstd/lib/legacy/zstd_v01.c +18 -53
  85. data/contrib/zstd/lib/legacy/zstd_v01.h +1 -1
  86. data/contrib/zstd/lib/legacy/zstd_v02.c +28 -85
  87. data/contrib/zstd/lib/legacy/zstd_v02.h +1 -1
  88. data/contrib/zstd/lib/legacy/zstd_v03.c +29 -88
  89. data/contrib/zstd/lib/legacy/zstd_v03.h +1 -1
  90. data/contrib/zstd/lib/legacy/zstd_v04.c +27 -80
  91. data/contrib/zstd/lib/legacy/zstd_v04.h +1 -1
  92. data/contrib/zstd/lib/legacy/zstd_v05.c +36 -85
  93. data/contrib/zstd/lib/legacy/zstd_v05.h +1 -1
  94. data/contrib/zstd/lib/legacy/zstd_v06.c +44 -96
  95. data/contrib/zstd/lib/legacy/zstd_v06.h +1 -1
  96. data/contrib/zstd/lib/legacy/zstd_v07.c +37 -92
  97. data/contrib/zstd/lib/legacy/zstd_v07.h +1 -1
  98. data/contrib/zstd/lib/libzstd.mk +237 -0
  99. data/contrib/zstd/lib/libzstd.pc.in +4 -3
  100. data/contrib/zstd/lib/module.modulemap +35 -0
  101. data/contrib/zstd/lib/{dictBuilder/zdict.h → zdict.h} +202 -33
  102. data/contrib/zstd/lib/zstd.h +1030 -332
  103. data/contrib/zstd/lib/{common/zstd_errors.h → zstd_errors.h} +27 -8
  104. data/ext/extconf.rb +26 -7
  105. data/ext/extzstd.c +51 -24
  106. data/ext/extzstd.h +33 -6
  107. data/ext/extzstd_stream.c +74 -31
  108. data/ext/libzstd_conf.h +0 -1
  109. data/ext/zstd_decompress_asm.S +1 -0
  110. metadata +17 -7
  111. data/contrib/zstd/appveyor.yml +0 -292
  112. data/ext/depend +0 -2
@@ -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
@@ -14,6 +14,7 @@
14
14
  #include <stddef.h> /* size_t, ptrdiff_t */
15
15
  #include <string.h> /* memcpy */
16
16
  #include <stdlib.h> /* malloc, free, qsort */
17
+ #include "../common/compiler.h"
17
18
  #include "../common/error_private.h"
18
19
 
19
20
 
@@ -23,7 +24,7 @@
23
24
  low-level memory access routines
24
25
  Copyright (C) 2013-2015, Yann Collet.
25
26
 
26
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
27
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
27
28
 
28
29
  Redistribution and use in source and binary forms, with or without
29
30
  modification, are permitted provided that the following conditions are
@@ -67,15 +68,6 @@ extern "C" {
67
68
  # include <stdlib.h> /* _byteswap_ulong */
68
69
  # include <intrin.h> /* _byteswap_* */
69
70
  #endif
70
- #if defined(__GNUC__)
71
- # define MEM_STATIC static __attribute__((unused))
72
- #elif defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
73
- # define MEM_STATIC static inline
74
- #elif defined(_MSC_VER)
75
- # define MEM_STATIC static __inline
76
- #else
77
- # define MEM_STATIC static /* this version may generate warnings for unused static functions; disable the relevant warning */
78
- #endif
79
71
 
80
72
 
81
73
  /*-**************************************************************
@@ -108,27 +100,6 @@ extern "C" {
108
100
  /*-**************************************************************
109
101
  * Memory I/O
110
102
  *****************************************************************/
111
- /* MEM_FORCE_MEMORY_ACCESS :
112
- * By default, access to unaligned memory is controlled by `memcpy()`, which is safe and portable.
113
- * Unfortunately, on some target/compiler combinations, the generated assembly is sub-optimal.
114
- * The below switch allow to select different access method for improved performance.
115
- * Method 0 (default) : use `memcpy()`. Safe and portable.
116
- * Method 1 : `__packed` statement. It depends on compiler extension (ie, not portable).
117
- * This method is safe if your compiler supports it, and *generally* as fast or faster than `memcpy`.
118
- * Method 2 : direct access. This method is portable but violate C standard.
119
- * It can generate buggy code on targets depending on alignment.
120
- * In some circumstances, it's the only known way to get the most performance (ie GCC + ARMv6)
121
- * See http://fastcompression.blogspot.fr/2015/08/accessing-unaligned-memory.html for details.
122
- * Prefer these methods in priority order (0 > 1 > 2)
123
- */
124
- #ifndef MEM_FORCE_MEMORY_ACCESS /* can be defined externally, on command line for example */
125
- # 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__) )
126
- # define MEM_FORCE_MEMORY_ACCESS 2
127
- # elif (defined(__INTEL_COMPILER) && !defined(WIN32)) || \
128
- (defined(__GNUC__) && ( defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__) ))
129
- # define MEM_FORCE_MEMORY_ACCESS 1
130
- # endif
131
- #endif
132
103
 
133
104
  MEM_STATIC unsigned MEM_32bits(void) { return sizeof(size_t)==4; }
134
105
  MEM_STATIC unsigned MEM_64bits(void) { return sizeof(size_t)==8; }
@@ -139,33 +110,6 @@ MEM_STATIC unsigned MEM_isLittleEndian(void)
139
110
  return one.c[0];
140
111
  }
141
112
 
142
- #if defined(MEM_FORCE_MEMORY_ACCESS) && (MEM_FORCE_MEMORY_ACCESS==2)
143
-
144
- /* violates C standard, by lying on structure alignment.
145
- Only use if no other choice to achieve best performance on target platform */
146
- MEM_STATIC U16 MEM_read16(const void* memPtr) { return *(const U16*) memPtr; }
147
- MEM_STATIC U32 MEM_read32(const void* memPtr) { return *(const U32*) memPtr; }
148
- MEM_STATIC U64 MEM_read64(const void* memPtr) { return *(const U64*) memPtr; }
149
-
150
- MEM_STATIC void MEM_write16(void* memPtr, U16 value) { *(U16*)memPtr = value; }
151
-
152
- #elif defined(MEM_FORCE_MEMORY_ACCESS) && (MEM_FORCE_MEMORY_ACCESS==1)
153
-
154
- /* __pack instructions are safer, but compiler specific, hence potentially problematic for some compilers */
155
- /* currently only defined for gcc and icc */
156
- typedef union { U16 u16; U32 u32; U64 u64; size_t st; } __attribute__((packed)) unalign;
157
-
158
- MEM_STATIC U16 MEM_read16(const void* ptr) { return ((const unalign*)ptr)->u16; }
159
- MEM_STATIC U32 MEM_read32(const void* ptr) { return ((const unalign*)ptr)->u32; }
160
- MEM_STATIC U64 MEM_read64(const void* ptr) { return ((const unalign*)ptr)->u64; }
161
-
162
- MEM_STATIC void MEM_write16(void* memPtr, U16 value) { ((unalign*)memPtr)->u16 = value; }
163
-
164
- #else
165
-
166
- /* default method, safe and standard.
167
- can sometimes prove slower */
168
-
169
113
  MEM_STATIC U16 MEM_read16(const void* memPtr)
170
114
  {
171
115
  U16 val; memcpy(&val, memPtr, sizeof(val)); return val;
@@ -186,9 +130,6 @@ MEM_STATIC void MEM_write16(void* memPtr, U16 value)
186
130
  memcpy(memPtr, &value, sizeof(value));
187
131
  }
188
132
 
189
-
190
- #endif /* MEM_FORCE_MEMORY_ACCESS */
191
-
192
133
  MEM_STATIC U32 MEM_swap32(U32 in)
193
134
  {
194
135
  #if defined(_MSC_VER) /* Visual Studio */
@@ -284,7 +225,7 @@ MEM_STATIC size_t MEM_readLEST(const void* memPtr)
284
225
  Header File for static linking only
285
226
  Copyright (C) 2014-2016, Yann Collet.
286
227
 
287
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
228
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
288
229
 
289
230
  Redistribution and use in source and binary forms, with or without
290
231
  modification, are permitted provided that the following conditions are
@@ -308,7 +249,7 @@ MEM_STATIC size_t MEM_readLEST(const void* memPtr)
308
249
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
309
250
 
310
251
  You can contact the author at :
311
- - zstd homepage : http://www.zstd.net
252
+ - zstd homepage : https://facebook.github.io/zstd
312
253
  */
313
254
  #ifndef ZSTDv06_STATIC_H
314
255
  #define ZSTDv06_STATIC_H
@@ -415,7 +356,7 @@ ZSTDLIBv06_API size_t ZSTDv06_decompressBlock(ZSTDv06_DCtx* dctx, void* dst, siz
415
356
  Header File for include
416
357
  Copyright (C) 2014-2016, Yann Collet.
417
358
 
418
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
359
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
419
360
 
420
361
  Redistribution and use in source and binary forms, with or without
421
362
  modification, are permitted provided that the following conditions are
@@ -482,7 +423,7 @@ typedef enum { bt_compressed, bt_raw, bt_rle, bt_end } blockType_t;
482
423
  #define MIN_SEQUENCES_SIZE 1 /* nbSeq==0 */
483
424
  #define MIN_CBLOCK_SIZE (1 /*litCSize*/ + 1 /* RLE or RAW */ + MIN_SEQUENCES_SIZE /* nbSeq==0 */) /* for a non-null block */
484
425
 
485
- #define HufLog 12
426
+ #define ZSTD_HUFFDTABLE_CAPACITY_LOG 12
486
427
 
487
428
  #define IS_HUF 0
488
429
  #define IS_PCH 1
@@ -622,7 +563,7 @@ void ZSTDv06_seqToCodes(const seqStore_t* seqStorePtr, size_t const nbSeq);
622
563
  Public Prototypes declaration
623
564
  Copyright (C) 2013-2016, Yann Collet.
624
565
 
625
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
566
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
626
567
 
627
568
  Redistribution and use in source and binary forms, with or without
628
569
  modification, are permitted provided that the following conditions are
@@ -770,7 +711,7 @@ If there is an error, the function will return an error code, which can be teste
770
711
  header file (to include)
771
712
  Copyright (C) 2013-2016, Yann Collet.
772
713
 
773
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
714
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
774
715
 
775
716
  Redistribution and use in source and binary forms, with or without
776
717
  modification, are permitted provided that the following conditions are
@@ -860,9 +801,8 @@ MEM_STATIC size_t BITv06_readBitsFast(BITv06_DStream_t* bitD, unsigned nbBits);
860
801
  MEM_STATIC unsigned BITv06_highbit32 ( U32 val)
861
802
  {
862
803
  # if defined(_MSC_VER) /* Visual */
863
- unsigned long r=0;
864
- _BitScanReverse ( &r, val );
865
- return (unsigned) r;
804
+ unsigned long r;
805
+ return _BitScanReverse(&r, val) ? (unsigned)r : 0;
866
806
  # elif defined(__GNUC__) && (__GNUC__ >= 3) /* Use GCC Intrinsic */
867
807
  return __builtin_clz (val) ^ 31;
868
808
  # else /* Software version */
@@ -932,7 +872,7 @@ MEM_STATIC size_t BITv06_initDStream(BITv06_DStream_t* bitD, const void* srcBuff
932
872
  }
933
873
 
934
874
  /*! BITv06_lookBitsFast() :
935
- * unsafe version; only works only if nbBits >= 1 */
875
+ * unsafe version; only works if nbBits >= 1 */
936
876
  MEM_STATIC size_t BITv06_lookBitsFast(const BITv06_DStream_t* bitD, U32 nbBits)
937
877
  {
938
878
  U32 const bitMask = sizeof(bitD->bitContainer)*8 - 1;
@@ -952,7 +892,7 @@ MEM_STATIC size_t BITv06_readBits(BITv06_DStream_t* bitD, U32 nbBits)
952
892
  }
953
893
 
954
894
  /*! BITv06_readBitsFast() :
955
- * unsafe version; only works only if nbBits >= 1 */
895
+ * unsafe version; only works if nbBits >= 1 */
956
896
  MEM_STATIC size_t BITv06_readBitsFast(BITv06_DStream_t* bitD, U32 nbBits)
957
897
  {
958
898
  size_t const value = BITv06_lookBitsFast(bitD, nbBits);
@@ -1006,7 +946,7 @@ MEM_STATIC unsigned BITv06_endOfDStream(const BITv06_DStream_t* DStream)
1006
946
  header file for static linking (only)
1007
947
  Copyright (C) 2013-2015, Yann Collet
1008
948
 
1009
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
949
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
1010
950
 
1011
951
  Redistribution and use in source and binary forms, with or without
1012
952
  modification, are permitted provided that the following conditions are
@@ -1214,7 +1154,7 @@ MEM_STATIC BYTE FSEv06_decodeSymbolFast(FSEv06_DState_t* DStatePtr, BITv06_DStre
1214
1154
  Common functions of New Generation Entropy library
1215
1155
  Copyright (C) 2016, Yann Collet.
1216
1156
 
1217
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
1157
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
1218
1158
 
1219
1159
  Redistribution and use in source and binary forms, with or without
1220
1160
  modification, are permitted provided that the following conditions are
@@ -1359,7 +1299,7 @@ size_t FSEv06_readNCount (short* normalizedCounter, unsigned* maxSVPtr, unsigned
1359
1299
  FSE : Finite State Entropy decoder
1360
1300
  Copyright (C) 2013-2015, Yann Collet.
1361
1301
 
1362
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
1302
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
1363
1303
 
1364
1304
  Redistribution and use in source and binary forms, with or without
1365
1305
  modification, are permitted provided that the following conditions are
@@ -1683,7 +1623,7 @@ size_t FSEv06_decompress(void* dst, size_t maxDstSize, const void* cSrc, size_t
1683
1623
  header file
1684
1624
  Copyright (C) 2013-2016, Yann Collet.
1685
1625
 
1686
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
1626
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
1687
1627
 
1688
1628
  Redistribution and use in source and binary forms, with or without
1689
1629
  modification, are permitted provided that the following conditions are
@@ -1753,7 +1693,7 @@ size_t HUFv06_compressBound(size_t size); /**< maximum compressed size */
1753
1693
  header file, for static linking only
1754
1694
  Copyright (C) 2013-2016, Yann Collet
1755
1695
 
1756
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
1696
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
1757
1697
 
1758
1698
  Redistribution and use in source and binary forms, with or without
1759
1699
  modification, are permitted provided that the following conditions are
@@ -1935,7 +1875,7 @@ MEM_STATIC size_t HUFv06_readStats(BYTE* huffWeight, size_t hwSize, U32* rankSta
1935
1875
  Huffman decoder, part of New Generation Entropy library
1936
1876
  Copyright (C) 2013-2016, Yann Collet.
1937
1877
 
1938
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
1878
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
1939
1879
 
1940
1880
  Redistribution and use in source and binary forms, with or without
1941
1881
  modification, are permitted provided that the following conditions are
@@ -2680,7 +2620,7 @@ size_t HUFv06_decompress (void* dst, size_t dstSize, const void* cSrc, size_t cS
2680
2620
  Common functions of Zstd compression library
2681
2621
  Copyright (C) 2015-2016, Yann Collet.
2682
2622
 
2683
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
2623
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
2684
2624
 
2685
2625
  Redistribution and use in source and binary forms, with or without
2686
2626
  modification, are permitted provided that the following conditions are
@@ -2704,7 +2644,7 @@ size_t HUFv06_decompress (void* dst, size_t dstSize, const void* cSrc, size_t cS
2704
2644
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2705
2645
 
2706
2646
  You can contact the author at :
2707
- - zstd homepage : http://www.zstd.net/
2647
+ - zstd homepage : https://facebook.github.io/zstd/
2708
2648
  */
2709
2649
 
2710
2650
 
@@ -2734,7 +2674,7 @@ const char* ZBUFFv06_getErrorName(size_t errorCode) { return ERR_getErrorName(er
2734
2674
  zstd - standard compression library
2735
2675
  Copyright (C) 2014-2016, Yann Collet.
2736
2676
 
2737
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
2677
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
2738
2678
 
2739
2679
  Redistribution and use in source and binary forms, with or without
2740
2680
  modification, are permitted provided that the following conditions are
@@ -2758,7 +2698,7 @@ const char* ZBUFFv06_getErrorName(size_t errorCode) { return ERR_getErrorName(er
2758
2698
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2759
2699
 
2760
2700
  You can contact the author at :
2761
- - zstd homepage : http://www.zstd.net
2701
+ - zstd homepage : https://facebook.github.io/zstd
2762
2702
  */
2763
2703
 
2764
2704
  /* ***************************************************************
@@ -2810,7 +2750,7 @@ struct ZSTDv06_DCtx_s
2810
2750
  FSEv06_DTable LLTable[FSEv06_DTABLE_SIZE_U32(LLFSELog)];
2811
2751
  FSEv06_DTable OffTable[FSEv06_DTABLE_SIZE_U32(OffFSELog)];
2812
2752
  FSEv06_DTable MLTable[FSEv06_DTABLE_SIZE_U32(MLFSELog)];
2813
- unsigned hufTableX4[HUFv06_DTABLE_SIZE(HufLog)];
2753
+ unsigned hufTableX4[HUFv06_DTABLE_SIZE(ZSTD_HUFFDTABLE_CAPACITY_LOG)];
2814
2754
  const void* previousDstEnd;
2815
2755
  const void* base;
2816
2756
  const void* vBase;
@@ -2838,7 +2778,7 @@ size_t ZSTDv06_decompressBegin(ZSTDv06_DCtx* dctx)
2838
2778
  dctx->base = NULL;
2839
2779
  dctx->vBase = NULL;
2840
2780
  dctx->dictEnd = NULL;
2841
- dctx->hufTableX4[0] = HufLog;
2781
+ dctx->hufTableX4[0] = ZSTD_HUFFDTABLE_CAPACITY_LOG;
2842
2782
  dctx->flagRepeatTable = 0;
2843
2783
  return 0;
2844
2784
  }
@@ -3029,7 +2969,7 @@ typedef struct
3029
2969
  * Provides the size of compressed block from block header `src` */
3030
2970
  static size_t ZSTDv06_getcBlockSize(const void* src, size_t srcSize, blockProperties_t* bpPtr)
3031
2971
  {
3032
- const BYTE* const in = (const BYTE* const)src;
2972
+ const BYTE* const in = (const BYTE*)src;
3033
2973
  U32 cSize;
3034
2974
 
3035
2975
  if (srcSize < ZSTDv06_blockHeaderSize) return ERROR(srcSize_wrong);
@@ -3223,7 +3163,7 @@ static size_t ZSTDv06_decodeSeqHeaders(int* nbSeqPtr,
3223
3163
  FSEv06_DTable* DTableLL, FSEv06_DTable* DTableML, FSEv06_DTable* DTableOffb, U32 flagRepeatTable,
3224
3164
  const void* src, size_t srcSize)
3225
3165
  {
3226
- const BYTE* const istart = (const BYTE* const)src;
3166
+ const BYTE* const istart = (const BYTE*)src;
3227
3167
  const BYTE* const iend = istart + srcSize;
3228
3168
  const BYTE* ip = istart;
3229
3169
 
@@ -3374,13 +3314,19 @@ static size_t ZSTDv06_execSequence(BYTE* op,
3374
3314
  const BYTE* const iLitEnd = *litPtr + sequence.litLength;
3375
3315
  const BYTE* match = oLitEnd - sequence.offset;
3376
3316
 
3377
- /* check */
3378
- if (oLitEnd > oend_8) return ERROR(dstSize_tooSmall); /* last match must start at a minimum distance of 8 from oend */
3317
+ /* checks */
3318
+ size_t const seqLength = sequence.litLength + sequence.matchLength;
3319
+
3320
+ if (seqLength > (size_t)(oend - op)) return ERROR(dstSize_tooSmall);
3321
+ if (sequence.litLength > (size_t)(litLimit - *litPtr)) return ERROR(corruption_detected);
3322
+ /* Now we know there are no overflow in literal nor match lengths, can use pointer checks */
3323
+ if (oLitEnd > oend_8) return ERROR(dstSize_tooSmall);
3324
+
3379
3325
  if (oMatchEnd > oend) return ERROR(dstSize_tooSmall); /* overwrite beyond dst buffer */
3380
- if (iLitEnd > litLimit) return ERROR(corruption_detected); /* over-read beyond lit buffer */
3326
+ if (iLitEnd > litLimit) return ERROR(corruption_detected); /* overRead beyond lit buffer */
3381
3327
 
3382
3328
  /* copy Literals */
3383
- ZSTDv06_wildcopy(op, *litPtr, sequence.litLength); /* note : oLitEnd <= oend-8 : no risk of overwrite beyond oend */
3329
+ ZSTDv06_wildcopy(op, *litPtr, (ptrdiff_t)sequence.litLength); /* note : oLitEnd <= oend-8 : no risk of overwrite beyond oend */
3384
3330
  op = oLitEnd;
3385
3331
  *litPtr = iLitEnd; /* update for next sequence */
3386
3332
 
@@ -3445,7 +3391,7 @@ static size_t ZSTDv06_decompressSequences(
3445
3391
  {
3446
3392
  const BYTE* ip = (const BYTE*)seqStart;
3447
3393
  const BYTE* const iend = ip + seqSize;
3448
- BYTE* const ostart = (BYTE* const)dst;
3394
+ BYTE* const ostart = (BYTE*)dst;
3449
3395
  BYTE* const oend = ostart + maxDstSize;
3450
3396
  BYTE* op = ostart;
3451
3397
  const BYTE* litPtr = dctx->litPtr;
@@ -3561,7 +3507,7 @@ static size_t ZSTDv06_decompressFrame(ZSTDv06_DCtx* dctx,
3561
3507
  {
3562
3508
  const BYTE* ip = (const BYTE*)src;
3563
3509
  const BYTE* const iend = ip + srcSize;
3564
- BYTE* const ostart = (BYTE* const)dst;
3510
+ BYTE* const ostart = (BYTE*)dst;
3565
3511
  BYTE* op = ostart;
3566
3512
  BYTE* const oend = ostart + dstCapacity;
3567
3513
  size_t remainingSize = srcSize;
@@ -3791,6 +3737,7 @@ size_t ZSTDv06_decompressContinue(ZSTDv06_DCtx* dctx, void* dst, size_t dstCapac
3791
3737
  }
3792
3738
  dctx->stage = ZSTDds_decodeBlockHeader;
3793
3739
  dctx->expected = ZSTDv06_blockHeaderSize;
3740
+ if (ZSTDv06_isError(rSize)) return rSize;
3794
3741
  dctx->previousDstEnd = (char*)dst + rSize;
3795
3742
  return rSize;
3796
3743
  }
@@ -3893,7 +3840,7 @@ size_t ZSTDv06_decompressBegin_usingDict(ZSTDv06_DCtx* dctx, const void* dict, s
3893
3840
  Buffered version of Zstd compression library
3894
3841
  Copyright (C) 2015-2016, Yann Collet.
3895
3842
 
3896
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
3843
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
3897
3844
 
3898
3845
  Redistribution and use in source and binary forms, with or without
3899
3846
  modification, are permitted provided that the following conditions are
@@ -3917,7 +3864,7 @@ size_t ZSTDv06_decompressBegin_usingDict(ZSTDv06_DCtx* dctx, const void* dict, s
3917
3864
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3918
3865
 
3919
3866
  You can contact the author at :
3920
- - zstd homepage : http://www.zstd.net/
3867
+ - zstd homepage : https://facebook.github.io/zstd/
3921
3868
  */
3922
3869
 
3923
3870
 
@@ -4039,7 +3986,8 @@ size_t ZBUFFv06_decompressContinue(ZBUFFv06_DCtx* zbd,
4039
3986
  size_t const toLoad = hSize - zbd->lhSize; /* if hSize!=0, hSize > zbd->lhSize */
4040
3987
  if (ZSTDv06_isError(hSize)) return hSize;
4041
3988
  if (toLoad > (size_t)(iend-ip)) { /* not enough input to load full header */
4042
- memcpy(zbd->headerBuffer + zbd->lhSize, ip, iend-ip);
3989
+ if (ip != NULL)
3990
+ memcpy(zbd->headerBuffer + zbd->lhSize, ip, iend-ip);
4043
3991
  zbd->lhSize += iend-ip;
4044
3992
  *dstCapacityPtr = 0;
4045
3993
  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