extzstd 0.3.2 → 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 (108) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -3
  3. data/contrib/zstd/CHANGELOG +188 -1
  4. data/contrib/zstd/CONTRIBUTING.md +157 -74
  5. data/contrib/zstd/LICENSE +4 -4
  6. data/contrib/zstd/Makefile +81 -58
  7. data/contrib/zstd/Package.swift +36 -0
  8. data/contrib/zstd/README.md +59 -35
  9. data/contrib/zstd/TESTING.md +2 -3
  10. data/contrib/zstd/appveyor.yml +49 -136
  11. data/contrib/zstd/lib/BUCK +5 -7
  12. data/contrib/zstd/lib/Makefile +87 -181
  13. data/contrib/zstd/lib/README.md +23 -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 +33 -59
  17. data/contrib/zstd/lib/common/compiler.h +115 -45
  18. data/contrib/zstd/lib/common/cpu.h +1 -1
  19. data/contrib/zstd/lib/common/debug.c +1 -1
  20. data/contrib/zstd/lib/common/debug.h +1 -1
  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 +82 -3
  24. data/contrib/zstd/lib/common/fse.h +9 -85
  25. data/contrib/zstd/lib/common/fse_decompress.c +29 -111
  26. data/contrib/zstd/lib/common/huf.h +84 -172
  27. data/contrib/zstd/lib/common/mem.h +58 -49
  28. data/contrib/zstd/lib/common/pool.c +37 -16
  29. data/contrib/zstd/lib/common/pool.h +9 -3
  30. data/contrib/zstd/lib/common/portability_macros.h +156 -0
  31. data/contrib/zstd/lib/common/threading.c +68 -14
  32. data/contrib/zstd/lib/common/threading.h +5 -10
  33. data/contrib/zstd/lib/common/xxhash.c +7 -809
  34. data/contrib/zstd/lib/common/xxhash.h +5568 -167
  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 +64 -150
  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 +69 -150
  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 +773 -251
  44. data/contrib/zstd/lib/compress/zstd_compress.c +2650 -826
  45. data/contrib/zstd/lib/compress/zstd_compress_internal.h +509 -180
  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 +33 -305
  51. data/contrib/zstd/lib/compress/zstd_compress_superblock.h +1 -1
  52. data/contrib/zstd/lib/compress/zstd_cwksp.h +266 -85
  53. data/contrib/zstd/lib/compress/zstd_double_fast.c +369 -132
  54. data/contrib/zstd/lib/compress/zstd_double_fast.h +3 -2
  55. data/contrib/zstd/lib/compress/zstd_fast.c +722 -258
  56. data/contrib/zstd/lib/compress/zstd_fast.h +3 -2
  57. data/contrib/zstd/lib/compress/zstd_lazy.c +1105 -360
  58. data/contrib/zstd/lib/compress/zstd_lazy.h +41 -1
  59. data/contrib/zstd/lib/compress/zstd_ldm.c +272 -208
  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 +324 -197
  63. data/contrib/zstd/lib/compress/zstd_opt.h +1 -1
  64. data/contrib/zstd/lib/compress/zstdmt_compress.c +109 -53
  65. data/contrib/zstd/lib/compress/zstdmt_compress.h +9 -6
  66. data/contrib/zstd/lib/decompress/huf_decompress.c +1071 -539
  67. data/contrib/zstd/lib/decompress/huf_decompress_amd64.S +576 -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 +507 -82
  71. data/contrib/zstd/lib/decompress/zstd_decompress_block.c +962 -310
  72. data/contrib/zstd/lib/decompress/zstd_decompress_block.h +14 -3
  73. data/contrib/zstd/lib/decompress/zstd_decompress_internal.h +54 -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 +44 -32
  79. data/contrib/zstd/lib/dictBuilder/cover.h +6 -5
  80. data/contrib/zstd/lib/dictBuilder/divsufsort.c +1 -1
  81. data/contrib/zstd/lib/dictBuilder/fastcover.c +24 -16
  82. data/contrib/zstd/lib/dictBuilder/zdict.c +88 -95
  83. data/contrib/zstd/lib/legacy/zstd_legacy.h +8 -1
  84. data/contrib/zstd/lib/legacy/zstd_v01.c +16 -53
  85. data/contrib/zstd/lib/legacy/zstd_v01.h +1 -1
  86. data/contrib/zstd/lib/legacy/zstd_v02.c +24 -69
  87. data/contrib/zstd/lib/legacy/zstd_v02.h +1 -1
  88. data/contrib/zstd/lib/legacy/zstd_v03.c +25 -72
  89. data/contrib/zstd/lib/legacy/zstd_v03.h +1 -1
  90. data/contrib/zstd/lib/legacy/zstd_v04.c +23 -69
  91. data/contrib/zstd/lib/legacy/zstd_v04.h +1 -1
  92. data/contrib/zstd/lib/legacy/zstd_v05.c +35 -85
  93. data/contrib/zstd/lib/legacy/zstd_v05.h +1 -1
  94. data/contrib/zstd/lib/legacy/zstd_v06.c +42 -87
  95. data/contrib/zstd/lib/legacy/zstd_v06.h +1 -1
  96. data/contrib/zstd/lib/legacy/zstd_v07.c +35 -82
  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 +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 +922 -293
  103. data/contrib/zstd/lib/{common/zstd_errors.h → zstd_errors.h} +27 -8
  104. data/ext/extconf.rb +7 -6
  105. data/ext/extzstd.c +13 -10
  106. data/ext/libzstd_conf.h +0 -1
  107. data/ext/zstd_decompress_asm.S +1 -0
  108. metadata +16 -5
