22# define ZSTD_HEAPMODE 1
29#ifndef ZSTD_LEGACY_SUPPORT
30# define ZSTD_LEGACY_SUPPORT 0
39#ifndef ZSTD_MAXWINDOWSIZE_DEFAULT
40# define ZSTD_MAXWINDOWSIZE_DEFAULT (((U32)1 << ZSTD_WINDOWLOG_LIMIT_DEFAULT) + 1)
50#ifndef ZSTD_NO_FORWARD_PROGRESS_MAX
51# define ZSTD_NO_FORWARD_PROGRESS_MAX 16
58#include "../common/zstd_deps.h"
59#include "../common/allocations.h"
60#include "../common/error_private.h"
61#include "../common/zstd_internal.h"
62#include "../common/mem.h"
63#include "../common/bits.h"
64#define FSE_STATIC_LINKING_ONLY
65#include "../common/fse.h"
66#include "../common/huf.h"
67#include "../common/xxhash.h"
72#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT>=1)
73# include "../legacy/zstd_legacy.h"
82#define DDICT_HASHSET_MAX_LOAD_FACTOR_COUNT_MULT 4
83#define DDICT_HASHSET_MAX_LOAD_FACTOR_SIZE_MULT 3
89#define DDICT_HASHSET_TABLE_BASE_SIZE 64
90#define DDICT_HASHSET_RESIZE_FACTOR 2
107 size_t idx = ZSTD_DDictHashSet_getIndex(hashSet, dictID);
110 DEBUGLOG(4,
"Hashed index: for dictID: %u is %zu", dictID, idx);
114 DEBUGLOG(4,
"DictID already exists, replacing rather than adding");
121 DEBUGLOG(4,
"Final idx after probing for dictID %u is: %zu", dictID, idx);
131static size_t ZSTD_DDictHashSet_expand(
ZSTD_DDictHashSet* hashSet, ZSTD_customMem customMem) {
138 DEBUGLOG(4,
"Expanding DDict hash table! Old size: %zu new size: %zu", oldTableSize, newTableSize);
139 RETURN_ERROR_IF(!newTable, memory_allocation,
"Expanded hashset allocation failed!");
143 for (i = 0; i < oldTableSize; ++i) {
144 if (oldTable[i] != NULL) {
157 size_t idx = ZSTD_DDictHashSet_getIndex(hashSet, dictID);
159 DEBUGLOG(4,
"Hashed index: for dictID: %u is %zu", dictID, idx);
162 if (currDictID == dictID || currDictID == 0) {
170 DEBUGLOG(4,
"Final idx after probing for dictID %u is: %zu", dictID, idx);
180 DEBUGLOG(4,
"Allocating new hash set");
196static void ZSTD_freeDDictHashSet(
ZSTD_DDictHashSet* hashSet, ZSTD_customMem customMem) {
197 DEBUGLOG(4,
"Freeing ddict hash set");
223 if (dctx==NULL)
return 0;
232static size_t ZSTD_startingInputLength(ZSTD_format_e format)
234 size_t const startingInputLength = ZSTD_FRAMEHEADERSIZE_PREFIX(format);
236 assert( (format == ZSTD_f_zstd1) || (format == ZSTD_f_zstd1_magicless) );
237 return startingInputLength;
240static void ZSTD_DCtx_resetParameters(
ZSTD_DCtx* dctx)
243 dctx->
format = ZSTD_f_zstd1;
252static void ZSTD_initDCtx_internal(
ZSTD_DCtx* dctx)
264#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT>=1)
265 dctx->legacyContext = NULL;
266 dctx->previousLegacyVersion = 0;
275 ZSTD_DCtx_resetParameters(dctx);
276#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
277 dctx->dictContentEndForFuzzing = NULL;
285 if ((
size_t)workspace & 7)
return NULL;
286 if (workspaceSize <
sizeof(
ZSTD_DCtx))
return NULL;
288 ZSTD_initDCtx_internal(dctx);
290 dctx->
inBuff = (
char*)(dctx+1);
294static ZSTD_DCtx* ZSTD_createDCtx_internal(ZSTD_customMem customMem) {
295 if ((!customMem.customAlloc) ^ (!customMem.customFree))
return NULL;
298 if (!dctx)
return NULL;
300 ZSTD_initDCtx_internal(dctx);
307 return ZSTD_createDCtx_internal(customMem);
313 return ZSTD_createDCtx_internal(ZSTD_defaultCMem);
316static void ZSTD_clearDict(
ZSTD_DCtx* dctx)
326 if (dctx==NULL)
return 0;
328 { ZSTD_customMem
const cMem = dctx->
customMem;
329 ZSTD_clearDict(dctx);
332#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT >= 1)
333 if (dctx->legacyContext)
334 ZSTD_freeLegacyStreamContext(dctx->legacyContext, dctx->previousLegacyVersion);
337 ZSTD_freeDDictHashSet(dctx->
ddictSet, cMem);
348 size_t const toCopy = (size_t)((
char*)(&dstDCtx->
inBuff) - (
char*)dstDCtx);
360static void ZSTD_DCtx_selectFrameDDict(
ZSTD_DCtx* dctx) {
362 DEBUGLOG(4,
"Adjusting DDict based on requested dict ID from frame");
367 ZSTD_clearDict(dctx);
369 dctx->
ddict = frameDDict;
392#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT >= 1)
393 if (ZSTD_isLegacy(buffer, size))
return 1;
416static size_t ZSTD_frameHeaderSize_internal(
const void* src,
size_t srcSize, ZSTD_format_e format)
418 size_t const minInputSize = ZSTD_startingInputLength(format);
421 {
BYTE const fhd = ((
const BYTE*)src)[minInputSize-1];
422 U32 const dictID= fhd & 3;
423 U32 const singleSegment = (fhd >> 5) & 1;
424 U32 const fcsId = fhd >> 6;
425 return minInputSize + !singleSegment
426 + ZSTD_did_fieldSize[dictID] + ZSTD_fcs_fieldSize[fcsId]
427 + (singleSegment && !fcsId);
437 return ZSTD_frameHeaderSize_internal(src, srcSize, ZSTD_f_zstd1);
450 size_t const minInputSize = ZSTD_startingInputLength(format);
452 DEBUGLOG(5,
"ZSTD_getFrameHeader_advanced: minInputSize = %zu, srcSize = %zu", minInputSize, srcSize);
456 RETURN_ERROR_IF(src==NULL, GENERIC,
"invalid parameter : src==NULL, but srcSize>0");
458 if (srcSize < minInputSize) {
459 if (srcSize > 0 && format != ZSTD_f_zstd1_magicless) {
464 size_t const toCopy =
MIN(4, srcSize);
474 "first bytes don't correspond to any supported magic number");
480 if ( (format != ZSTD_f_zstd1_magicless)
484 if (srcSize < ZSTD_SKIPPABLEHEADERSIZE)
485 return ZSTD_SKIPPABLEHEADERSIZE;
488 zfhPtr->frameType = ZSTD_skippableFrame;
495 {
size_t const fhsize = ZSTD_frameHeaderSize_internal(src, srcSize, format);
496 if (srcSize < fhsize)
return fhsize;
497 zfhPtr->headerSize = (
U32)fhsize;
500 {
BYTE const fhdByte = ip[minInputSize-1];
501 size_t pos = minInputSize;
502 U32 const dictIDSizeCode = fhdByte&3;
503 U32 const checksumFlag = (fhdByte>>2)&1;
504 U32 const singleSegment = (fhdByte>>5)&1;
505 U32 const fcsID = fhdByte>>6;
510 "reserved bits, must be zero");
512 if (!singleSegment) {
513 BYTE const wlByte = ip[pos++];
515 RETURN_ERROR_IF(windowLog > ZSTD_WINDOWLOG_MAX, frameParameter_windowTooLarge,
"");
516 windowSize = (1ULL << windowLog);
517 windowSize += (windowSize >> 3) * (wlByte&7);
519 switch(dictIDSizeCode)
525 case 1 : dictID = ip[pos]; pos++;
break;
534 case 0 :
if (singleSegment) frameContentSize = ip[pos];
break;
535 case 1 : frameContentSize =
MEM_readLE16(ip+pos)+256;
break;
536 case 2 : frameContentSize =
MEM_readLE32(ip+pos);
break;
537 case 3 : frameContentSize =
MEM_readLE64(ip+pos);
break;
539 if (singleSegment) windowSize = frameContentSize;
541 zfhPtr->frameType = ZSTD_frame;
542 zfhPtr->frameContentSize = frameContentSize;
543 zfhPtr->windowSize = windowSize;
545 zfhPtr->dictID = dictID;
546 zfhPtr->checksumFlag = checksumFlag;
569#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT >= 1)
570 if (ZSTD_isLegacy(src, srcSize)) {
571 unsigned long long const ret = ZSTD_getDecompressedSize_legacy(src, srcSize);
575 { ZSTD_frameHeader zfh;
578 if (zfh.frameType == ZSTD_skippableFrame) {
581 return zfh.frameContentSize;
585static size_t readSkippableFrameSize(
void const* src,
size_t srcSize)
587 size_t const skippableHeaderSize = ZSTD_SKIPPABLEHEADERSIZE;
590 RETURN_ERROR_IF(srcSize < ZSTD_SKIPPABLEHEADERSIZE, srcSize_wrong,
"");
594 frameParameter_unsupported,
"");
595 {
size_t const skippableSize = skippableHeaderSize + sizeU32;
597 return skippableSize;
613 unsigned* magicVariant,
614 const void* src,
size_t srcSize)
616 RETURN_ERROR_IF(srcSize < ZSTD_SKIPPABLEHEADERSIZE, srcSize_wrong,
"");
619 size_t skippableFrameSize = readSkippableFrameSize(src, srcSize);
620 size_t skippableContentSize = skippableFrameSize - ZSTD_SKIPPABLEHEADERSIZE;
624 RETURN_ERROR_IF(skippableFrameSize < ZSTD_SKIPPABLEHEADERSIZE || skippableFrameSize > srcSize, srcSize_wrong,
"");
625 RETURN_ERROR_IF(skippableContentSize > dstCapacity, dstSize_tooSmall,
"");
628 if (skippableContentSize > 0 && dst != NULL)
629 ZSTD_memcpy(dst, (
const BYTE *)src + ZSTD_SKIPPABLEHEADERSIZE, skippableContentSize);
630 if (magicVariant != NULL)
632 return skippableContentSize;
643 unsigned long long totalDstSize = 0;
645 while (srcSize >= ZSTD_startingInputLength(ZSTD_f_zstd1)) {
649 size_t const skippableSize = readSkippableFrameSize(src, srcSize);
651 assert(skippableSize <= srcSize);
653 src = (
const BYTE *)src + skippableSize;
654 srcSize -= skippableSize;
661 if (totalDstSize + fcs < totalDstSize)
668 assert(frameSrcSize <= srcSize);
670 src = (
const BYTE *)src + frameSrcSize;
671 srcSize -= frameSrcSize;
700static size_t ZSTD_decodeFrameHeader(
ZSTD_DCtx* dctx,
const void* src,
size_t headerSize)
708 ZSTD_DCtx_selectFrameDDict(dctx);
711#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
716 dictionary_wrong,
"");
729 return frameSizeInfo;
732static ZSTD_frameSizeInfo ZSTD_findFrameSizeInfo(
const void* src,
size_t srcSize, ZSTD_format_e format)
737#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT >= 1)
738 if (format == ZSTD_f_zstd1 && ZSTD_isLegacy(src, srcSize))
739 return ZSTD_findFrameSizeInfoLegacy(src, srcSize);
742 if (format == ZSTD_f_zstd1 && (srcSize >= ZSTD_SKIPPABLEHEADERSIZE)
744 frameSizeInfo.
compressedSize = readSkippableFrameSize(src, srcSize);
747 return frameSizeInfo;
750 const BYTE*
const ipstart = ip;
751 size_t remainingSize = srcSize;
753 ZSTD_frameHeader zfh;
758 return ZSTD_errorFrameSizeInfo(ret);
760 return ZSTD_errorFrameSizeInfo(
ERROR(srcSize_wrong));
763 ip += zfh.headerSize;
764 remainingSize -= zfh.headerSize;
771 return ZSTD_errorFrameSizeInfo(cBlockSize);
773 if (ZSTD_blockHeaderSize + cBlockSize > remainingSize)
774 return ZSTD_errorFrameSizeInfo(
ERROR(srcSize_wrong));
776 ip += ZSTD_blockHeaderSize + cBlockSize;
777 remainingSize -= ZSTD_blockHeaderSize + cBlockSize;
784 if (zfh.checksumFlag) {
785 if (remainingSize < 4)
786 return ZSTD_errorFrameSizeInfo(
ERROR(srcSize_wrong));
793 ? zfh.frameContentSize
794 : (
unsigned long long)nbBlocks * zfh.blockSizeMax;
795 return frameSizeInfo;
799static size_t ZSTD_findFrameCompressedSize_advanced(
const void *src,
size_t srcSize, ZSTD_format_e format) {
800 ZSTD_frameSizeInfo const frameSizeInfo = ZSTD_findFrameSizeInfo(src, srcSize, format);
809 return ZSTD_findFrameCompressedSize_advanced(src, srcSize, ZSTD_f_zstd1);
820 unsigned long long bound = 0;
822 while (srcSize > 0) {
823 ZSTD_frameSizeInfo const frameSizeInfo = ZSTD_findFrameSizeInfo(src, srcSize, ZSTD_f_zstd1);
828 assert(srcSize >= compressedSize);
829 src = (
const BYTE*)src + compressedSize;
830 srcSize -= compressedSize;
831 bound += decompressedBound;
839 unsigned maxBlockSize = 0;
842 while (srcSize > 0) {
843 ZSTD_frameSizeInfo const frameSizeInfo = ZSTD_findFrameSizeInfo(src, srcSize, ZSTD_f_zstd1);
846 ZSTD_frameHeader zfh;
850 return ERROR(corruption_detected);
852 if (zfh.frameType == ZSTD_frame) {
854 margin += zfh.headerSize;
856 margin += zfh.checksumFlag ? 4 : 0;
858 margin += 3 * frameSizeInfo.
nbBlocks;
861 maxBlockSize =
MAX(maxBlockSize, zfh.blockSizeMax);
863 assert(zfh.frameType == ZSTD_skippableFrame);
865 margin += compressedSize;
868 assert(srcSize >= compressedSize);
869 src = (
const BYTE*)src + compressedSize;
870 srcSize -= compressedSize;
874 margin += maxBlockSize;
887 DEBUGLOG(5,
"ZSTD_insertBlock: %u bytes", (
unsigned)blockSize);
894static size_t ZSTD_copyRawBlock(
void* dst,
size_t dstCapacity,
895 const void* src,
size_t srcSize)
900 if (srcSize == 0)
return 0;
907static size_t ZSTD_setRleBlock(
void* dst,
size_t dstCapacity,
913 if (regenSize == 0)
return 0;
920static void ZSTD_DCtx_trace_end(
ZSTD_DCtx const* dctx,
U64 uncompressedSize,
U64 compressedSize,
unsigned streaming)
923 if (dctx->traceCtx && ZSTD_trace_decompress_end != NULL) {
927 trace.streaming = streaming;
933 trace.uncompressedSize = (size_t)uncompressedSize;
934 trace.compressedSize = (size_t)compressedSize;
936 ZSTD_trace_decompress_end(dctx->traceCtx, &trace);
940 (void)uncompressedSize;
941 (void)compressedSize;
951static size_t ZSTD_decompressFrame(
ZSTD_DCtx* dctx,
952 void* dst,
size_t dstCapacity,
953 const void** srcPtr,
size_t *srcSizePtr)
955 const BYTE*
const istart = (
const BYTE*)(*srcPtr);
956 const BYTE* ip = istart;
958 BYTE*
const oend = dstCapacity != 0 ? ostart + dstCapacity : ostart;
960 size_t remainingSrcSize = *srcSizePtr;
962 DEBUGLOG(4,
"ZSTD_decompressFrame (srcSize:%i)", (
int)*srcSizePtr);
966 remainingSrcSize < ZSTD_FRAMEHEADERSIZE_MIN(dctx->
format)+ZSTD_blockHeaderSize,
970 {
size_t const frameHeaderSize = ZSTD_frameHeaderSize_internal(
971 ip, ZSTD_FRAMEHEADERSIZE_PREFIX(dctx->
format), dctx->
format);
972 if (
ZSTD_isError(frameHeaderSize))
return frameHeaderSize;
973 RETURN_ERROR_IF(remainingSrcSize < frameHeaderSize+ZSTD_blockHeaderSize,
976 ip += frameHeaderSize; remainingSrcSize -= frameHeaderSize;
985 BYTE* oBlockEnd = oend;
991 ip += ZSTD_blockHeaderSize;
992 remainingSrcSize -= ZSTD_blockHeaderSize;
995 if (ip >= op && ip < oBlockEnd) {
1009 oBlockEnd = op + (ip - op);
1020 decodedSize = ZSTD_copyRawBlock(op, (
size_t)(oend-op), ip, cBlockSize);
1023 decodedSize = ZSTD_setRleBlock(op, (
size_t)(oBlockEnd-op), *ip, blockProperties.
origSize);
1027 RETURN_ERROR(corruption_detected,
"invalid block type");
1030 DEBUGLOG(5,
"Decompressed block of dSize = %u", (
unsigned)decodedSize);
1039 remainingSrcSize -= cBlockSize;
1045 corruption_detected,
"");
1047 if (dctx->
fParams.checksumFlag) {
1056 remainingSrcSize -= 4;
1058 ZSTD_DCtx_trace_end(dctx, (
U64)(op-ostart), (
U64)(ip-istart), 0);
1060 DEBUGLOG(4,
"ZSTD_decompressFrame: decompressed frame of size %zi, consuming %zi bytes of input", op-ostart, ip - (
const BYTE*)*srcPtr);
1062 *srcSizePtr = remainingSrcSize;
1063 return (
size_t)(op-ostart);
1068size_t ZSTD_decompressMultiFrame(
ZSTD_DCtx* dctx,
1069 void* dst,
size_t dstCapacity,
1070 const void* src,
size_t srcSize,
1071 const void* dict,
size_t dictSize,
1074 void*
const dststart = dst;
1075 int moreThan1Frame = 0;
1077 DEBUGLOG(5,
"ZSTD_decompressMultiFrame");
1078 assert(dict==NULL || ddict==NULL);
1085 while (srcSize >= ZSTD_startingInputLength(dctx->
format)) {
1087#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT >= 1)
1088 if (dctx->
format == ZSTD_f_zstd1 && ZSTD_isLegacy(src, srcSize)) {
1090 size_t const frameSize = ZSTD_findFrameCompressedSizeLegacy(src, srcSize);
1093 "legacy support is not compatible with static dctx");
1095 decodedSize = ZSTD_decompressLegacy(dst, dstCapacity, src, frameSize, dict, dictSize);
1103 "Frame header size does not match decoded size!");
1107 assert(decodedSize <= dstCapacity);
1108 dst = (
BYTE*)dst + decodedSize;
1109 dstCapacity -= decodedSize;
1111 src = (
const BYTE*)src + frameSize;
1112 srcSize -= frameSize;
1118 if (dctx->
format == ZSTD_f_zstd1 && srcSize >= 4) {
1120 DEBUGLOG(5,
"reading magic number %08X", (
unsigned)magicNumber);
1123 size_t const skippableSize = readSkippableFrameSize(src, srcSize);
1125 assert(skippableSize <= srcSize);
1127 src = (
const BYTE *)src + skippableSize;
1128 srcSize -= skippableSize;
1142 {
const size_t res = ZSTD_decompressFrame(dctx, dst, dstCapacity,
1146 && (moreThan1Frame==1),
1148 "At least one frame successfully completed, "
1149 "but following bytes are garbage: "
1150 "it's more likely to be a srcSize error, "
1151 "specifying more input bytes than size of frame(s). "
1152 "Note: one could be unlucky, it might be a corruption error instead, "
1153 "happening right at the place where we expect zstd magic bytes. "
1154 "But this is _much_ less likely than a srcSize field error.");
1156 assert(res <= dstCapacity);
1158 dst = (
BYTE*)dst + res;
1164 RETURN_ERROR_IF(srcSize, srcSize_wrong,
"input not entirely consumed");
1166 return (
size_t)((
BYTE*)dst - (
BYTE*)dststart);
1170 void* dst,
size_t dstCapacity,
1171 const void* src,
size_t srcSize,
1172 const void* dict,
size_t dictSize)
1174 return ZSTD_decompressMultiFrame(dctx, dst, dstCapacity, src, srcSize, dict, dictSize, NULL);
1185 ZSTD_clearDict(dctx);
1201size_t ZSTD_decompress(
void* dst,
size_t dstCapacity,
const void* src,
size_t srcSize)
1203#if defined(ZSTD_HEAPMODE) && (ZSTD_HEAPMODE>=1)
1205 ZSTD_DCtx*
const dctx = ZSTD_createDCtx_internal(ZSTD_defaultCMem);
1212 ZSTD_initDCtx_internal(&dctx);
1234static size_t ZSTD_nextSrcSizeToDecompressWithInputSize(
ZSTD_DCtx* dctx,
size_t inputSize) {
1251 return ZSTDnit_frameHeader;
1253 return ZSTDnit_blockHeader;
1255 return ZSTDnit_block;
1257 return ZSTDnit_lastBlock;
1259 return ZSTDnit_checksum;
1263 return ZSTDnit_skippableFrame;
1275 DEBUGLOG(5,
"ZSTD_decompressContinue (srcSize:%u)", (
unsigned)srcSize);
1277 RETURN_ERROR_IF(srcSize != ZSTD_nextSrcSizeToDecompressWithInputSize(dctx, srcSize), srcSize_wrong,
"not allowed");
1282 switch (dctx->
stage)
1286 if (dctx->
format == ZSTD_f_zstd1) {
1290 dctx->
expected = ZSTD_SKIPPABLEHEADERSIZE - srcSize;
1294 dctx->
headerSize = ZSTD_frameHeaderSize_internal(src, srcSize, dctx->
format);
1305 dctx->
expected = ZSTD_blockHeaderSize;
1313 RETURN_ERROR_IF(cBlockSize > dctx->
fParams.blockSizeMax, corruption_detected,
"Block Size Exceeds Maximum");
1323 if (dctx->
fParams.checksumFlag) {
1331 dctx->
expected = ZSTD_blockHeaderSize;
1339 DEBUGLOG(5,
"ZSTD_decompressContinue: case ZSTDds_decompressBlock");
1344 DEBUGLOG(5,
"ZSTD_decompressContinue: case bt_compressed");
1350 assert(srcSize <= dctx->expected);
1351 rSize = ZSTD_copyRawBlock(dst, dstCapacity, src, srcSize);
1353 assert(rSize == srcSize);
1357 rSize = ZSTD_setRleBlock(dst, dstCapacity, *(
const BYTE*)src, dctx->
rleSize);
1362 RETURN_ERROR(corruption_detected,
"invalid block type");
1365 RETURN_ERROR_IF(rSize > dctx->
fParams.blockSizeMax, corruption_detected,
"Decompressed Block Size Exceeds Maximum");
1366 DEBUGLOG(5,
"ZSTD_decompressContinue: decoded size from block : %u", (
unsigned)rSize);
1377 DEBUGLOG(4,
"ZSTD_decompressContinue: decoded size from frame : %u", (
unsigned)dctx->
decodedSize);
1381 corruption_detected,
"");
1382 if (dctx->
fParams.checksumFlag) {
1392 dctx->
expected = ZSTD_blockHeaderSize;
1403 DEBUGLOG(4,
"ZSTD_decompressContinue: checksum : calculated %08X :: %08X read", (
unsigned)h32, (
unsigned)check32);
1414 assert(srcSize <= ZSTD_SKIPPABLEHEADERSIZE);
1433static size_t ZSTD_refDictContent(
ZSTD_DCtx* dctx,
const void* dict,
size_t dictSize)
1439#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
1440 dctx->dictContentBeginForFuzzing = dctx->
prefixStart;
1451 const void*
const dict,
size_t const dictSize)
1453 const BYTE* dictPtr = (
const BYTE*)dict;
1454 const BYTE*
const dictEnd = dictPtr + dictSize;
1456 RETURN_ERROR_IF(dictSize <= 8, dictionary_corrupted,
"dict is too small");
1463 {
void*
const workspace = &entropy->
LLTable;
1464 size_t const workspaceSize =
sizeof(entropy->
LLTable) +
sizeof(entropy->
OFTable) +
sizeof(entropy->
MLTable);
1465#ifdef HUF_FORCE_DECOMPRESS_X1
1468 dictPtr, dictEnd - dictPtr,
1469 workspace, workspaceSize, 0);
1472 dictPtr, (
size_t)(dictEnd - dictPtr),
1473 workspace, workspaceSize, 0);
1479 {
short offcodeNCount[
MaxOff+1];
1480 unsigned offcodeMaxValue =
MaxOff, offcodeLog;
1481 size_t const offcodeHeaderSize =
FSE_readNCount(offcodeNCount, &offcodeMaxValue, &offcodeLog, dictPtr, (
size_t)(dictEnd-dictPtr));
1486 offcodeNCount, offcodeMaxValue,
1491 dictPtr += offcodeHeaderSize;
1494 {
short matchlengthNCount[
MaxML+1];
1495 unsigned matchlengthMaxValue =
MaxML, matchlengthLog;
1496 size_t const matchlengthHeaderSize =
FSE_readNCount(matchlengthNCount, &matchlengthMaxValue, &matchlengthLog, dictPtr, (
size_t)(dictEnd-dictPtr));
1501 matchlengthNCount, matchlengthMaxValue,
1506 dictPtr += matchlengthHeaderSize;
1509 {
short litlengthNCount[
MaxLL+1];
1510 unsigned litlengthMaxValue =
MaxLL, litlengthLog;
1511 size_t const litlengthHeaderSize =
FSE_readNCount(litlengthNCount, &litlengthMaxValue, &litlengthLog, dictPtr, (
size_t)(dictEnd-dictPtr));
1516 litlengthNCount, litlengthMaxValue,
1521 dictPtr += litlengthHeaderSize;
1526 size_t const dictContentSize = (size_t)(dictEnd - (dictPtr+12));
1527 for (i=0; i<3; i++) {
1530 dictionary_corrupted,
"");
1531 entropy->
rep[i] = rep;
1534 return (
size_t)(dictPtr - (
const BYTE*)dict);
1537static size_t ZSTD_decompress_insertDictionary(
ZSTD_DCtx* dctx,
const void* dict,
size_t dictSize)
1539 if (dictSize < 8)
return ZSTD_refDictContent(dctx, dict, dictSize);
1542 return ZSTD_refDictContent(dctx, dict, dictSize);
1549 dict = (
const char*)dict + eSize;
1555 return ZSTD_refDictContent(dctx, dict, dictSize);
1562 dctx->traceCtx = (ZSTD_trace_decompress_begin != NULL) ? ZSTD_trace_decompress_begin(dctx) : 0;
1589 if (dict && dictSize)
1591 ZSTD_isError(ZSTD_decompress_insertDictionary(dctx, dict, dictSize)),
1592 dictionary_corrupted,
"");
1601 DEBUGLOG(4,
"ZSTD_decompressBegin_usingDDict");
1606 const void*
const dictEnd = dictStart + dictSize;
1624 if (dictSize < 8)
return 0;
1644 ZSTD_frameHeader zfp = { 0, 0, 0, ZSTD_frame, 0, 0, 0, 0, 0 };
1655 void* dst,
size_t dstCapacity,
1656 const void* src,
size_t srcSize,
1660 return ZSTD_decompressMultiFrame(dctx, dst, dstCapacity, src, srcSize,
1673 return ZSTD_createDCtx_internal(ZSTD_defaultCMem);
1683 return ZSTD_createDCtx_internal(customMem);
1698 const void* dict,
size_t dictSize,
1699 ZSTD_dictLoadMethod_e dictLoadMethod,
1700 ZSTD_dictContentType_e dictContentType)
1703 ZSTD_clearDict(dctx);
1704 if (dict && dictSize != 0) {
1741 DEBUGLOG(4,
"ZSTD_initDStream_usingDict");
1744 return ZSTD_startingInputLength(zds->
format);
1753 return ZSTD_startingInputLength(zds->
format);
1761 DEBUGLOG(4,
"ZSTD_initDStream_usingDDict");
1764 return ZSTD_startingInputLength(dctx->
format);
1774 return ZSTD_startingInputLength(dctx->
format);
1781 ZSTD_clearDict(dctx);
1783 dctx->
ddict = ddict;
1789 RETURN_ERROR(memory_allocation,
"Failed to allocate memory for hash set!");
1805 size_t const min = (size_t)1 << bounds.
lowerBound;
1806 size_t const max = (
size_t)1 << bounds.
upperBound;
1829 bounds.
upperBound = (int)ZSTD_f_zstd1_magicless;
1832 case ZSTD_d_stableOutBuffer:
1836 case ZSTD_d_forceIgnoreChecksum:
1837 bounds.
lowerBound = (int)ZSTD_d_validateChecksum;
1838 bounds.
upperBound = (int)ZSTD_d_ignoreChecksum;
1840 case ZSTD_d_refMultipleDDicts:
1841 bounds.
lowerBound = (int)ZSTD_rmd_refSingleDDict;
1842 bounds.
upperBound = (int)ZSTD_rmd_refMultipleDDicts;
1844 case ZSTD_d_disableHuffmanAssembly:
1848 case ZSTD_d_maxBlockSize:
1871#define CHECK_DBOUNDS(p,v) { \
1872 RETURN_ERROR_IF(!ZSTD_dParam_withinBounds(p, v), parameter_outOfBound, ""); \
1882 *value = (int)dctx->
format;
1884 case ZSTD_d_stableOutBuffer:
1887 case ZSTD_d_forceIgnoreChecksum:
1890 case ZSTD_d_refMultipleDDicts:
1893 case ZSTD_d_disableHuffmanAssembly:
1896 case ZSTD_d_maxBlockSize:
1909 if (value == 0)
value = ZSTD_WINDOWLOG_LIMIT_DEFAULT;
1915 dctx->
format = (ZSTD_format_e)value;
1917 case ZSTD_d_stableOutBuffer:
1921 case ZSTD_d_forceIgnoreChecksum:
1925 case ZSTD_d_refMultipleDDicts:
1928 RETURN_ERROR(parameter_unsupported,
"Static dctx does not support multiple DDicts!");
1932 case ZSTD_d_disableHuffmanAssembly:
1936 case ZSTD_d_maxBlockSize:
1956 ZSTD_clearDict(dctx);
1957 ZSTD_DCtx_resetParameters(dctx);
1968static size_t ZSTD_decodingBufferSize_internal(
unsigned long long windowSize,
unsigned long long frameContentSize,
size_t blockSizeMax)
1978 unsigned long long const neededRBSize = windowSize + (blockSize * 2) + (
WILDCOPY_OVERLENGTH * 2);
1979 unsigned long long const neededSize =
MIN(frameContentSize, neededRBSize);
1980 size_t const minRBSize = (size_t) neededSize;
1982 frameParameter_windowTooLarge,
"");
1988 return ZSTD_decodingBufferSize_internal(windowSize, frameContentSize,
ZSTD_BLOCKSIZE_MAX);
1994 size_t const inBuffSize = blockSize;
2001 U32 const windowSizeMax = 1U << ZSTD_WINDOWLOG_MAX;
2002 ZSTD_frameHeader zfh;
2007 frameParameter_windowTooLarge,
"");
2014static int ZSTD_DCtx_isOverflow(
ZSTD_DStream* zds,
size_t const neededInBuffSize,
size_t const neededOutBuffSize)
2019static void ZSTD_DCtx_updateOversizedDuration(
ZSTD_DStream* zds,
size_t const neededInBuffSize,
size_t const neededOutBuffSize)
2021 if (ZSTD_DCtx_isOverflow(zds, neededInBuffSize, neededOutBuffSize))
2027static int ZSTD_DCtx_isOversizedTooLong(
ZSTD_DStream* zds)
2047 RETURN_ERROR(dstBuffer_wrong,
"ZSTD_d_stableOutBuffer enabled but output differs!");
2055static size_t ZSTD_decompressContinueStream(
2057 void const* src,
size_t srcSize) {
2058 int const isSkipFrame = ZSTD_isSkipFrame(zds);
2064 if (!decodedSize && !isSkipFrame) {
2072 size_t const dstSize = isSkipFrame ? 0 : (size_t)(oend - *op);
2086 const char*
const src = (
const char*)
input->src;
2087 const char*
const istart =
input->pos != 0 ? src +
input->pos : src;
2088 const char*
const iend =
input->size != 0 ? src +
input->size : src;
2089 const char* ip = istart;
2090 char*
const dst = (
char*)
output->dst;
2091 char*
const ostart =
output->pos != 0 ? dst +
output->pos : dst;
2092 char*
const oend =
output->size != 0 ? dst +
output->size : dst;
2094 U32 someMoreWork = 1;
2096 DEBUGLOG(5,
"ZSTD_decompressStream");
2100 "forbidden. in: pos: %u vs size: %u",
2105 "forbidden. out: pos: %u vs size: %u",
2110 while (someMoreWork) {
2114 DEBUGLOG(5,
"stage zdss_init => transparent reset ");
2117#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT>=1)
2118 zds->legacyVersion = 0;
2125 DEBUGLOG(5,
"stage zdss_loadHeader (srcSize : %u)", (
U32)(iend - ip));
2126#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT>=1)
2127 if (zds->legacyVersion) {
2129 "legacy support is incompatible with static dctx");
2130 {
size_t const hint = ZSTD_decompressLegacyStream(zds->legacyContext, zds->legacyVersion,
output,
input);
2137 ZSTD_DCtx_selectFrameDDict(zds);
2140#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT>=1)
2141 U32 const legacyVersion = ZSTD_isLegacy(istart, iend-istart);
2142 if (legacyVersion) {
2143 ZSTD_DDict const*
const ddict = ZSTD_getDDict(zds);
2146 DEBUGLOG(5,
"ZSTD_decompressStream: detected legacy version v0.%u", legacyVersion);
2148 "legacy support is incompatible with static dctx");
2150 zds->previousLegacyVersion, legacyVersion,
2151 dict, dictSize),
"");
2152 zds->legacyVersion = zds->previousLegacyVersion = legacyVersion;
2153 {
size_t const hint = ZSTD_decompressLegacyStream(zds->legacyContext, legacyVersion,
output,
input);
2161 size_t const toLoad = hSize - zds->
lhSize;
2162 size_t const remainingInput = (size_t)(iend-ip);
2164 if (toLoad > remainingInput) {
2165 if (remainingInput > 0) {
2167 zds->
lhSize += remainingInput;
2173 "First few bytes detected incorrect" );
2175 return (
MAX((
size_t)ZSTD_FRAMEHEADERSIZE_MIN(zds->
format), hSize) - zds->
lhSize) + ZSTD_blockHeaderSize;
2184 && zds->
fParams.frameType != ZSTD_skippableFrame
2185 && (
U64)(
size_t)(oend-op) >= zds->
fParams.frameContentSize) {
2186 size_t const cSize = ZSTD_findFrameCompressedSize_advanced(istart, (
size_t)(iend-istart), zds->
format);
2187 if (cSize <= (
size_t)(iend-istart)) {
2190 if (
ZSTD_isError(decompressedSize))
return decompressedSize;
2191 DEBUGLOG(4,
"shortcut to single-pass ZSTD_decompress_usingDDict()");
2193 ip = istart + cSize;
2194 op = op ? op + decompressedSize : op;
2203 && zds->
fParams.frameType != ZSTD_skippableFrame
2205 && (
U64)(
size_t)(oend-op) < zds->
fParams.frameContentSize) {
2206 RETURN_ERROR(dstSize_tooSmall,
"ZSTD_obm_stable passed but ZSTD_outBuffer is too small");
2213 if (zds->
format == ZSTD_f_zstd1
2219 zds->
expected = ZSTD_blockHeaderSize;
2224 DEBUGLOG(4,
"Control max memory usage (%u KB <= max %u KB)",
2229 frameParameter_windowTooLarge,
"");
2234 {
size_t const neededInBuffSize =
MAX(zds->
fParams.blockSizeMax, 4 );
2236 ? ZSTD_decodingBufferSize_internal(zds->
fParams.windowSize, zds->
fParams.frameContentSize, zds->
fParams.blockSizeMax)
2239 ZSTD_DCtx_updateOversizedDuration(zds, neededInBuffSize, neededOutBuffSize);
2241 {
int const tooSmall = (zds->
inBuffSize < neededInBuffSize) || (zds->
outBuffSize < neededOutBuffSize);
2242 int const tooLarge = ZSTD_DCtx_isOversizedTooLong(zds);
2244 if (tooSmall || tooLarge) {
2245 size_t const bufferSize = neededInBuffSize + neededOutBuffSize;
2246 DEBUGLOG(4,
"inBuff : from %u to %u",
2248 DEBUGLOG(4,
"outBuff : from %u to %u",
2255 memory_allocation,
"");
2272 {
size_t const neededInSize = ZSTD_nextSrcSizeToDecompressWithInputSize(zds, (
size_t)(iend - ip));
2273 DEBUGLOG(5,
"neededInSize = %u", (
U32)neededInSize);
2274 if (neededInSize==0) {
2279 if ((
size_t)(iend-ip) >= neededInSize) {
2280 FORWARD_IF_ERROR(ZSTD_decompressContinueStream(zds, &op, oend, ip, neededInSize),
"");
2286 if (ip==iend) { someMoreWork = 0;
break; }
2292 size_t const toLoad = neededInSize - zds->
inPos;
2293 int const isSkipFrame = ZSTD_isSkipFrame(zds);
2296 assert(neededInSize == ZSTD_nextSrcSizeToDecompressWithInputSize(zds, (
size_t)(iend - ip)));
2298 loadedSize =
MIN(toLoad, (
size_t)(iend-ip));
2301 corruption_detected,
2302 "should never happen");
2305 if (loadedSize != 0) {
2308 zds->
inPos += loadedSize;
2310 if (loadedSize < toLoad) { someMoreWork = 0;
break; }
2323 op = op ? op + flushedSize : op;
2326 if (flushedSize == toFlushSize) {
2330 DEBUGLOG(5,
"restart filling outBuff from beginning (left:%i, needed:%u)",
2347 input->pos = (size_t)(ip - (
const char*)(
input->src));
2353 if ((ip==istart) && (op==ostart)) {
2364 if (!nextSrcSizeHint) {
2382 nextSrcSizeHint += ZSTD_blockHeaderSize * (
ZSTD_nextInputType(zds) == ZSTDnit_block);
2384 nextSrcSizeHint -= zds->
inPos;
2385 return nextSrcSizeHint;
2391 void* dst,
size_t dstCapacity,
size_t* dstPos,
2392 const void* src,
size_t srcSize,
size_t* srcPos)
2397 output.size = dstCapacity;
2400 input.size = srcSize;
2401 input.pos = *srcPos;
2404 *srcPos =
input.pos;
MEM_STATIC void ZSTD_customFree(void *ptr, ZSTD_customMem customMem)
MEM_STATIC void * ZSTD_customMalloc(size_t size, ZSTD_customMem customMem)
MEM_STATIC void * ZSTD_customCalloc(size_t size, ZSTD_customMem customMem)
MEM_STATIC unsigned ZSTD_highbit32(U32 val)
#define ZSTD_ALLOW_POINTER_OVERFLOW_ATTR
#define assert(condition)
size_t FSE_readNCount(short *normalizedCounter, unsigned *maxSVPtr, unsigned *tableLogPtr, const void *headerBuffer, size_t hbSize)
#define RETURN_ERROR(err,...)
#define FORWARD_IF_ERROR(err,...)
#define RETURN_ERROR_IF(cond, err,...)
size_t HUF_readDTableX2_wksp(HUF_DTable *DTable, const void *src, size_t srcSize, void *workSpace, size_t wkspSize, int flags)
#define HUF_DECOMPRESS_WORKSPACE_SIZE
size_t HUF_readDTableX1_wksp(HUF_DTable *DTable, const void *src, size_t srcSize, void *workSpace, size_t wkspSize, int flags)
MEM_STATIC void MEM_writeLE32(void *memPtr, U32 val32)
MEM_STATIC U16 MEM_readLE16(const void *memPtr)
MEM_STATIC U64 MEM_readLE64(const void *memPtr)
MEM_STATIC U32 MEM_readLE32(const void *memPtr)
ZSTD_refMultipleDDicts_e refMultipleDDicts
const HUF_DTable * HUFptr
ZSTD_dStreamStage streamStage
ZSTD_DDictHashSet * ddictSet
const ZSTD_seqSymbol * MLTptr
const void * virtualStart
const ZSTD_seqSymbol * OFTptr
ZSTD_entropyDTables_t entropy
ZSTD_bufferMode_e outBufferMode
ZSTD_outBuffer expectedOutBuffer
BYTE headerBuffer[ZSTD_FRAMEHEADERSIZE_MAX]
const void * previousDstEnd
const ZSTD_seqSymbol * LLTptr
ZSTD_forceIgnoreChecksum_e forceIgnoreChecksum
const ZSTD_DDict ** ddictPtrTable
HUF_DTable hufTable[HUF_DTABLE_SIZE(ZSTD_HUFFDTABLE_CAPACITY_LOG)]
U32 workspace[ZSTD_BUILD_FSE_TABLE_WKSP_SIZE_U32]
ZSTD_seqSymbol LLTable[SEQSYMBOL_TABLE_SIZE(LLFSELog)]
ZSTD_seqSymbol MLTable[SEQSYMBOL_TABLE_SIZE(MLFSELog)]
ZSTD_seqSymbol OFTable[SEQSYMBOL_TABLE_SIZE(OffFSELog)]
unsigned long long decompressedBound
#define ZSTD_VERSION_NUMBER
#define ZSTD_CONTENTSIZE_UNKNOWN
#define ZSTD_MAGIC_DICTIONARY
#define ZSTD_MAGIC_SKIPPABLE_MASK
struct ZSTD_DCtx_s ZSTD_DCtx
#define ZSTD_CONTENTSIZE_ERROR
@ ZSTD_reset_session_only
@ ZSTD_reset_session_and_parameters
#define ZSTD_BLOCKSIZE_MAX
#define ZSTD_MAGIC_SKIPPABLE_START
ZSTD_ErrorCode ZSTD_getErrorCode(size_t code)
ZSTD_DDict * ZSTD_createDDict_advanced(const void *dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType, ZSTD_customMem customMem)
unsigned ZSTD_getDictID_fromDDict(const ZSTD_DDict *ddict)
void ZSTD_copyDDictParameters(ZSTD_DCtx *dctx, const ZSTD_DDict *ddict)
size_t ZSTD_freeDDict(ZSTD_DDict *ddict)
const void * ZSTD_DDict_dictContent(const ZSTD_DDict *ddict)
size_t ZSTD_DDict_dictSize(const ZSTD_DDict *ddict)
size_t ZSTD_sizeof_DDict(const ZSTD_DDict *ddict)
size_t ZSTD_DCtx_loadDictionary_advanced(ZSTD_DCtx *dctx, const void *dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType)
size_t ZSTD_nextSrcSizeToDecompress(ZSTD_DCtx *dctx)
size_t ZSTD_decodingBufferSize_min(unsigned long long windowSize, unsigned long long frameContentSize)
size_t ZSTD_DCtx_getParameter(ZSTD_DCtx *dctx, ZSTD_dParameter param, int *value)
ZSTD_bounds ZSTD_dParam_getBounds(ZSTD_dParameter dParam)
#define CHECK_DBOUNDS(p, v)
size_t ZSTD_DCtx_loadDictionary_byReference(ZSTD_DCtx *dctx, const void *dict, size_t dictSize)
size_t ZSTD_decompressionMargin(void const *src, size_t srcSize)
size_t ZSTD_decompressBegin_usingDDict(ZSTD_DCtx *dctx, const ZSTD_DDict *ddict)
ZSTD_DCtx * ZSTD_initStaticDCtx(void *workspace, size_t workspaceSize)
ZSTD_DStream * ZSTD_createDStream(void)
size_t ZSTD_DCtx_loadDictionary(ZSTD_DCtx *dctx, const void *dict, size_t dictSize)
size_t ZSTD_freeDStream(ZSTD_DStream *zds)
size_t ZSTD_estimateDStreamSize_fromFrame(const void *src, size_t srcSize)
size_t ZSTD_DCtx_refPrefix(ZSTD_DCtx *dctx, const void *prefix, size_t prefixSize)
ZSTD_nextInputType_e ZSTD_nextInputType(ZSTD_DCtx *dctx)
size_t ZSTD_decompressStream(ZSTD_DStream *zds, ZSTD_outBuffer *output, ZSTD_inBuffer *input)
size_t ZSTD_decompressBegin(ZSTD_DCtx *dctx)
size_t ZSTD_estimateDCtxSize(void)
ZSTD_DStream * ZSTD_createDStream_advanced(ZSTD_customMem customMem)
size_t ZSTD_freeDCtx(ZSTD_DCtx *dctx)
size_t ZSTD_DCtx_reset(ZSTD_DCtx *dctx, ZSTD_ResetDirective reset)
size_t ZSTD_decompress_usingDict(ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const void *dict, size_t dictSize)
unsigned long long ZSTD_getDecompressedSize(const void *src, size_t srcSize)
size_t ZSTD_initDStream(ZSTD_DStream *zds)
#define DDICT_HASHSET_MAX_LOAD_FACTOR_COUNT_MULT
size_t ZSTD_loadDEntropy(ZSTD_entropyDTables_t *entropy, const void *const dict, size_t const dictSize)
size_t ZSTD_sizeof_DCtx(const ZSTD_DCtx *dctx)
size_t ZSTD_getFrameHeader_advanced(ZSTD_frameHeader *zfhPtr, const void *src, size_t srcSize, ZSTD_format_e format)
ZSTD_DStream * ZSTD_initStaticDStream(void *workspace, size_t workspaceSize)
void ZSTD_copyDCtx(ZSTD_DCtx *dstDCtx, const ZSTD_DCtx *srcDCtx)
#define DDICT_HASHSET_TABLE_BASE_SIZE
size_t ZSTD_DCtx_refPrefix_advanced(ZSTD_DCtx *dctx, const void *prefix, size_t prefixSize, ZSTD_dictContentType_e dictContentType)
size_t ZSTD_decompressBegin_usingDict(ZSTD_DCtx *dctx, const void *dict, size_t dictSize)
unsigned ZSTD_getDictID_fromFrame(const void *src, size_t srcSize)
size_t ZSTD_resetDStream(ZSTD_DStream *dctx)
unsigned ZSTD_isSkippableFrame(const void *buffer, size_t size)
size_t ZSTD_DCtx_setFormat(ZSTD_DCtx *dctx, ZSTD_format_e format)
size_t ZSTD_DStreamOutSize(void)
size_t ZSTD_frameHeaderSize(const void *src, size_t srcSize)
size_t ZSTD_estimateDStreamSize(size_t windowSize)
unsigned long long ZSTD_getFrameContentSize(const void *src, size_t srcSize)
unsigned ZSTD_getDictID_fromDict(const void *dict, size_t dictSize)
size_t ZSTD_DCtx_refDDict(ZSTD_DCtx *dctx, const ZSTD_DDict *ddict)
size_t ZSTD_decompress(void *dst, size_t dstCapacity, const void *src, size_t srcSize)
unsigned long long ZSTD_findDecompressedSize(const void *src, size_t srcSize)
size_t ZSTD_DStreamInSize(void)
size_t ZSTD_findFrameCompressedSize(const void *src, size_t srcSize)
#define DDICT_HASHSET_RESIZE_FACTOR
size_t ZSTD_initDStream_usingDDict(ZSTD_DStream *dctx, const ZSTD_DDict *ddict)
size_t ZSTD_getFrameHeader(ZSTD_frameHeader *zfhPtr, const void *src, size_t srcSize)
size_t ZSTD_initDStream_usingDict(ZSTD_DStream *zds, const void *dict, size_t dictSize)
unsigned ZSTD_isFrame(const void *buffer, size_t size)
size_t ZSTD_decompressStream_simpleArgs(ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, size_t *dstPos, const void *src, size_t srcSize, size_t *srcPos)
size_t ZSTD_insertBlock(ZSTD_DCtx *dctx, const void *blockStart, size_t blockSize)
size_t ZSTD_DCtx_setParameter(ZSTD_DCtx *dctx, ZSTD_dParameter dParam, int value)
size_t ZSTD_decompressDCtx(ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize)
ZSTD_DCtx * ZSTD_createDCtx(void)
unsigned long long ZSTD_decompressBound(const void *src, size_t srcSize)
size_t ZSTD_decompress_usingDDict(ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const ZSTD_DDict *ddict)
#define ZSTD_NO_FORWARD_PROGRESS_MAX
ZSTD_DCtx * ZSTD_createDCtx_advanced(ZSTD_customMem customMem)
size_t ZSTD_DCtx_setMaxWindowSize(ZSTD_DCtx *dctx, size_t maxWindowSize)
#define DDICT_HASHSET_MAX_LOAD_FACTOR_SIZE_MULT
size_t ZSTD_decompressContinue(ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize)
size_t ZSTD_readSkippableFrame(void *dst, size_t dstCapacity, unsigned *magicVariant, const void *src, size_t srcSize)
#define ZSTD_MAXWINDOWSIZE_DEFAULT
size_t ZSTD_sizeof_DStream(const ZSTD_DStream *dctx)
ZSTD_ALLOW_POINTER_OVERFLOW_ATTR void ZSTD_checkContinuity(ZSTD_DCtx *dctx, const void *dst, size_t dstSize)
void ZSTD_buildFSETable(ZSTD_seqSymbol *dt, const short *normalizedCounter, unsigned maxSymbolValue, const U32 *baseValue, const U8 *nbAdditionalBits, unsigned tableLog, void *wksp, size_t wkspSize, int bmi2)
size_t ZSTD_decompressBlock_internal(ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const streaming_operation streaming)
#define ZSTD_HUFFDTABLE_CAPACITY_LOG
@ ZSTDds_getFrameHeaderSize
@ ZSTDds_decodeBlockHeader
@ ZSTDds_decompressLastBlock
@ ZSTDds_decodeFrameHeader
@ ZSTDds_decodeSkippableHeader
#define ZSTD_memmove(d, s, l)
#define ZSTD_memcpy(d, s, l)
#define ZSTD_memset(p, v, l)
@ ZSTD_error_prefix_unknown
#define ZSTD_WORKSPACETOOLARGE_MAXDURATION
#define WILDCOPY_OVERLENGTH
MEM_STATIC int ZSTD_cpuSupportsBmi2(void)
#define ZSTD_WINDOWLOG_ABSOLUTEMIN
MEM_STATIC size_t ZSTD_limitCopy(void *dst, size_t dstCapacity, const void *src, size_t srcSize)
#define BOUNDED(min, val, max)
#define ZSTD_STATIC_ASSERT(c)
size_t ZSTD_getcBlockSize(const void *src, size_t srcSize, blockProperties_t *bpPtr)
#define ZSTD_WORKSPACETOOLARGE_FACTOR