zstdlib 0.8.0-x64-mingw32 → 0.9.0-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +10 -0
  3. data/README.md +7 -1
  4. data/Rakefile +38 -8
  5. data/ext/{zstdlib → zstdlib_c}/extconf.rb +10 -5
  6. data/ext/{zstdlib → zstdlib_c}/ruby/zlib-2.2/zstdlib.c +2 -2
  7. data/ext/{zstdlib → zstdlib_c}/ruby/zlib-2.3/zstdlib.c +2 -2
  8. data/ext/{zstdlib → zstdlib_c}/ruby/zlib-2.4/zstdlib.c +2 -2
  9. data/ext/{zstdlib → zstdlib_c}/ruby/zlib-2.5/zstdlib.c +2 -2
  10. data/ext/{zstdlib → zstdlib_c}/ruby/zlib-2.6/zstdlib.c +2 -2
  11. data/ext/{zstdlib → zstdlib_c}/ruby/zlib-2.7/zstdlib.c +2 -2
  12. data/ext/{zstdlib → zstdlib_c}/ruby/zlib-3.0/zstdlib.c +2 -2
  13. data/ext/zstdlib_c/ruby/zlib-3.1/zstdlib.c +5076 -0
  14. data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/adler32.c +0 -0
  15. data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/compress.c +0 -0
  16. data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/crc32.c +0 -0
  17. data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/crc32.h +0 -0
  18. data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/deflate.c +0 -0
  19. data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/deflate.h +0 -0
  20. data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/gzclose.c +0 -0
  21. data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/gzguts.h +0 -0
  22. data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/gzlib.c +0 -0
  23. data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/gzread.c +0 -0
  24. data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/gzwrite.c +0 -0
  25. data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/infback.c +0 -0
  26. data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/inffast.c +0 -0
  27. data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/inffast.h +0 -0
  28. data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/inffixed.h +0 -0
  29. data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/inflate.c +0 -0
  30. data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/inflate.h +0 -0
  31. data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/inftrees.c +0 -0
  32. data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/inftrees.h +0 -0
  33. data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/trees.c +0 -0
  34. data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/trees.h +0 -0
  35. data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/uncompr.c +0 -0
  36. data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/zconf.h +0 -0
  37. data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/zlib.h +0 -0
  38. data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/zutil.c +0 -0
  39. data/ext/{zstdlib → zstdlib_c}/zlib-1.2.11/zutil.h +0 -0
  40. data/ext/{zstdlib → zstdlib_c}/zlib.mk +0 -0
  41. data/ext/{zstdlib → zstdlib_c}/zlibwrapper/zlibwrapper.c +1 -5
  42. data/ext/{zstdlib → zstdlib_c}/zlibwrapper.mk +0 -0
  43. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/common/bitstream.h +24 -9
  44. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/common/compiler.h +89 -43
  45. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/common/cpu.h +0 -0
  46. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/common/debug.c +0 -0
  47. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/common/debug.h +0 -0
  48. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/common/entropy_common.c +11 -5
  49. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/common/error_private.c +0 -0
  50. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/common/error_private.h +79 -0
  51. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/common/fse.h +2 -1
  52. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/common/fse_decompress.c +1 -1
  53. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/common/huf.h +24 -22
  54. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/common/mem.h +18 -0
  55. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/common/pool.c +11 -6
  56. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/common/pool.h +2 -2
  57. data/ext/zstdlib_c/zstd-1.5.2/lib/common/portability_macros.h +137 -0
  58. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/common/threading.c +0 -0
  59. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/common/threading.h +0 -0
  60. data/ext/zstdlib_c/zstd-1.5.2/lib/common/xxhash.c +24 -0
  61. data/ext/zstdlib_c/zstd-1.5.2/lib/common/xxhash.h +5686 -0
  62. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/common/zstd_common.c +0 -0
  63. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/common/zstd_deps.h +0 -0
  64. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/common/zstd_internal.h +95 -92
  65. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/common/zstd_trace.h +12 -3
  66. data/ext/zstdlib_c/zstd-1.5.2/lib/compress/clevels.h +134 -0
  67. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/compress/fse_compress.c +63 -27
  68. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/compress/hist.c +0 -0
  69. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/compress/hist.h +0 -0
  70. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/compress/huf_compress.c +537 -104
  71. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_compress.c +307 -373
  72. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_compress_internal.h +174 -83
  73. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_compress_literals.c +4 -3
  74. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_compress_literals.h +3 -1
  75. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_compress_sequences.c +15 -14
  76. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_compress_sequences.h +0 -0
  77. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_compress_superblock.c +4 -3
  78. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_compress_superblock.h +0 -0
  79. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_cwksp.h +41 -27
  80. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_double_fast.c +295 -120
  81. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_double_fast.h +0 -0
  82. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_fast.c +309 -130
  83. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_fast.h +0 -0
  84. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_lazy.c +482 -562
  85. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_lazy.h +0 -0
  86. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_ldm.c +9 -7
  87. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_ldm.h +1 -1
  88. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_ldm_geartab.h +4 -1
  89. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_opt.c +249 -148
  90. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_opt.h +0 -0
  91. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/compress/zstdmt_compress.c +76 -38
  92. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/compress/zstdmt_compress.h +4 -1
  93. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/decompress/huf_decompress.c +727 -189
  94. data/ext/zstdlib_c/zstd-1.5.2/lib/decompress/huf_decompress_amd64.S +585 -0
  95. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/decompress/zstd_ddict.c +0 -0
  96. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/decompress/zstd_ddict.h +0 -0
  97. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/decompress/zstd_decompress.c +85 -22
  98. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/decompress/zstd_decompress_block.c +744 -220
  99. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/decompress/zstd_decompress_block.h +8 -2
  100. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/decompress/zstd_decompress_internal.h +34 -3
  101. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/zdict.h +4 -4
  102. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/zstd.h +179 -136
  103. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/lib/zstd_errors.h +0 -0
  104. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/zlibWrapper/gzclose.c +0 -0
  105. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/zlibWrapper/gzcompatibility.h +0 -0
  106. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/zlibWrapper/gzguts.h +0 -0
  107. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/zlibWrapper/gzlib.c +0 -0
  108. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/zlibWrapper/gzread.c +0 -0
  109. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/zlibWrapper/gzwrite.c +0 -0
  110. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/zlibWrapper/zstd_zlibwrapper.c +7 -0
  111. data/ext/{zstdlib/zstd-1.5.0 → zstdlib_c/zstd-1.5.2}/zlibWrapper/zstd_zlibwrapper.h +0 -0
  112. data/ext/zstdlib_c/zstd.mk +15 -0
  113. data/lib/2.4/zstdlib_c.so +0 -0
  114. data/lib/2.5/zstdlib_c.so +0 -0
  115. data/lib/2.6/zstdlib_c.so +0 -0
  116. data/lib/2.7/zstdlib_c.so +0 -0
  117. data/lib/3.0/zstdlib_c.so +0 -0
  118. data/lib/zstdlib.rb +2 -2
  119. metadata +124 -121
  120. data/ext/zstdlib/zstd-1.5.0/lib/common/xxhash.c +0 -824
  121. data/ext/zstdlib/zstd-1.5.0/lib/common/xxhash.h +0 -285
  122. data/ext/zstdlib/zstd.mk +0 -14
  123. data/lib/2.2/zstdlib.so +0 -0
  124. data/lib/2.3/zstdlib.so +0 -0
  125. data/lib/2.4/zstdlib.so +0 -0
  126. data/lib/2.5/zstdlib.so +0 -0
  127. data/lib/2.6/zstdlib.so +0 -0
  128. data/lib/2.7/zstdlib.so +0 -0