@@ -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
@@ -28,7 +28,7 @@
28
28
  low-level memory access routines
29
29
  Copyright (C) 2013-2015, Yann Collet.
30
30
 
31
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
31
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
32
32
 
33
33
  Redistribution and use in source and binary forms, with or without
34
34
  modification, are permitted provided that the following conditions are
@@ -115,27 +115,6 @@ extern "C" {
115
115
  /****************************************************************
116
116
  * Memory I/O
117
117
  *****************************************************************/
118
- /* MEM_FORCE_MEMORY_ACCESS
119
- * By default, access to unaligned memory is controlled by `memcpy()`, which is safe and portable.
120
- * Unfortunately, on some target/compiler combinations, the generated assembly is sub-optimal.
121
- * The below switch allow to select different access method for improved performance.
122
- * Method 0 (default) : use `memcpy()`. Safe and portable.
123
- * Method 1 : `__packed` statement. It depends on compiler extension (ie, not portable).
124
- * This method is safe if your compiler supports it, and *generally* as fast or faster than `memcpy`.
125
- * Method 2 : direct access. This method is portable but violate C standard.
126
- * It can generate buggy code on targets generating assembly depending on alignment.
127
- * But in some circumstances, it's the only known way to get the most performance (ie GCC + ARMv6)
128
- * See http://fastcompression.blogspot.fr/2015/08/accessing-unaligned-memory.html for details.
129
- * Prefer these methods in priority order (0 > 1 > 2)
130
- */
131
- #ifndef MEM_FORCE_MEMORY_ACCESS /* can be defined externally, on command line for example */
132
- # 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__) )
133
- # define MEM_FORCE_MEMORY_ACCESS 2
134
- # elif (defined(__INTEL_COMPILER) && !defined(WIN32)) || \
135
- (defined(__GNUC__) && ( defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__) ))
136
- # define MEM_FORCE_MEMORY_ACCESS 1
137
- # endif
138
- #endif
139
118
 
140
119
  MEM_STATIC unsigned MEM_32bits(void) { return sizeof(void*)==4; }
141
120
  MEM_STATIC unsigned MEM_64bits(void) { return sizeof(void*)==8; }
@@ -146,33 +125,6 @@ MEM_STATIC unsigned MEM_isLittleEndian(void)
146
125
  return one.c[0];
147
126
  }
148
127
 
149
- #if defined(MEM_FORCE_MEMORY_ACCESS) && (MEM_FORCE_MEMORY_ACCESS==2)
150
-
151
- /* violates C standard on structure alignment.
152
- Only use if no other choice to achieve best performance on target platform */
153
- MEM_STATIC U16 MEM_read16(const void* memPtr) { return *(const U16*) memPtr; }
154
- MEM_STATIC U32 MEM_read32(const void* memPtr) { return *(const U32*) memPtr; }
155
- MEM_STATIC U64 MEM_read64(const void* memPtr) { return *(const U64*) memPtr; }
156
-
157
- MEM_STATIC void MEM_write16(void* memPtr, U16 value) { *(U16*)memPtr = value; }
158
-
159
- #elif defined(MEM_FORCE_MEMORY_ACCESS) && (MEM_FORCE_MEMORY_ACCESS==1)
160
-
161
- /* __pack instructions are safer, but compiler specific, hence potentially problematic for some compilers */
162
- /* currently only defined for gcc and icc */
163
- typedef union { U16 u16; U32 u32; U64 u64; } __attribute__((packed)) unalign;
164
-
165
- MEM_STATIC U16 MEM_read16(const void* ptr) { return ((const unalign*)ptr)->u16; }
166
- MEM_STATIC U32 MEM_read32(const void* ptr) { return ((const unalign*)ptr)->u32; }
167
- MEM_STATIC U64 MEM_read64(const void* ptr) { return ((const unalign*)ptr)->u64; }
168
-
169
- MEM_STATIC void MEM_write16(void* memPtr, U16 value) { ((unalign*)memPtr)->u16 = value; }
170
-
171
- #else
172
-
173
- /* default method, safe and standard.
174
- can sometimes prove slower */
175
-
176
128
  MEM_STATIC U16 MEM_read16(const void* memPtr)
177
129
  {
178
130
  U16 val; memcpy(&val, memPtr, sizeof(val)); return val;
@@ -193,9 +145,6 @@ MEM_STATIC void MEM_write16(void* memPtr, U16 value)
193
145
  memcpy(memPtr, &value, sizeof(value));
194
146
  }
195
147
 
196
- #endif /* MEM_FORCE_MEMORY_ACCESS */
197
-
198
-
199
148
  MEM_STATIC U16 MEM_readLE16(const void* memPtr)
