multi_compress 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 (210) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +10 -3
  3. data/GET_STARTED.md +3 -3
  4. data/README.md +75 -66
  5. data/THIRD_PARTY_NOTICES.md +24 -0
  6. data/ext/multi_compress/brotli_dec_static_init.c +3 -0
  7. data/ext/multi_compress/brotli_enc_static_init.c +3 -0
  8. data/ext/multi_compress/extconf.rb +22 -1
  9. data/ext/multi_compress/vendor/.vendored +2 -2
  10. data/ext/multi_compress/vendor/brotli/LICENSE +19 -0
  11. data/ext/multi_compress/vendor/brotli/c/common/constants.c +7 -7
  12. data/ext/multi_compress/vendor/brotli/c/common/constants.h +2 -5
  13. data/ext/multi_compress/vendor/brotli/c/common/context.c +2 -2
  14. data/ext/multi_compress/vendor/brotli/c/common/context.h +1 -2
  15. data/ext/multi_compress/vendor/brotli/c/common/dictionary.c +4 -5856
  16. data/ext/multi_compress/vendor/brotli/c/common/dictionary.h +1 -2
  17. data/ext/multi_compress/vendor/brotli/c/common/dictionary_inc.h +5847 -0
  18. data/ext/multi_compress/vendor/brotli/c/common/platform.c +0 -4
  19. data/ext/multi_compress/vendor/brotli/c/common/platform.h +182 -43
  20. data/ext/multi_compress/vendor/brotli/c/common/shared_dictionary.c +3 -7
  21. data/ext/multi_compress/vendor/brotli/c/common/shared_dictionary_internal.h +1 -1
  22. data/ext/multi_compress/vendor/brotli/c/common/static_init.h +56 -0
  23. data/ext/multi_compress/vendor/brotli/c/common/transform.c +6 -4
  24. data/ext/multi_compress/vendor/brotli/c/common/transform.h +1 -2
  25. data/ext/multi_compress/vendor/brotli/c/common/version.h +3 -3
  26. data/ext/multi_compress/vendor/brotli/c/dec/bit_reader.c +2 -3
  27. data/ext/multi_compress/vendor/brotli/c/dec/bit_reader.h +0 -4
  28. data/ext/multi_compress/vendor/brotli/c/dec/decode.c +128 -39
  29. data/ext/multi_compress/vendor/brotli/c/dec/huffman.c +2 -5
  30. data/ext/multi_compress/vendor/brotli/c/dec/huffman.h +0 -2
  31. data/ext/multi_compress/vendor/brotli/c/dec/prefix.c +67 -0
  32. data/ext/multi_compress/vendor/brotli/c/dec/prefix.h +18 -708
  33. data/ext/multi_compress/vendor/brotli/c/dec/prefix_inc.h +707 -0
  34. data/ext/multi_compress/vendor/brotli/c/dec/state.c +18 -15
  35. data/ext/multi_compress/vendor/brotli/c/dec/state.h +2 -6
  36. data/ext/multi_compress/vendor/brotli/c/dec/static_init.c +53 -0
  37. data/ext/multi_compress/vendor/brotli/c/dec/static_init.h +30 -0
  38. data/ext/multi_compress/vendor/brotli/c/enc/backward_references.c +32 -8
  39. data/ext/multi_compress/vendor/brotli/c/enc/backward_references.h +1 -5
  40. data/ext/multi_compress/vendor/brotli/c/enc/backward_references_hq.c +15 -15
  41. data/ext/multi_compress/vendor/brotli/c/enc/backward_references_hq.h +1 -5
  42. data/ext/multi_compress/vendor/brotli/c/enc/bit_cost.c +28 -4
  43. data/ext/multi_compress/vendor/brotli/c/enc/bit_cost.h +8 -40
  44. data/ext/multi_compress/vendor/brotli/c/enc/bit_cost_inc.h +1 -1
  45. data/ext/multi_compress/vendor/brotli/c/enc/block_splitter.c +9 -12
  46. data/ext/multi_compress/vendor/brotli/c/enc/block_splitter.h +0 -3
  47. data/ext/multi_compress/vendor/brotli/c/enc/block_splitter_inc.h +14 -8
  48. data/ext/multi_compress/vendor/brotli/c/enc/brotli_bit_stream.c +10 -9
  49. data/ext/multi_compress/vendor/brotli/c/enc/brotli_bit_stream.h +0 -6
  50. data/ext/multi_compress/vendor/brotli/c/enc/cluster.c +0 -2
  51. data/ext/multi_compress/vendor/brotli/c/enc/cluster.h +0 -2
  52. data/ext/multi_compress/vendor/brotli/c/enc/command.c +1 -1
  53. data/ext/multi_compress/vendor/brotli/c/enc/command.h +8 -10
  54. data/ext/multi_compress/vendor/brotli/c/enc/compound_dictionary.c +3 -5
  55. data/ext/multi_compress/vendor/brotli/c/enc/compound_dictionary.h +1 -4
  56. data/ext/multi_compress/vendor/brotli/c/enc/compress_fragment.c +3 -13
  57. data/ext/multi_compress/vendor/brotli/c/enc/compress_fragment.h +0 -2
  58. data/ext/multi_compress/vendor/brotli/c/enc/compress_fragment_two_pass.c +5 -15
  59. data/ext/multi_compress/vendor/brotli/c/enc/compress_fragment_two_pass.h +0 -2
  60. data/ext/multi_compress/vendor/brotli/c/enc/dictionary_hash.c +127 -1830
  61. data/ext/multi_compress/vendor/brotli/c/enc/dictionary_hash.h +23 -3
  62. data/ext/multi_compress/vendor/brotli/c/enc/dictionary_hash_inc.h +1829 -0
  63. data/ext/multi_compress/vendor/brotli/c/enc/encode.c +77 -52
  64. data/ext/multi_compress/vendor/brotli/c/enc/encoder_dict.c +9 -7
  65. data/ext/multi_compress/vendor/brotli/c/enc/encoder_dict.h +2 -4
  66. data/ext/multi_compress/vendor/brotli/c/enc/entropy_encode.c +3 -6
  67. data/ext/multi_compress/vendor/brotli/c/enc/entropy_encode.h +2 -4
  68. data/ext/multi_compress/vendor/brotli/c/enc/entropy_encode_static.h +18 -12
  69. data/ext/multi_compress/vendor/brotli/c/enc/fast_log.c +1 -1
  70. data/ext/multi_compress/vendor/brotli/c/enc/fast_log.h +2 -3
  71. data/ext/multi_compress/vendor/brotli/c/enc/find_match_length.h +0 -2
  72. data/ext/multi_compress/vendor/brotli/c/enc/hash.h +38 -31
  73. data/ext/multi_compress/vendor/brotli/c/enc/hash_base.h +38 -0
  74. data/ext/multi_compress/vendor/brotli/c/enc/hash_forgetful_chain_inc.h +11 -1
  75. data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match64_inc.h +24 -7
  76. data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match64_simd_inc.h +304 -0
  77. data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match_inc.h +30 -11
  78. data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match_quickly_inc.h +4 -0
  79. data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match_simd_inc.h +278 -0
  80. data/ext/multi_compress/vendor/brotli/c/enc/histogram.c +1 -0
  81. data/ext/multi_compress/vendor/brotli/c/enc/histogram.h +0 -4
  82. data/ext/multi_compress/vendor/brotli/c/enc/literal_cost.c +4 -6
  83. data/ext/multi_compress/vendor/brotli/c/enc/literal_cost.h +0 -2
  84. data/ext/multi_compress/vendor/brotli/c/enc/matching_tag_mask.h +69 -0
  85. data/ext/multi_compress/vendor/brotli/c/enc/memory.c +0 -5
  86. data/ext/multi_compress/vendor/brotli/c/enc/memory.h +0 -4
  87. data/ext/multi_compress/vendor/brotli/c/enc/metablock.c +7 -9
  88. data/ext/multi_compress/vendor/brotli/c/enc/metablock.h +3 -3
  89. data/ext/multi_compress/vendor/brotli/c/enc/metablock_inc.h +4 -4
  90. data/ext/multi_compress/vendor/brotli/c/enc/params.h +0 -1
  91. data/ext/multi_compress/vendor/brotli/c/enc/prefix.h +0 -2
  92. data/ext/multi_compress/vendor/brotli/c/enc/quality.h +17 -10
  93. data/ext/multi_compress/vendor/brotli/c/enc/ringbuffer.h +1 -4
  94. data/ext/multi_compress/vendor/brotli/c/enc/state.h +2 -2
  95. data/ext/multi_compress/vendor/brotli/c/enc/static_dict.c +5 -11
  96. data/ext/multi_compress/vendor/brotli/c/enc/static_dict.h +1 -3
  97. data/ext/multi_compress/vendor/brotli/c/enc/static_dict_lut.c +224 -0
  98. data/ext/multi_compress/vendor/brotli/c/enc/static_dict_lut.h +20 -5837
  99. data/ext/multi_compress/vendor/brotli/c/enc/static_dict_lut_inc.h +5830 -0
  100. data/ext/multi_compress/vendor/brotli/c/enc/static_init.c +59 -0
  101. data/ext/multi_compress/vendor/brotli/c/enc/static_init.h +30 -0
  102. data/ext/multi_compress/vendor/brotli/c/enc/static_init_lazy.cc +26 -0
  103. data/ext/multi_compress/vendor/brotli/c/enc/utf8_util.c +1 -1
  104. data/ext/multi_compress/vendor/brotli/c/enc/utf8_util.h +0 -2
  105. data/ext/multi_compress/vendor/brotli/c/enc/write_bits.h +0 -2
  106. data/ext/multi_compress/vendor/brotli/c/include/brotli/decode.h +1 -1
  107. data/ext/multi_compress/vendor/brotli/c/include/brotli/encode.h +5 -1
  108. data/ext/multi_compress/vendor/brotli/c/include/brotli/port.h +4 -7
  109. data/ext/multi_compress/vendor/brotli/c/include/brotli/types.h +2 -2
  110. data/ext/multi_compress/vendor/lz4/LICENSE +12 -0
  111. data/ext/multi_compress/vendor/zstd/COPYING +339 -0
  112. data/ext/multi_compress/vendor/zstd/LICENSE +30 -0
  113. data/ext/multi_compress/vendor/zstd/lib/Makefile +67 -35
  114. data/ext/multi_compress/vendor/zstd/lib/README.md +33 -2
  115. data/ext/multi_compress/vendor/zstd/lib/common/allocations.h +55 -0
  116. data/ext/multi_compress/vendor/zstd/lib/common/bits.h +205 -0
  117. data/ext/multi_compress/vendor/zstd/lib/common/bitstream.h +84 -108
  118. data/ext/multi_compress/vendor/zstd/lib/common/compiler.h +170 -41
  119. data/ext/multi_compress/vendor/zstd/lib/common/cpu.h +37 -1
  120. data/ext/multi_compress/vendor/zstd/lib/common/debug.c +7 -1
  121. data/ext/multi_compress/vendor/zstd/lib/common/debug.h +21 -21
  122. data/ext/multi_compress/vendor/zstd/lib/common/entropy_common.c +12 -40
  123. data/ext/multi_compress/vendor/zstd/lib/common/error_private.c +10 -2
  124. data/ext/multi_compress/vendor/zstd/lib/common/error_private.h +46 -47
  125. data/ext/multi_compress/vendor/zstd/lib/common/fse.h +8 -100
  126. data/ext/multi_compress/vendor/zstd/lib/common/fse_decompress.c +28 -116
  127. data/ext/multi_compress/vendor/zstd/lib/common/huf.h +79 -166
  128. data/ext/multi_compress/vendor/zstd/lib/common/mem.h +46 -66
  129. data/ext/multi_compress/vendor/zstd/lib/common/pool.c +27 -11
  130. data/ext/multi_compress/vendor/zstd/lib/common/pool.h +8 -11
  131. data/ext/multi_compress/vendor/zstd/lib/common/portability_macros.h +45 -11
  132. data/ext/multi_compress/vendor/zstd/lib/common/threading.c +74 -14
  133. data/ext/multi_compress/vendor/zstd/lib/common/threading.h +5 -18
  134. data/ext/multi_compress/vendor/zstd/lib/common/xxhash.c +5 -11
  135. data/ext/multi_compress/vendor/zstd/lib/common/xxhash.h +2411 -1003
  136. data/ext/multi_compress/vendor/zstd/lib/common/zstd_common.c +1 -36
  137. data/ext/multi_compress/vendor/zstd/lib/common/zstd_deps.h +13 -1
  138. data/ext/multi_compress/vendor/zstd/lib/common/zstd_internal.h +13 -182
  139. data/ext/multi_compress/vendor/zstd/lib/common/zstd_trace.h +6 -13
  140. data/ext/multi_compress/vendor/zstd/lib/compress/clevels.h +1 -1
  141. data/ext/multi_compress/vendor/zstd/lib/compress/fse_compress.c +15 -131
  142. data/ext/multi_compress/vendor/zstd/lib/compress/hist.c +11 -1
  143. data/ext/multi_compress/vendor/zstd/lib/compress/hist.h +8 -1
  144. data/ext/multi_compress/vendor/zstd/lib/compress/huf_compress.c +283 -189
  145. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress.c +2419 -903
  146. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_internal.h +423 -245
  147. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_literals.c +116 -40
  148. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_literals.h +16 -8
  149. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_sequences.c +10 -10
  150. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_sequences.h +8 -7
  151. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_superblock.c +254 -139
  152. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_superblock.h +1 -1
  153. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_cwksp.h +184 -95
  154. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_double_fast.c +163 -81
  155. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_double_fast.h +18 -14
  156. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_fast.c +507 -197
  157. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_fast.h +7 -14
  158. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_lazy.c +579 -484
  159. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_lazy.h +133 -65
  160. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_ldm.c +61 -40
  161. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_ldm.h +7 -15
  162. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_ldm_geartab.h +1 -1
  163. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_opt.c +352 -218
  164. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_opt.h +37 -21
  165. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_preSplit.c +238 -0
  166. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_preSplit.h +33 -0
  167. data/ext/multi_compress/vendor/zstd/lib/compress/zstdmt_compress.c +239 -175
  168. data/ext/multi_compress/vendor/zstd/lib/compress/zstdmt_compress.h +5 -16
  169. data/ext/multi_compress/vendor/zstd/lib/decompress/huf_decompress.c +543 -488
  170. data/ext/multi_compress/vendor/zstd/lib/decompress/huf_decompress_amd64.S +78 -61
  171. data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_ddict.c +4 -4
  172. data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_ddict.h +1 -1
  173. data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress.c +295 -115
  174. data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress_block.c +430 -293
  175. data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress_block.h +7 -2
  176. data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress_internal.h +11 -7
  177. data/ext/multi_compress/vendor/zstd/lib/deprecated/zbuff.h +1 -1
  178. data/ext/multi_compress/vendor/zstd/lib/deprecated/zbuff_common.c +1 -1
  179. data/ext/multi_compress/vendor/zstd/lib/deprecated/zbuff_compress.c +1 -1
  180. data/ext/multi_compress/vendor/zstd/lib/deprecated/zbuff_decompress.c +3 -1
  181. data/ext/multi_compress/vendor/zstd/lib/dictBuilder/cover.c +95 -46
  182. data/ext/multi_compress/vendor/zstd/lib/dictBuilder/cover.h +3 -9
  183. data/ext/multi_compress/vendor/zstd/lib/dictBuilder/divsufsort.h +0 -10
  184. data/ext/multi_compress/vendor/zstd/lib/dictBuilder/fastcover.c +4 -4
  185. data/ext/multi_compress/vendor/zstd/lib/dictBuilder/zdict.c +25 -97
  186. data/ext/multi_compress/vendor/zstd/lib/dll/example/Makefile +1 -1
  187. data/ext/multi_compress/vendor/zstd/lib/dll/example/README.md +1 -1
  188. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_legacy.h +38 -1
  189. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v01.c +19 -50
  190. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v01.h +1 -1
  191. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v02.c +27 -80
  192. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v02.h +1 -1
  193. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v03.c +28 -83
  194. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v03.h +1 -1
  195. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v04.c +25 -74
  196. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v04.h +1 -1
  197. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v05.c +31 -76
  198. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v05.h +1 -1
  199. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v06.c +44 -88
  200. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v06.h +1 -1
  201. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v07.c +33 -84
  202. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v07.h +1 -1
  203. data/ext/multi_compress/vendor/zstd/lib/libzstd.mk +65 -33
  204. data/ext/multi_compress/vendor/zstd/lib/libzstd.pc.in +5 -5
  205. data/ext/multi_compress/vendor/zstd/lib/module.modulemap +13 -3
  206. data/ext/multi_compress/vendor/zstd/lib/zdict.h +65 -36
  207. data/ext/multi_compress/vendor/zstd/lib/zstd.h +890 -267
  208. data/ext/multi_compress/vendor/zstd/lib/zstd_errors.h +28 -16
  209. data/lib/multi_compress/version.rb +1 -1
  210. metadata +29 -2
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 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,24 +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(__INTEL_COMPILER) || defined(__GNUC__) || defined(__ICCARM__)
126
- # define MEM_FORCE_MEMORY_ACCESS 1
127
- # endif
128
- #endif
129
103
 