@@ -56,7 +56,6 @@
56
56
  * Dependencies
57
57
  *********************************************************/
58
58
  #include "../common/zstd_deps.h" /* ZSTD_memcpy, ZSTD_memmove, ZSTD_memset */
59
- #include "../common/cpu.h" /* bmi2 */
60
59
  #include "../common/mem.h" /* low level memory routines */
61
60
  #define FSE_STATIC_LINKING_ONLY
62
61
  #include "../common/fse.h"
@@ -177,12 +176,15 @@ static const ZSTD_DDict* ZSTD_DDictHashSet_getDDict(ZSTD_DDictHashSet* hashSet,
177
176
  static ZSTD_DDictHashSet* ZSTD_createDDictHashSet(ZSTD_customMem customMem) {
178
177
  ZSTD_DDictHashSet* ret = (ZSTD_DDictHashSet*)ZSTD_customMalloc(sizeof(ZSTD_DDictHashSet), customMem);
179
178
  DEBUGLOG(4, "Allocating new hash set");
179
+ if (!ret)
180
+ return NULL;
180
181
  ret->ddictPtrTable = (const ZSTD_DDict**)ZSTD_customCalloc(DDICT_HASHSET_TABLE_BASE_SIZE * sizeof(ZSTD_DDict*), customMem);
181
- ret->ddictPtrTableSize = DDICT_HASHSET_TABLE_BASE_SIZE;
182
- ret->ddictPtrCount = 0;
183
- if (!ret || !ret->ddictPtrTable) {
182
+ if (!ret->ddictPtrTable) {
183
+ ZSTD_customFree(ret, customMem);
184
184
  return NULL;
185
185
  }
186
+ ret->ddictPtrTableSize = DDICT_HASHSET_TABLE_BASE_SIZE;
187
+ ret->ddictPtrCount = 0;
186
188
  return ret;
187
189
  }
188
190
 
@@ -255,11 +257,15 @@ static void ZSTD_initDCtx_internal(ZSTD_DCtx* dctx)
255
257
  dctx->inBuffSize = 0;
256
258
  dctx->outBuffSize = 0;
257
259
  dctx->streamStage = zdss_init;
260
+ #if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT>=1)
258
261
  dctx->legacyContext = NULL;
259
262
  dctx->previousLegacyVersion = 0;
263
+ #endif
260
264
  dctx->noForwardProgress = 0;
261
265
  dctx->oversizedDuration = 0;
262
- dctx->bmi2 = ZSTD_cpuid_bmi2(ZSTD_cpuid());
266
+ #if DYNAMIC_BMI2
267
+ dctx->bmi2 = ZSTD_cpuSupportsBmi2();
268
+ #endif
263
269
  dctx->ddictSet = NULL;
264
270
  ZSTD_DCtx_resetParameters(dctx);
265
271
  #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
@@ -280,8 +286,7 @@ ZSTD_DCtx* ZSTD_initStaticDCtx(void *workspace, size_t workspaceSize)
280
286
  return dctx;
281
287
  }
282
288
 
283
- ZSTD_DCtx* ZSTD_createDCtx_advanced(ZSTD_customMem customMem)
284
- {
289
+ static ZSTD_DCtx* ZSTD_createDCtx_internal(ZSTD_customMem customMem) {
285
290
  if ((!customMem.customAlloc) ^ (!customMem.customFree)) return NULL;
286
291
 
287
292
  { ZSTD_DCtx* const dctx = (ZSTD_DCtx*)ZSTD_customMalloc(sizeof(*dctx), customMem);
@@ -292,10 +297,15 @@ ZSTD_DCtx* ZSTD_createDCtx_advanced(ZSTD_customMem customMem)
292
297
  }
293
298
  }
294
299
 
300
+ ZSTD_DCtx* ZSTD_createDCtx_advanced(ZSTD_customMem customMem)
301
+ {
302
+ return ZSTD_createDCtx_internal(customMem);
303
+ }
304
+
295
305
  ZSTD_DCtx* ZSTD_createDCtx(void)
296
306
  {
297
307
  DEBUGLOG(3, "ZSTD_createDCtx");
298
- return ZSTD_createDCtx_advanced(ZSTD_defaultCMem);
308
+ return ZSTD_createDCtx_internal(ZSTD_defaultCMem);
299
309
  }
300
310
 
301
311
  static void ZSTD_clearDict(ZSTD_DCtx* dctx)
@@ -380,6 +390,19 @@ unsigned ZSTD_isFrame(const void* buffer, size_t size)
380
390
  return 0;
381
391
  }
382
392
 
393
+ /*! ZSTD_isSkippableFrame() :
394
+ * Tells if the content of `buffer` starts with a valid Frame Identifier for a skippable frame.
395
+ * Note : Frame Identifier is 4 bytes. If `size < 4`, @return will always be 0.
396
+ */
397
+ unsigned ZSTD_isSkippableFrame(const void* buffer, size_t size)
398
+ {
399
+ if (size < ZSTD_FRAMEIDSIZE) return 0;
400
+ { U32 const magic = MEM_readLE32(buffer);
401
+ if ((magic & ZSTD_MAGIC_SKIPPABLE_MASK) == ZSTD_MAGIC_SKIPPABLE_START) return 1;
402
+ }
403
+ return 0;
404
+ }
405
+
383
406
  /** ZSTD_frameHeaderSize_internal() :
384
407
  * srcSize must be large enough to reach header size fields.
385
408
  * note : only works for formats ZSTD_f_zstd1 and ZSTD_f_zstd1_magicless.
@@ -466,7 +489,9 @@ size_t ZSTD_getFrameHeader_advanced(ZSTD_frameHeader* zfhPtr, const void* src, s
466
489
  }
467
490
  switch(dictIDSizeCode)
468
491
  {
469
- default: assert(0); /* impossible */
492
+ default:
493
+ assert(0); /* impossible */
494
+ ZSTD_FALLTHROUGH;
470
495
  case 0 : break;
471
496
  case 1 : dictID = ip[pos]; pos++; break;
472
497
  case 2 : dictID = MEM_readLE16(ip+pos); pos+=2; break;
@@ -474,7 +499,9 @@ size_t ZSTD_getFrameHeader_advanced(ZSTD_frameHeader* zfhPtr, const void* src, s
474
499
  }
475
500
  switch(fcsID)
476
501
  {
477
- default: assert(0); /* impossible */
502
+ default:
503
+ assert(0); /* impossible */
504
+ ZSTD_FALLTHROUGH;
478
505
  case 0 : if (singleSegment) frameContentSize = ip[pos]; break;
479
506
  case 1 : frameContentSize = MEM_readLE16(ip+pos)+256; break;
480
507
  case 2 : frameContentSize = MEM_readLE32(ip+pos); break;
@@ -503,7 +530,6 @@ size_t ZSTD_getFrameHeader(ZSTD_frameHeader* zfhPtr, const void* src, size_t src
503
530
  return ZSTD_getFrameHeader_advanced(zfhPtr, src, srcSize, ZSTD_f_zstd1);
504
531
  }
505
532
 
506
-
507
533
  /** ZSTD_getFrameContentSize() :
508
534
  * compatible with legacy mode
509
535
  * @return : decompressed size of the single frame pointed to be `src` if known, otherwise
@@ -544,6 +570,37 @@ static size_t readSkippableFrameSize(void const* src, size_t srcSize)
544
570
  }
545
571
  }
546
572
 
573
+ /*! ZSTD_readSkippableFrame() :
574
+ * Retrieves a zstd skippable frame containing data given by src, and writes it to dst buffer.
575
+ *
576
+ * The parameter magicVariant will receive the magicVariant that was supplied when the frame was written,
577
+ * i.e. magicNumber - ZSTD_MAGIC_SKIPPABLE_START. This can be NULL if the caller is not interested
578
+ * in the magicVariant.
579
+ *
580
+ * Returns an error if destination buffer is not large enough, or if the frame is not skippable.
581
+ *
582
+ * @return : number of bytes written or a ZSTD error.
583
+ */
584
+ ZSTDLIB_API size_t ZSTD_readSkippableFrame(void* dst, size_t dstCapacity, unsigned* magicVariant,
585
+ const void* src, size_t srcSize)
586
+ {
587
+ U32 const magicNumber = MEM_readLE32(src);
588
+ size_t skippableFrameSize = readSkippableFrameSize(src, srcSize);
589
+ size_t skippableContentSize = skippableFrameSize - ZSTD_SKIPPABLEHEADERSIZE;
590
+
591
+ /* check input validity */
592
+ RETURN_ERROR_IF(!ZSTD_isSkippableFrame(src, srcSize), frameParameter_unsupported, "");
593
+ RETURN_ERROR_IF(skippableFrameSize < ZSTD_SKIPPABLEHEADERSIZE || skippableFrameSize > srcSize, srcSize_wrong, "");
594
+ RETURN_ERROR_IF(skippableContentSize > dstCapacity, dstSize_tooSmall, "");
595
+
596
+ /* deliver payload */
597
+ if (skippableContentSize > 0 && dst != NULL)
598
+ ZSTD_memcpy(dst, (const BYTE *)src + ZSTD_SKIPPABLEHEADERSIZE, skippableContentSize);
599
+ if (magicVariant != NULL)
600
+ *magicVariant = magicNumber - ZSTD_MAGIC_SKIPPABLE_START;
601
+ return skippableContentSize;
602
+ }
603
+
547
604
  /** ZSTD_findDecompressedSize() :
548
605
  * compatible with legacy mode
549
606
  * `srcSize` must be the exact length of some number of ZSTD compressed and/or
@@ -858,7 +915,7 @@ static size_t ZSTD_decompressFrame(ZSTD_DCtx* dctx,
858
915
  switch(blockProperties.blockType)
859
916
  {
860
917
  case bt_compressed:
861
- decodedSize = ZSTD_decompressBlock_internal(dctx, op, (size_t)(oend-op), ip, cBlockSize, /* frame */ 1);
918
+ decodedSize = ZSTD_decompressBlock_internal(dctx, op, (size_t)(oend-op), ip, cBlockSize, /* frame */ 1, not_streaming);
862
919
  break;
863
920
  case bt_raw :
864
921
  decodedSize = ZSTD_copyRawBlock(op, (size_t)(oend-op), ip, cBlockSize);
@@ -1009,7 +1066,7 @@ static ZSTD_DDict const* ZSTD_getDDict(ZSTD_DCtx* dctx)
1009
1066
  switch (dctx->dictUses) {
1010
1067
  default:
1011
1068
  assert(0 /* Impossible */);
1012
- /* fall-through */
1069
+ ZSTD_FALLTHROUGH;
1013
1070
  case ZSTD_dont_use:
1014
1071
  ZSTD_clearDict(dctx);
1015
1072
  return NULL;
@@ -1031,7 +1088,7 @@ size_t ZSTD_decompress(void* dst, size_t dstCapacity, const void* src, size_t sr
1031
1088
  {
1032
1089
  #if defined(ZSTD_HEAPMODE) && (ZSTD_HEAPMODE>=1)
1033
1090
  size_t regenSize;
1034
- ZSTD_DCtx* const dctx = ZSTD_createDCtx();
1091
+ ZSTD_DCtx* const dctx = ZSTD_createDCtx_internal(ZSTD_defaultCMem);
1035
1092
  RETURN_ERROR_IF(dctx==NULL, memory_allocation, "NULL pointer!");
1036
1093
  regenSize = ZSTD_decompressDCtx(dctx, dst, dstCapacity, src, srcSize);
1037
1094
  ZSTD_freeDCtx(dctx);
@@ -1065,7 +1122,7 @@ static size_t ZSTD_nextSrcSizeToDecompressWithInputSize(ZSTD_DCtx* dctx, size_t
1065
1122
  return dctx->expected;
1066
1123
  if (dctx->bType != bt_raw)
1067
1124
  return dctx->expected;
1068
- return MIN(MAX(inputSize, 1), dctx->expected);
1125
+ return BOUNDED(1, inputSize, dctx->expected);
1069
1126
  }
1070
1127
 
1071
1128
  ZSTD_nextInputType_e ZSTD_nextInputType(ZSTD_DCtx* dctx) {
@@ -1073,7 +1130,9 @@ ZSTD_nextInputType_e ZSTD_nextInputType(ZSTD_DCtx* dctx) {
1073
1130
  {
1074
1131
  default: /* should not happen */
1075
1132
  assert(0);
1133
+ ZSTD_FALLTHROUGH;
1076
1134
  case ZSTDds_getFrameHeaderSize:
1135
+ ZSTD_FALLTHROUGH;
1077
1136
  case ZSTDds_decodeFrameHeader:
1078
1137
  return ZSTDnit_frameHeader;
1079
1138
  case ZSTDds_decodeBlockHeader:
@@ -1085,6 +1144,7 @@ ZSTD_nextInputType_e ZSTD_nextInputType(ZSTD_DCtx* dctx) {
1085
1144
  case ZSTDds_checkChecksum:
1086
1145
  return ZSTDnit_checksum;
1087
1146
  case ZSTDds_decodeSkippableHeader:
1147
+ ZSTD_FALLTHROUGH;
1088
1148
  case ZSTDds_skipFrame:
1089
1149
  return ZSTDnit_skippableFrame;
1090
1150
  }
@@ -1168,7 +1228,7 @@ size_t ZSTD_decompressContinue(ZSTD_DCtx* dctx, void* dst, size_t dstCapacity, c
1168
1228
  {
1169
1229
  case bt_compressed:
1170
1230
  DEBUGLOG(5, "ZSTD_decompressContinue: case bt_compressed");
1171
- rSize = ZSTD_decompressBlock_internal(dctx, dst, dstCapacity, src, srcSize, /* frame */ 1);
1231
+ rSize = ZSTD_decompressBlock_internal(dctx, dst, dstCapacity, src, srcSize, /* frame */ 1, is_streaming);
1172
1232
  dctx->expected = 0; /* Streaming not supported */
1173
1233
  break;
1174
1234
  case bt_raw :
@@ -1493,7 +1553,7 @@ size_t ZSTD_decompress_usingDDict(ZSTD_DCtx* dctx,
1493
1553
  ZSTD_DStream* ZSTD_createDStream(void)
1494
1554
  {
1495
1555
  DEBUGLOG(3, "ZSTD_createDStream");
1496
- return ZSTD_createDStream_advanced(ZSTD_defaultCMem);
1556
+ return ZSTD_createDCtx_internal(ZSTD_defaultCMem);
1497
1557
  }
1498
1558
 
1499
1559
  ZSTD_DStream* ZSTD_initStaticDStream(void *workspace, size_t workspaceSize)
@@ -1503,7 +1563,7 @@ ZSTD_DStream* ZSTD_initStaticDStream(void *workspace, size_t workspaceSize)
1503
1563
 
1504
1564
  ZSTD_DStream* ZSTD_createDStream_advanced(ZSTD_customMem customMem)
1505
1565
  {
1506
- return ZSTD_createDCtx_advanced(customMem);
1566
+ return ZSTD_createDCtx_internal(customMem);
1507
1567
  }
1508
1568
 
1509
1569
  size_t ZSTD_freeDStream(ZSTD_DStream* zds)
@@ -1763,7 +1823,8 @@ size_t ZSTD_sizeof_DStream(const ZSTD_DStream* dctx)
1763
1823
  size_t ZSTD_decodingBufferSize_min(unsigned long long windowSize, unsigned long long frameContentSize)
1764
1824
  {
1765
1825
  size_t const blockSize = (size_t) MIN(windowSize, ZSTD_BLOCKSIZE_MAX);
1766
- unsigned long long const neededRBSize = windowSize + blockSize + (WILDCOPY_OVERLENGTH * 2);
1826
+ /* space is needed to store the litbuffer after the output of a given block without stomping the extDict of a previous run, as well as to cover both windows against wildcopy*/
1827
+ unsigned long long const neededRBSize = windowSize + blockSize + ZSTD_BLOCKSIZE_MAX + (WILDCOPY_OVERLENGTH * 2);
1767
1828
  unsigned long long const neededSize = MIN(frameContentSize, neededRBSize);
1768
1829
  size_t const minRBSize = (size_t) neededSize;
1769
1830
  RETURN_ERROR_IF((unsigned long long)minRBSize != neededSize,
@@ -1897,10 +1958,12 @@ size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inB
1897
1958
  DEBUGLOG(5, "stage zdss_init => transparent reset ");
1898
1959
  zds->streamStage = zdss_loadHeader;
1899
1960
  zds->lhSize = zds->inPos = zds->outStart = zds->outEnd = 0;
1961
+ #if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT>=1)
1900
1962
  zds->legacyVersion = 0;
1963
+ #endif
1901
1964
  zds->hostageByte = 0;
1902
1965
  zds->expectedOutBuffer = *output;
1903
- /* fall-through */
1966
+ ZSTD_FALLTHROUGH;
1904
1967
 
1905
1968
  case zdss_loadHeader :
1906
1969
  DEBUGLOG(5, "stage zdss_loadHeader (srcSize : %u)", (U32)(iend - ip));
@@ -2038,7 +2101,7 @@ size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inB
2038
2101
  zds->outBuffSize = neededOutBuffSize;
2039
2102
  } } }
2040
2103
  zds->streamStage = zdss_read;
2041
- /* fall-through */
2104
+ ZSTD_FALLTHROUGH;
2042
2105
 
2043
2106
  case zdss_read:
2044
2107
  DEBUGLOG(5, "stage zdss_read");
@@ -2057,7 +2120,7 @@ size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inB
2057
2120
  } }
2058
2121
  if (ip==iend) { someMoreWork = 0; break; } /* no more input */
2059
2122
  zds->streamStage = zdss_load;
2060
- /* fall-through */
2123
+ ZSTD_FALLTHROUGH;
2061
2124
 
2062
2125
  case zdss_load:
2063
2126
  { size_t const neededInSize = ZSTD_nextSrcSizeToDecompress(zds);