200
149
  {
201
150
  if (MEM_isLittleEndian())
@@ -272,7 +221,7 @@ MEM_STATIC size_t MEM_readLEST(const void* memPtr)
272
221
  header file (to include)
273
222
  Copyright (C) 2013-2015, Yann Collet.
274
223
 
275
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
224
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
276
225
 
277
226
  Redistribution and use in source and binary forms, with or without
278
227
  modification, are permitted provided that the following conditions are
@@ -353,9 +302,8 @@ MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, unsigned nbBits);
353
302
  MEM_STATIC unsigned BIT_highbit32 (U32 val)
354
303
  {
355
304
  # if defined(_MSC_VER) /* Visual */
356
- unsigned long r=0;
357
- _BitScanReverse ( &r, val );
358
- return (unsigned) r;
305
+ unsigned long r;
306
+ return _BitScanReverse(&r, val) ? (unsigned)r : 0;
359
307
  # elif defined(__GNUC__) && (__GNUC__ >= 3) /* Use GCC Intrinsic */
360
308
  return __builtin_clz (val) ^ 31;
361
309
  # else /* Software version */
@@ -437,7 +385,7 @@ MEM_STATIC size_t BIT_lookBits(BIT_DStream_t* bitD, U32 nbBits)
437
385
  }
438
386
 
439
387
  /*! BIT_lookBitsFast :
440
- * unsafe version; only works only if nbBits >= 1 */
388
+ * unsafe version; only works if nbBits >= 1 */
441
389
  MEM_STATIC size_t BIT_lookBitsFast(BIT_DStream_t* bitD, U32 nbBits)
442
390
  {
443
391
  const U32 bitMask = sizeof(bitD->bitContainer)*8 - 1;
@@ -457,7 +405,7 @@ MEM_STATIC size_t BIT_readBits(BIT_DStream_t* bitD, U32 nbBits)
457
405
  }
458
406
 
459
407
  /*!BIT_readBitsFast :
460
- * unsafe version; only works only if nbBits >= 1 */
408
+ * unsafe version; only works if nbBits >= 1 */
461
409
  MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, U32 nbBits)