130
104
  MEM_STATIC unsigned MEM_32bits(void) { return sizeof(size_t)==4; }
131
105
  MEM_STATIC unsigned MEM_64bits(void) { return sizeof(size_t)==8; }
@@ -136,33 +110,6 @@ MEM_STATIC unsigned MEM_isLittleEndian(void)
136
110
  return one.c[0];
137
111
  }
138
112
 
139
- #if defined(MEM_FORCE_MEMORY_ACCESS) && (MEM_FORCE_MEMORY_ACCESS==2)
140
-
141
- /* violates C standard, by lying on structure alignment.
142
- Only use if no other choice to achieve best performance on target platform */
143
- MEM_STATIC U16 MEM_read16(const void* memPtr) { return *(const U16*) memPtr; }
144
- MEM_STATIC U32 MEM_read32(const void* memPtr) { return *(const U32*) memPtr; }
145
- MEM_STATIC U64 MEM_read64(const void* memPtr) { return *(const U64*) memPtr; }
146
-
147
- MEM_STATIC void MEM_write16(void* memPtr, U16 value) { *(U16*)memPtr = value; }
148
-
149
- #elif defined(MEM_FORCE_MEMORY_ACCESS) && (MEM_FORCE_MEMORY_ACCESS==1)
150
-
151
- /* __pack instructions are safer, but compiler specific, hence potentially problematic for some compilers */
152
- /* currently only defined for gcc and icc */
153
- typedef union { U16 u16; U32 u32; U64 u64; size_t st; } __attribute__((packed)) unalign;
154
-
155
- MEM_STATIC U16 MEM_read16(const void* ptr) { return ((const unalign*)ptr)->u16; }
156
- MEM_STATIC U32 MEM_read32(const void* ptr) { return ((const unalign*)ptr)->u32; }
157
- MEM_STATIC U64 MEM_read64(const void* ptr) { return ((const unalign*)ptr)->u64; }
158
-
159
- MEM_STATIC void MEM_write16(void* memPtr, U16 value) { ((unalign*)memPtr)->u16 = value; }
160
-
161
- #else
162
-
163
- /* default method, safe and standard.
164
- can sometimes prove slower */
165
-
166
113
  MEM_STATIC U16 MEM_read16(const void* memPtr)
167
114
  {
168
115
  U16 val; memcpy(&val, memPtr, sizeof(val)); return val;
@@ -183,9 +130,6 @@ MEM_STATIC void MEM_write16(void* memPtr, U16 value)
183
130
  memcpy(memPtr, &value, sizeof(value));
184
131
  }
185
132
 
186
-
187
- #endif /* MEM_FORCE_MEMORY_ACCESS */
188
-
189
133
  MEM_STATIC U32 MEM_swap32(U32 in)
190
134
  {
191
135
  #if defined(_MSC_VER) /* Visual Studio */
@@ -281,7 +225,7 @@ MEM_STATIC size_t MEM_readLEST(const void* memPtr)
281
225
  Header File for static linking only
282
226
  Copyright (C) 2014-2016, Yann Collet.
283
227
 
284
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
228
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
285
229
 
286
230
  Redistribution and use in source and binary forms, with or without
287
231
  modification, are permitted provided that the following conditions are
@@ -305,7 +249,7 @@ MEM_STATIC size_t MEM_readLEST(const void* memPtr)
305
249
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
306
250
 
307
251
  You can contact the author at :
308
- - zstd homepage : http://www.zstd.net
252
+ - zstd homepage : https://facebook.github.io/zstd
309
253
  */
310
254
  #ifndef ZSTDv06_STATIC_H
311
255
  #define ZSTDv06_STATIC_H
@@ -412,7 +356,7 @@ ZSTDLIBv06_API size_t ZSTDv06_decompressBlock(ZSTDv06_DCtx* dctx, void* dst, siz
412
356
  Header File for include
413
357
  Copyright (C) 2014-2016, Yann Collet.
414
358
 
415
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
359
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
416
360
 
417
361
  Redistribution and use in source and binary forms, with or without
418
362
  modification, are permitted provided that the following conditions are
@@ -479,7 +423,7 @@ typedef enum { bt_compressed, bt_raw, bt_rle, bt_end } blockType_t;
479
423
  #define MIN_SEQUENCES_SIZE 1 /* nbSeq==0 */
480
424
  #define MIN_CBLOCK_SIZE (1 /*litCSize*/ + 1 /* RLE or RAW */ + MIN_SEQUENCES_SIZE /* nbSeq==0 */) /* for a non-null block */
481
425
 
482
- #define HufLog 12
426
+ #define ZSTD_HUFFDTABLE_CAPACITY_LOG 12
483
427
 
484
428
  #define IS_HUF 0
485
429
  #define IS_PCH 1
@@ -608,9 +552,9 @@ typedef struct {
608
552
  U32 cachedLitLength;
609
553
  const BYTE* cachedLiterals;
610
554
  ZSTDv06_stats_t stats;
611
- } seqStore_t;
555
+ } SeqStore_t;
612
556
 
613
- void ZSTDv06_seqToCodes(const seqStore_t* seqStorePtr, size_t const nbSeq);
557
+ void ZSTDv06_seqToCodes(const SeqStore_t* seqStorePtr, size_t const nbSeq);
614
558
 
615
559
 
616
560
  #endif /* ZSTDv06_CCOMMON_H_MODULE */
@@ -619,7 +563,7 @@ void ZSTDv06_seqToCodes(const seqStore_t* seqStorePtr, size_t const nbSeq);
619
563
  Public Prototypes declaration
620
564
  Copyright (C) 2013-2016, Yann Collet.
621
565
 
622
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
566
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
623
567
 
624
568
  Redistribution and use in source and binary forms, with or without
625
569
  modification, are permitted provided that the following conditions are
@@ -767,7 +711,7 @@ If there is an error, the function will return an error code, which can be teste
767
711
  header file (to include)
768
712
  Copyright (C) 2013-2016, Yann Collet.
769
713
 
770
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
714
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
771
715
 
772
716
  Redistribution and use in source and binary forms, with or without
773
717
  modification, are permitted provided that the following conditions are
@@ -928,7 +872,7 @@ MEM_STATIC size_t BITv06_initDStream(BITv06_DStream_t* bitD, const void* srcBuff
928
872
  }
929
873
 
930
874
  /*! BITv06_lookBitsFast() :
931
- * unsafe version; only works only if nbBits >= 1 */
875
+ * unsafe version; only works if nbBits >= 1 */
932
876
  MEM_STATIC size_t BITv06_lookBitsFast(const BITv06_DStream_t* bitD, U32 nbBits)
933
877
  {
934
878
  U32 const bitMask = sizeof(bitD->bitContainer)*8 - 1;
@@ -948,7 +892,7 @@ MEM_STATIC size_t BITv06_readBits(BITv06_DStream_t* bitD, U32 nbBits)
948
892
  }
949
893
 
950
894
  /*! BITv06_readBitsFast() :
951
- * unsafe version; only works only if nbBits >= 1 */
895
+ * unsafe version; only works if nbBits >= 1 */
952
896
  MEM_STATIC size_t BITv06_readBitsFast(BITv06_DStream_t* bitD, U32 nbBits)
953
897
  {
954
898
  size_t const value = BITv06_lookBitsFast(bitD, nbBits);
@@ -1002,7 +946,7 @@ MEM_STATIC unsigned BITv06_endOfDStream(const BITv06_DStream_t* DStream)
1002
946
  header file for static linking (only)
1003
947
  Copyright (C) 2013-2015, Yann Collet
1004
948
 
1005
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
949
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
1006
950
 
1007
951
  Redistribution and use in source and binary forms, with or without
1008
952
  modification, are permitted provided that the following conditions are
@@ -1210,7 +1154,7 @@ MEM_STATIC BYTE FSEv06_decodeSymbolFast(FSEv06_DState_t* DStatePtr, BITv06_DStre
1210
1154
  Common functions of New Generation Entropy library
1211
1155
  Copyright (C) 2016, Yann Collet.
1212
1156
 
1213
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
1157
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
1214
1158
 
1215
1159
  Redistribution and use in source and binary forms, with or without
1216
1160
  modification, are permitted provided that the following conditions are
@@ -1355,7 +1299,7 @@ size_t FSEv06_readNCount (short* normalizedCounter, unsigned* maxSVPtr, unsigned
1355
1299
  FSE : Finite State Entropy decoder
1356
1300
  Copyright (C) 2013-2015, Yann Collet.
1357
1301
 
1358
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
1302
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
1359
1303
 
1360
1304
  Redistribution and use in source and binary forms, with or without
1361
1305
  modification, are permitted provided that the following conditions are
@@ -1679,7 +1623,7 @@ size_t FSEv06_decompress(void* dst, size_t maxDstSize, const void* cSrc, size_t
1679
1623
  header file
1680
1624
  Copyright (C) 2013-2016, Yann Collet.
1681
1625
 
1682
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
1626
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
1683
1627
 
1684
1628
  Redistribution and use in source and binary forms, with or without
1685
1629
  modification, are permitted provided that the following conditions are
@@ -1749,7 +1693,7 @@ size_t HUFv06_compressBound(size_t size); /**< maximum compressed size */
1749
1693
  header file, for static linking only
1750
1694
  Copyright (C) 2013-2016, Yann Collet
1751
1695
 
1752
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
1696
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
1753
1697
 
1754
1698
  Redistribution and use in source and binary forms, with or without
1755
1699
  modification, are permitted provided that the following conditions are
@@ -1931,7 +1875,7 @@ MEM_STATIC size_t HUFv06_readStats(BYTE* huffWeight, size_t hwSize, U32* rankSta
1931
1875
  Huffman decoder, part of New Generation Entropy library
1932
1876
  Copyright (C) 2013-2016, Yann Collet.
1933
1877
 
1934
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
1878
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
1935
1879
 
1936
1880
  Redistribution and use in source and binary forms, with or without
1937
1881
  modification, are permitted provided that the following conditions are
@@ -2676,7 +2620,7 @@ size_t HUFv06_decompress (void* dst, size_t dstSize, const void* cSrc, size_t cS
2676
2620
  Common functions of Zstd compression library
2677
2621
  Copyright (C) 2015-2016, Yann Collet.
2678
2622
 
2679
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
2623
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
2680
2624
 
2681
2625
  Redistribution and use in source and binary forms, with or without
2682
2626
  modification, are permitted provided that the following conditions are
@@ -2700,7 +2644,7 @@ size_t HUFv06_decompress (void* dst, size_t dstSize, const void* cSrc, size_t cS
2700
2644
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2701
2645
 
2702
2646
  You can contact the author at :
2703
- - zstd homepage : http://www.zstd.net/
2647
+ - zstd homepage : https://facebook.github.io/zstd/
2704
2648
  */
2705
2649
 
2706
2650
 
@@ -2730,7 +2674,7 @@ const char* ZBUFFv06_getErrorName(size_t errorCode) { return ERR_getErrorName(er
2730
2674
  zstd - standard compression library
2731
2675
  Copyright (C) 2014-2016, Yann Collet.
2732
2676
 
2733
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
2677
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
2734
2678
 
2735
2679
  Redistribution and use in source and binary forms, with or without
2736
2680
  modification, are permitted provided that the following conditions are
@@ -2754,7 +2698,7 @@ const char* ZBUFFv06_getErrorName(size_t errorCode) { return ERR_getErrorName(er
2754
2698
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2755
2699
 
2756
2700
  You can contact the author at :
2757
- - zstd homepage : http://www.zstd.net
2701
+ - zstd homepage : https://facebook.github.io/zstd
2758
2702
  */
2759
2703
 
2760
2704
  /* ***************************************************************
@@ -2806,7 +2750,7 @@ struct ZSTDv06_DCtx_s
2806
2750
  FSEv06_DTable LLTable[FSEv06_DTABLE_SIZE_U32(LLFSELog)];
2807
2751
  FSEv06_DTable OffTable[FSEv06_DTABLE_SIZE_U32(OffFSELog)];
2808
2752
  FSEv06_DTable MLTable[FSEv06_DTABLE_SIZE_U32(MLFSELog)];
2809
- unsigned hufTableX4[HUFv06_DTABLE_SIZE(HufLog)];
2753
+ unsigned hufTableX4[HUFv06_DTABLE_SIZE(ZSTD_HUFFDTABLE_CAPACITY_LOG)];
2810
2754
  const void* previousDstEnd;
2811
2755
  const void* base;
2812
2756
  const void* vBase;
@@ -2834,7 +2778,7 @@ size_t ZSTDv06_decompressBegin(ZSTDv06_DCtx* dctx)
2834
2778
  dctx->base = NULL;
2835
2779
  dctx->vBase = NULL;
2836
2780
  dctx->dictEnd = NULL;
2837
- dctx->hufTableX4[0] = HufLog;
2781
+ dctx->hufTableX4[0] = ZSTD_HUFFDTABLE_CAPACITY_LOG;
2838
2782
  dctx->flagRepeatTable = 0;
2839
2783
  return 0;
2840
2784
  }
@@ -3370,13 +3314,19 @@ static size_t ZSTDv06_execSequence(BYTE* op,
3370
3314
  const BYTE* const iLitEnd = *litPtr + sequence.litLength;
3371
3315
  const BYTE* match = oLitEnd - sequence.offset;
3372
3316
 
3373
- /* check */
3374
- 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
+
3375
3325
  if (oMatchEnd > oend) return ERROR(dstSize_tooSmall); /* overwrite beyond dst buffer */
3376
- if (iLitEnd > litLimit) return ERROR(corruption_detected); /* over-read beyond lit buffer */
3326
+ if (iLitEnd > litLimit) return ERROR(corruption_detected); /* overRead beyond lit buffer */
3377
3327
 
3378
3328
  /* copy Literals */
3379
- 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 */
3380
3330
  op = oLitEnd;
3381
3331
  *litPtr = iLitEnd; /* update for next sequence */
3382
3332
 
@@ -3787,6 +3737,7 @@ size_t ZSTDv06_decompressContinue(ZSTDv06_DCtx* dctx, void* dst, size_t dstCapac
3787
3737
  }
3788
3738
  dctx->stage = ZSTDds_decodeBlockHeader;
3789
3739
  dctx->expected = ZSTDv06_blockHeaderSize;
3740
+ if (ZSTDv06_isError(rSize)) return rSize;
3790
3741
  dctx->previousDstEnd = (char*)dst + rSize;
3791
3742
  return rSize;
3792
3743
  }
@@ -3889,7 +3840,7 @@ size_t ZSTDv06_decompressBegin_usingDict(ZSTDv06_DCtx* dctx, const void* dict, s
3889
3840
  Buffered version of Zstd compression library
3890
3841
  Copyright (C) 2015-2016, Yann Collet.
3891
3842
 
3892
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
3843
+ BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
3893
3844
 
3894
3845
  Redistribution and use in source and binary forms, with or without
3895
3846
  modification, are permitted provided that the following conditions are
@@ -3913,7 +3864,7 @@ size_t ZSTDv06_decompressBegin_usingDict(ZSTDv06_DCtx* dctx, const void* dict, s
3913
3864
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3914
3865
 
3915
3866
  You can contact the author at :
3916
- - zstd homepage : http://www.zstd.net/
3867
+ - zstd homepage : https://facebook.github.io/zstd/
3917
3868
  */
3918
3869
 
3919
3870
 
@@ -3968,6 +3919,10 @@ ZBUFFv06_DCtx* ZBUFFv06_createDCtx(void)
3968
3919
  if (zbd==NULL) return NULL;
3969
3920
  memset(zbd, 0, sizeof(*zbd));
3970
3921
  zbd->zd = ZSTDv06_createDCtx();
3922
+ if (zbd->zd==NULL) {
3923
+ ZBUFFv06_freeDCtx(zbd); /* avoid leaking the context */
3924
+ return NULL;
3925
+ }
3971
3926
  zbd->stage = ZBUFFds_init;
3972
3927
  return zbd;
3973
3928
  }
@@ -4035,7 +3990,8 @@ size_t ZBUFFv06_decompressContinue(ZBUFFv06_DCtx* zbd,
4035
3990
  size_t const toLoad = hSize - zbd->lhSize; /* if hSize!=0, hSize > zbd->lhSize */
4036
3991
  if (ZSTDv06_isError(hSize)) return hSize;
4037
3992
  if (toLoad > (size_t)(iend-ip)) { /* not enough input to load full header */
4038
- memcpy(zbd->headerBuffer + zbd->lhSize, ip, iend-ip);
3993
+ if (ip != NULL)
3994
+ memcpy(zbd->headerBuffer + zbd->lhSize, ip, iend-ip);
4039
3995
  zbd->lhSize += iend-ip;
4040
3996
  *dstCapacityPtr = 0;
4041
3997
  return (hSize - zbd->lhSize) + ZSTDv06_blockHeaderSize; /* remaining header bytes + next block header */
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 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