462
410
  {
463
411
  size_t value = BIT_lookBitsFast(bitD, nbBits);
@@ -514,7 +462,7 @@ MEM_STATIC unsigned BIT_endOfDStream(const BIT_DStream_t* DStream)
514
462
  Error codes and messages
515
463
  Copyright (C) 2013-2015, Yann Collet
516
464
 
517
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
465
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
518
466
 
519
467
  Redistribution and use in source and binary forms, with or without
520
468
  modification, are permitted provided that the following conditions are
@@ -613,7 +561,7 @@ typedef unsigned FSE_DTable; /* don't allocate that. It's just a way to be mor
613
561
  header file for static linking (only)
614
562
  Copyright (C) 2013-2015, Yann Collet
615
563
 
616
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
564
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
617
565
 
618
566
  Redistribution and use in source and binary forms, with or without
619
567
  modification, are permitted provided that the following conditions are
@@ -757,7 +705,7 @@ MEM_STATIC unsigned FSE_endOfDState(const FSE_DState_t* DStatePtr)
757
705
  header file for static linking (only)
758
706
  Copyright (C) 2013-2015, Yann Collet
759
707
 
760
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
708
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
761
709
 
762
710
  Redistribution and use in source and binary forms, with or without
763
711
  modification, are permitted provided that the following conditions are
@@ -826,7 +774,7 @@ static size_t HUF_decompress4X6 (void* dst, size_t dstSize, const void* cSrc, si
826
774
  Header File
827
775
  Copyright (C) 2014-2015, Yann Collet.
828
776
 
829
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
777
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
830
778
 
831
779
  Redistribution and use in source and binary forms, with or without
832
780
  modification, are permitted provided that the following conditions are
@@ -886,7 +834,7 @@ typedef struct ZSTD_CCtx_s ZSTD_CCtx; /* incomplete type */
886
834
  Header File for static linking only
887
835
  Copyright (C) 2014-2015, Yann Collet.
888
836
 
889
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
837
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
890
838
 
891
839
  Redistribution and use in source and binary forms, with or without
892
840
  modification, are permitted provided that the following conditions are
@@ -950,7 +898,7 @@ typedef struct ZSTD_DCtx_s ZSTD_DCtx;
950
898
  FSE : Finite State Entropy coder
951
899
  Copyright (C) 2013-2015, Yann Collet.
952
900
 
953
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
901
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
954
902
 
955
903
  Redistribution and use in source and binary forms, with or without
956
904
  modification, are permitted provided that the following conditions are
@@ -1454,7 +1402,7 @@ static size_t FSE_decompress(void* dst, size_t maxDstSize, const void* cSrc, siz
1454
1402
  Huff0 : Huffman coder, part of New Generation Entropy library
1455
1403
  Copyright (C) 2013-2015, Yann Collet.
1456
1404
 
1457
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
1405
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
1458
1406
 
1459
1407
  Redistribution and use in source and binary forms, with or without
1460
1408
  modification, are permitted provided that the following conditions are
@@ -2613,7 +2561,7 @@ static size_t HUF_decompress (void* dst, size_t dstSize, const void* cSrc, size_
2613
2561
  zstd - standard compression library
2614
2562
  Copyright (C) 2014-2015, Yann Collet.
2615
2563
 
2616
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
2564
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
2617
2565
 
2618
2566
  Redistribution and use in source and binary forms, with or without
2619
2567
  modification, are permitted provided that the following conditions are
@@ -3118,12 +3066,19 @@ static size_t ZSTD_execSequence(BYTE* op,
3118
3066
  const BYTE* const litEnd = *litPtr + sequence.litLength;
3119
3067
 
3120
3068
  /* checks */
3121
- if (oLitEnd > oend_8) return ERROR(dstSize_tooSmall); /* last match must start at a minimum distance of 8 from oend */
3069
+ size_t const seqLength = sequence.litLength + sequence.matchLength;
3070
+
3071
+ if (seqLength > (size_t)(oend - op)) return ERROR(dstSize_tooSmall);
3072
+ if (sequence.litLength > (size_t)(litLimit - *litPtr)) return ERROR(corruption_detected);
3073
+ /* Now we know there are no overflow in literal nor match lengths, can use the pointer check */
3074
+ if (oLitEnd > oend_8) return ERROR(dstSize_tooSmall);
3075
+ if (sequence.offset > (U32)(oLitEnd - base)) return ERROR(corruption_detected);
3076
+
3122
3077
  if (oMatchEnd > oend) return ERROR(dstSize_tooSmall); /* overwrite beyond dst buffer */
3123
3078
  if (litEnd > litLimit) return ERROR(corruption_detected); /* overRead beyond lit buffer */
3124
3079
 
3125
3080
  /* copy Literals */
3126
- ZSTD_wildcopy(op, *litPtr, sequence.litLength); /* note : oLitEnd <= oend-8 : no risk of overwrite beyond oend */
3081
+ ZSTD_wildcopy(op, *litPtr, (ptrdiff_t)sequence.litLength); /* note : oLitEnd <= oend-8 : no risk of overwrite beyond oend */
3127
3082
  op = oLitEnd;
3128
3083
  *litPtr = litEnd; /* update for next sequence */
3129
3084
 
@@ -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
@@ -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
@@ -29,7 +29,7 @@
29
29
  low-level memory access routines
30
30
  Copyright (C) 2013-2015, Yann Collet.
31
31
 
32
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
32
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
33
33
 
34
34
  Redistribution and use in source and binary forms, with or without
35
35
  modification, are permitted provided that the following conditions are
@@ -116,27 +116,6 @@ extern "C" {
116
116
  /****************************************************************
117
117
  * Memory I/O
118
118
  *****************************************************************/
119
- /* MEM_FORCE_MEMORY_ACCESS
120
- * By default, access to unaligned memory is controlled by `memcpy()`, which is safe and portable.
121
- * Unfortunately, on some target/compiler combinations, the generated assembly is sub-optimal.
122
- * The below switch allow to select different access method for improved performance.
123
- * Method 0 (default) : use `memcpy()`. Safe and portable.
124
- * Method 1 : `__packed` statement. It depends on compiler extension (ie, not portable).
125
- * This method is safe if your compiler supports it, and *generally* as fast or faster than `memcpy`.
126
- * Method 2 : direct access. This method is portable but violate C standard.
127
- * It can generate buggy code on targets generating assembly depending on alignment.
128
- * But in some circumstances, it's the only known way to get the most performance (ie GCC + ARMv6)
129
- * See http://fastcompression.blogspot.fr/2015/08/accessing-unaligned-memory.html for details.
130
- * Prefer these methods in priority order (0 > 1 > 2)
131
- */
132
- #ifndef MEM_FORCE_MEMORY_ACCESS /* can be defined externally, on command line for example */
133
- # 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__) )
134
- # define MEM_FORCE_MEMORY_ACCESS 2
135
- # elif (defined(__INTEL_COMPILER) && !defined(WIN32)) || \
136
- (defined(__GNUC__) && ( defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__) ))
137
- # define MEM_FORCE_MEMORY_ACCESS 1
138
- # endif
139
- #endif
140
119
 
141
120
  MEM_STATIC unsigned MEM_32bits(void) { return sizeof(void*)==4; }
142
121
  MEM_STATIC unsigned MEM_64bits(void) { return sizeof(void*)==8; }
@@ -147,33 +126,6 @@ MEM_STATIC unsigned MEM_isLittleEndian(void)
147
126
  return one.c[0];
148
127
  }
149
128
 
150
- #if defined(MEM_FORCE_MEMORY_ACCESS) && (MEM_FORCE_MEMORY_ACCESS==2)
151
-
152
- /* violates C standard on structure alignment.
153
- Only use if no other choice to achieve best performance on target platform */
154
- MEM_STATIC U16 MEM_read16(const void* memPtr) { return *(const U16*) memPtr; }
155
- MEM_STATIC U32 MEM_read32(const void* memPtr) { return *(const U32*) memPtr; }
156
- MEM_STATIC U64 MEM_read64(const void* memPtr) { return *(const U64*) memPtr; }
157
-
158
- MEM_STATIC void MEM_write16(void* memPtr, U16 value) { *(U16*)memPtr = value; }
159
-
160
- #elif defined(MEM_FORCE_MEMORY_ACCESS) && (MEM_FORCE_MEMORY_ACCESS==1)
161
-
162
- /* __pack instructions are safer, but compiler specific, hence potentially problematic for some compilers */
163
- /* currently only defined for gcc and icc */
164
- typedef union { U16 u16; U32 u32; U64 u64; } __attribute__((packed)) unalign;
165
-
166
- MEM_STATIC U16 MEM_read16(const void* ptr) { return ((const unalign*)ptr)->u16; }
167
- MEM_STATIC U32 MEM_read32(const void* ptr) { return ((const unalign*)ptr)->u32; }
168
- MEM_STATIC U64 MEM_read64(const void* ptr) { return ((const unalign*)ptr)->u64; }
169
-
170
- MEM_STATIC void MEM_write16(void* memPtr, U16 value) { ((unalign*)memPtr)->u16 = value; }
171
-
172
- #else
173
-
174
- /* default method, safe and standard.
175
- can sometimes prove slower */
176
-
177
129
  MEM_STATIC U16 MEM_read16(const void* memPtr)
178
130
  {
179
131
  U16 val; memcpy(&val, memPtr, sizeof(val)); return val;
@@ -194,10 +146,6 @@ MEM_STATIC void MEM_write16(void* memPtr, U16 value)
194
146
  memcpy(memPtr, &value, sizeof(value));
195
147
  }
196
148
 
197
-
198
- #endif /* MEM_FORCE_MEMORY_ACCESS */
199
-
200
-
201
149
  MEM_STATIC U16 MEM_readLE16(const void* memPtr)
202
150
  {
203
151
  if (MEM_isLittleEndian())
@@ -274,7 +222,7 @@ MEM_STATIC size_t MEM_readLEST(const void* memPtr)
274
222
  header file (to include)
275
223
  Copyright (C) 2013-2015, Yann Collet.
276
224
 
277
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
225
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
278
226
 
279
227
  Redistribution and use in source and binary forms, with or without
280
228
  modification, are permitted provided that the following conditions are
@@ -356,9 +304,8 @@ MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, unsigned nbBits);
356
304
  MEM_STATIC unsigned BIT_highbit32 (U32 val)
357
305
  {
358
306
  # if defined(_MSC_VER) /* Visual */
359
- unsigned long r=0;
360
- _BitScanReverse ( &r, val );
361
- return (unsigned) r;
307
+ unsigned long r;
308
+ return _BitScanReverse(&r, val) ? (unsigned)r : 0;
362
309
  # elif defined(__GNUC__) && (__GNUC__ >= 3) /* Use GCC Intrinsic */
363
310
  return __builtin_clz (val) ^ 31;
364
311
  # else /* Software version */
@@ -439,7 +386,7 @@ MEM_STATIC size_t BIT_lookBits(BIT_DStream_t* bitD, U32 nbBits)
439
386
  }
440
387
 
441
388
  /*! BIT_lookBitsFast :
442
- * unsafe version; only works only if nbBits >= 1 */
389
+ * unsafe version; only works if nbBits >= 1 */
443
390
  MEM_STATIC size_t BIT_lookBitsFast(BIT_DStream_t* bitD, U32 nbBits)
444
391
  {
445
392
  const U32 bitMask = sizeof(bitD->bitContainer)*8 - 1;
@@ -459,7 +406,7 @@ MEM_STATIC size_t BIT_readBits(BIT_DStream_t* bitD, U32 nbBits)
459
406
  }
460
407
 
461
408
  /*!BIT_readBitsFast :
462
- * unsafe version; only works only if nbBits >= 1 */
409
+ * unsafe version; only works if nbBits >= 1 */
463
410
  MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, U32 nbBits)
464
411
  {
465
412
  size_t value = BIT_lookBitsFast(bitD, nbBits);
@@ -516,7 +463,7 @@ MEM_STATIC unsigned BIT_endOfDStream(const BIT_DStream_t* DStream)
516
463
  Error codes and messages
517
464
  Copyright (C) 2013-2015, Yann Collet
518
465
 
519
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
466
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
520
467
 
521
468
  Redistribution and use in source and binary forms, with or without
522
469
  modification, are permitted provided that the following conditions are
@@ -615,7 +562,7 @@ typedef unsigned FSE_DTable; /* don't allocate that. It's just a way to be mor
615
562
  header file for static linking (only)
616
563
  Copyright (C) 2013-2015, Yann Collet
617
564
 
618
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
565
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
619
566
 
620
567
  Redistribution and use in source and binary forms, with or without
621
568
  modification, are permitted provided that the following conditions are
@@ -759,7 +706,7 @@ MEM_STATIC unsigned FSE_endOfDState(const FSE_DState_t* DStatePtr)
759
706
  header file for static linking (only)
760
707
  Copyright (C) 2013-2015, Yann Collet
761
708
 
762
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
709
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
763
710
 
764
711
  Redistribution and use in source and binary forms, with or without
765
712
  modification, are permitted provided that the following conditions are
@@ -827,7 +774,7 @@ static size_t HUF_decompress4X4 (void* dst, size_t dstSize, const void* cSrc, si
827
774
  Header File
828
775
  Copyright (C) 2014-2015, Yann Collet.
829
776
 
830
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
777
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
831
778
 
832
779
  Redistribution and use in source and binary forms, with or without
833
780
  modification, are permitted provided that the following conditions are
@@ -887,7 +834,7 @@ typedef struct ZSTD_CCtx_s ZSTD_CCtx; /* incomplete type */
887
834
  Header File for static linking only
888
835
  Copyright (C) 2014-2015, Yann Collet.
889
836
 
890
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
837
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
891
838
 
892
839
  Redistribution and use in source and binary forms, with or without
893
840
  modification, are permitted provided that the following conditions are
@@ -951,7 +898,7 @@ typedef struct ZSTD_DCtx_s ZSTD_DCtx;
951
898
  FSE : Finite State Entropy coder
952
899
  Copyright (C) 2013-2015, Yann Collet.
953
900
 
954
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
901
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
955
902
 
956
903
  Redistribution and use in source and binary forms, with or without
957
904
  modification, are permitted provided that the following conditions are
@@ -1455,7 +1402,7 @@ static size_t FSE_decompress(void* dst, size_t maxDstSize, const void* cSrc, siz
1455
1402
  Huff0 : Huffman coder, part of New Generation Entropy library
1456
1403
  Copyright (C) 2013-2015, Yann Collet.
1457
1404
 
1458
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
1405
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
1459
1406
 
1460
1407
  Redistribution and use in source and binary forms, with or without
1461
1408
  modification, are permitted provided that the following conditions are
@@ -2252,7 +2199,7 @@ static size_t HUF_decompress (void* dst, size_t dstSize, const void* cSrc, size_
2252
2199
  zstd - standard compression library
2253
2200
  Copyright (C) 2014-2015, Yann Collet.
2254
2201
 
2255
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
2202
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
2256
2203
 
2257
2204
  Redistribution and use in source and binary forms, with or without
2258
2205
  modification, are permitted provided that the following conditions are
@@ -2759,18 +2706,24 @@ static size_t ZSTD_execSequence(BYTE* op,
2759
2706
  const BYTE* const litEnd = *litPtr + sequence.litLength;
2760
2707
 
2761
2708
  /* checks */
2762
- if (oLitEnd > oend_8) return ERROR(dstSize_tooSmall); /* last match must start at a minimum distance of 8 from oend */
2709
+ size_t const seqLength = sequence.litLength + sequence.matchLength;
2710
+
2711
+ if (seqLength > (size_t)(oend - op)) return ERROR(dstSize_tooSmall);
2712
+ if (sequence.litLength > (size_t)(litLimit - *litPtr)) return ERROR(corruption_detected);
2713
+ /* Now we know there are no overflow in literal nor match lengths, can use pointer checks */
2714
+ if (oLitEnd > oend_8) return ERROR(dstSize_tooSmall);
2715
+ if (sequence.offset > (U32)(oLitEnd - base)) return ERROR(corruption_detected);
2716
+
2763
2717
  if (oMatchEnd > oend) return ERROR(dstSize_tooSmall); /* overwrite beyond dst buffer */
2764
2718
  if (litEnd > litLimit) return ERROR(corruption_detected); /* overRead beyond lit buffer */
2765
2719
 
2766
2720
  /* copy Literals */
2767
- ZSTD_wildcopy(op, *litPtr, sequence.litLength); /* note : oLitEnd <= oend-8 : no risk of overwrite beyond oend */
2721
+ ZSTD_wildcopy(op, *litPtr, (ptrdiff_t)sequence.litLength); /* note : oLitEnd <= oend-8 : no risk of overwrite beyond oend */
2768
2722
  op = oLitEnd;
2769
2723
  *litPtr = litEnd; /* update for next sequence */
2770
2724
 
2771
2725
  /* copy Match */
2772
- {
2773
- const BYTE* match = op - sequence.offset;
2726
+ { const BYTE* match = op - sequence.offset;
2774
2727
 
2775
2728
  /* check */
2776
2729
  if (sequence.offset > (size_t)op) return ERROR(corruption_detected); /* address space overflow test (this test seems kept by clang optimizer) */
@@ -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
@@ -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
@@ -87,27 +87,6 @@ extern "C" {
87
87
  /****************************************************************
88
88
  * Memory I/O
89
89
  *****************************************************************/
90
- /* MEM_FORCE_MEMORY_ACCESS
91
- * By default, access to unaligned memory is controlled by `memcpy()`, which is safe and portable.
92
- * Unfortunately, on some target/compiler combinations, the generated assembly is sub-optimal.
93
- * The below switch allow to select different access method for improved performance.
94
- * Method 0 (default) : use `memcpy()`. Safe and portable.
95
- * Method 1 : `__packed` statement. It depends on compiler extension (ie, not portable).
96
- * This method is safe if your compiler supports it, and *generally* as fast or faster than `memcpy`.
97
- * Method 2 : direct access. This method is portable but violate C standard.
98
- * It can generate buggy code on targets generating assembly depending on alignment.
99
- * But in some circumstances, it's the only known way to get the most performance (ie GCC + ARMv6)
100
- * See http://fastcompression.blogspot.fr/2015/08/accessing-unaligned-memory.html for details.
101
- * Prefer these methods in priority order (0 > 1 > 2)
102
- */
103
- #ifndef MEM_FORCE_MEMORY_ACCESS /* can be defined externally, on command line for example */
104
- # 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__) )
105
- # define MEM_FORCE_MEMORY_ACCESS 2
106
- # elif (defined(__INTEL_COMPILER) && !defined(WIN32)) || \
107
- (defined(__GNUC__) && ( defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__) ))
108
- # define MEM_FORCE_MEMORY_ACCESS 1
109
- # endif
110
- #endif
111
90
 
112
91
  MEM_STATIC unsigned MEM_32bits(void) { return sizeof(void*)==4; }
113
92
  MEM_STATIC unsigned MEM_64bits(void) { return sizeof(void*)==8; }
@@ -118,33 +97,6 @@ MEM_STATIC unsigned MEM_isLittleEndian(void)
118
97
  return one.c[0];
119
98
  }
120
99
 
121
- #if defined(MEM_FORCE_MEMORY_ACCESS) && (MEM_FORCE_MEMORY_ACCESS==2)
122
-
123
- /* violates C standard on structure alignment.
124
- Only use if no other choice to achieve best performance on target platform */
125
- MEM_STATIC U16 MEM_read16(const void* memPtr) { return *(const U16*) memPtr; }
126
- MEM_STATIC U32 MEM_read32(const void* memPtr) { return *(const U32*) memPtr; }
127
- MEM_STATIC U64 MEM_read64(const void* memPtr) { return *(const U64*) memPtr; }
128
-
129
- MEM_STATIC void MEM_write16(void* memPtr, U16 value) { *(U16*)memPtr = value; }
130
-
131
- #elif defined(MEM_FORCE_MEMORY_ACCESS) && (MEM_FORCE_MEMORY_ACCESS==1)
132
-
133
- /* __pack instructions are safer, but compiler specific, hence potentially problematic for some compilers */
134
- /* currently only defined for gcc and icc */
135
- typedef union { U16 u16; U32 u32; U64 u64; } __attribute__((packed)) unalign;
136
-
137
- MEM_STATIC U16 MEM_read16(const void* ptr) { return ((const unalign*)ptr)->u16; }
138
- MEM_STATIC U32 MEM_read32(const void* ptr) { return ((const unalign*)ptr)->u32; }
139
- MEM_STATIC U64 MEM_read64(const void* ptr) { return ((const unalign*)ptr)->u64; }
140
-
141
- MEM_STATIC void MEM_write16(void* memPtr, U16 value) { ((unalign*)memPtr)->u16 = value; }
142
-
143
- #else
144
-
145
- /* default method, safe and standard.
146
- can sometimes prove slower */
147
-
148
100
  MEM_STATIC U16 MEM_read16(const void* memPtr)
149
101
  {
150
102
  U16 val; memcpy(&val, memPtr, sizeof(val)); return val;
@@ -165,9 +117,6 @@ MEM_STATIC void MEM_write16(void* memPtr, U16 value)
165
117
  memcpy(memPtr, &value, sizeof(value));
166
118
  }
167
119
 
168
- #endif /* MEM_FORCE_MEMORY_ACCESS */
169
-
170
-
171
120
  MEM_STATIC U16 MEM_readLE16(const void* memPtr)
172
121
  {
173
122
  if (MEM_isLittleEndian())
@@ -545,7 +494,7 @@ If there is an error, the function will return an error code, which can be teste
545
494
  header file (to include)
546
495
  Copyright (C) 2013-2015, Yann Collet.
547
496
 
548
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
497
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
549
498
 
550
499
  Redistribution and use in source and binary forms, with or without
551
500
  modification, are permitted provided that the following conditions are
@@ -627,9 +576,8 @@ MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, unsigned nbBits);
627
576
  MEM_STATIC unsigned BIT_highbit32 (U32 val)
628
577
  {
629
578
  # if defined(_MSC_VER) /* Visual */
630
- unsigned long r=0;
631
- _BitScanReverse ( &r, val );
632
- return (unsigned) r;
579
+ unsigned long r;
580
+ return _BitScanReverse(&r, val) ? (unsigned)r : 0;
633
581
  # elif defined(__GNUC__) && (__GNUC__ >= 3) /* Use GCC Intrinsic */
634
582
  return __builtin_clz (val) ^ 31;
635
583
  # else /* Software version */
@@ -704,7 +652,7 @@ MEM_STATIC size_t BIT_lookBits(BIT_DStream_t* bitD, U32 nbBits)
704
652
  }
705
653
 
706
654
  /*! BIT_lookBitsFast :
707
- * unsafe version; only works only if nbBits >= 1 */
655
+ * unsafe version; only works if nbBits >= 1 */
708
656
  MEM_STATIC size_t BIT_lookBitsFast(BIT_DStream_t* bitD, U32 nbBits)
709
657
  {
710
658
  const U32 bitMask = sizeof(bitD->bitContainer)*8 - 1;
@@ -724,7 +672,7 @@ MEM_STATIC size_t BIT_readBits(BIT_DStream_t* bitD, U32 nbBits)
724
672
  }
725
673
 
726
674
  /*!BIT_readBitsFast :
727
- * unsafe version; only works only if nbBits >= 1 */
675
+ * unsafe version; only works if nbBits >= 1 */
728
676
  MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, U32 nbBits)
729
677
  {
730
678
  size_t value = BIT_lookBitsFast(bitD, nbBits);
@@ -785,7 +733,7 @@ MEM_STATIC unsigned BIT_endOfDStream(const BIT_DStream_t* DStream)
785
733
  header file for static linking (only)
786
734
  Copyright (C) 2013-2015, Yann Collet
787
735
 
788
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
736
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
789
737
 
790
738
  Redistribution and use in source and binary forms, with or without
791
739
  modification, are permitted provided that the following conditions are
@@ -934,7 +882,7 @@ MEM_STATIC unsigned FSE_endOfDState(const FSE_DState_t* DStatePtr)
934
882
  FSE : Finite State Entropy coder
935
883
  Copyright (C) 2013-2015, Yann Collet.
936
884
 
937
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
885
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
938
886
 
939
887
  Redistribution and use in source and binary forms, with or without
940
888
  modification, are permitted provided that the following conditions are
@@ -1440,7 +1388,7 @@ static size_t FSE_decompress(void* dst, size_t maxDstSize, const void* cSrc, siz
1440
1388
  header file
1441
1389
  Copyright (C) 2013-2015, Yann Collet.
1442
1390
 
1443
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
1391
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
1444
1392
 
1445
1393
  Redistribution and use in source and binary forms, with or without
1446
1394
  modification, are permitted provided that the following conditions are
@@ -1518,7 +1466,7 @@ static unsigned HUF_isError(size_t code); /* tells if a return value i
1518
1466
  header file for static linking (only)
1519
1467
  Copyright (C) 2013-2015, Yann Collet
1520
1468
 
1521
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
1469
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
1522
1470
 
1523
1471
  Redistribution and use in source and binary forms, with or without
1524
1472
  modification, are permitted provided that the following conditions are
@@ -1605,7 +1553,7 @@ static size_t HUF_decompress4X4_usingDTable(void* dst, size_t maxDstSize, const
1605
1553
  Huff0 : Huffman coder, part of New Generation Entropy library
1606
1554
  Copyright (C) 2013-2015, Yann Collet.
1607
1555
 
1608
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
1556
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
1609
1557
 
1610
1558
  Redistribution and use in source and binary forms, with or without
1611
1559
  modification, are permitted provided that the following conditions are
@@ -2405,7 +2353,7 @@ static size_t HUF_decompress (void* dst, size_t dstSize, const void* cSrc, size_
2405
2353
  zstd - decompression module fo v0.4 legacy format
2406
2354
  Copyright (C) 2015-2016, Yann Collet.
2407
2355
 
2408
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
2356
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
2409
2357
 
2410
2358
  Redistribution and use in source and binary forms, with or without
2411
2359
  modification, are permitted provided that the following conditions are
@@ -2880,13 +2828,19 @@ static size_t ZSTD_execSequence(BYTE* op,
2880
2828
  const BYTE* const litEnd = *litPtr + sequence.litLength;
2881
2829
  const BYTE* match = oLitEnd - sequence.offset;
2882
2830
 
2883
- /* check */
2884
- if (oLitEnd > oend_8) return ERROR(dstSize_tooSmall); /* last match must start at a minimum distance of 8 from oend */
2831
+ /* checks */
2832
+ size_t const seqLength = sequence.litLength + sequence.matchLength;
2833
+
2834
+ if (seqLength > (size_t)(oend - op)) return ERROR(dstSize_tooSmall);
2835
+ if (sequence.litLength > (size_t)(litLimit - *litPtr)) return ERROR(corruption_detected);
2836
+ /* Now we know there are no overflow in literal nor match lengths, can use pointer checks */
2837
+ if (oLitEnd > oend_8) return ERROR(dstSize_tooSmall);
2838
+
2885
2839
  if (oMatchEnd > oend) return ERROR(dstSize_tooSmall); /* overwrite beyond dst buffer */
2886
- if (litEnd > litLimit) return ERROR(corruption_detected); /* risk read beyond lit buffer */
2840
+ if (litEnd > litLimit) return ERROR(corruption_detected); /* overRead beyond lit buffer */
2887
2841
 
2888
2842
  /* copy Literals */
2889
- ZSTD_wildcopy(op, *litPtr, sequence.litLength); /* note : oLitEnd <= oend-8 : no risk of overwrite beyond oend */
2843
+ ZSTD_wildcopy(op, *litPtr, (ptrdiff_t)sequence.litLength); /* note : oLitEnd <= oend-8 : no risk of overwrite beyond oend */
2890
2844
  op = oLitEnd;
2891
2845
  *litPtr = litEnd; /* update for next sequence */
2892
2846
 
@@ -3287,7 +3241,7 @@ static void ZSTD_decompress_insertDictionary(ZSTD_DCtx* ctx, const void* dict, s
3287
3241
  Buffered version of Zstd compression library
3288
3242
  Copyright (C) 2015, Yann Collet.
3289
3243
 
3290
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
3244
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
3291
3245
 
3292
3246
  Redistribution and use in source and binary forms, with or without
3293
3247
  modification, are permitted provided that the following conditions are
@@ -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