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_DEFAULTMAX) + 1) 50 #ifndef ZSTD_NO_FORWARD_PROGRESS_MAX 51 # define ZSTD_NO_FORWARD_PROGRESS_MAX 16 62 #define FSE_STATIC_LINKING_ONLY 64 #define HUF_STATIC_LINKING_ONLY 68 #if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT>=1) 69 # include "zstd_legacy.h" 79 #define ZSTD_isError ERR_isError 80 #define FSE_isError ERR_isError 81 #define HUF_isError ERR_isError 114 #define SEQSYMBOL_TABLE_SIZE(log) (1 + (1 << (log))) 120 HUF_DTable hufTable[HUF_DTABLE_SIZE(
HufLog)];
183 if (dctx==
NULL)
return 0;
194 size_t const startingInputLength = (
format==ZSTD_f_zstd1_magicless) ?
196 ZSTD_frameHeaderSize_prefix;
200 return startingInputLength;
205 dctx->
format = ZSTD_f_zstd1;
226 if ((
size_t)workspace & 7)
return NULL;
231 dctx->
inBuff = (
char*)(dctx+1);
237 if (!customMem.customAlloc ^ !customMem.customFree)
return NULL;
240 if (!dctx)
return NULL;
255 if (dctx==
NULL)
return 0;
257 { ZSTD_customMem
const cMem = dctx->
customMem;
262 #if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT >= 1) 274 size_t const toCopy = (
size_t)((
char*)(&dstDCtx->
inBuff) - (
char*)dstDCtx);
275 memcpy(dstDCtx, srcDCtx, toCopy);
292 if (
magic == ZSTD_MAGICNUMBER)
return 1;
293 if ((
magic & 0xFFFFFFF0U) == ZSTD_MAGIC_SKIPPABLE_START)
return 1;
295 #if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT >= 1) 309 if (srcSize < minInputSize)
return ERROR(srcSize_wrong);
311 {
BYTE const fhd = ((
const BYTE*)
src)[minInputSize-1];
312 U32 const dictID= fhd & 3;
313 U32 const singleSegment = (fhd >> 5) & 1;
314 U32 const fcsId = fhd >> 6;
315 return minInputSize + !singleSegment
317 + (singleSegment && !fcsId);
342 memset(zfhPtr, 0,
sizeof(*zfhPtr));
343 if (srcSize < minInputSize)
return minInputSize;
346 if ( (
format != ZSTD_f_zstd1_magicless)
350 if (srcSize < ZSTD_skippableHeaderSize)
351 return ZSTD_skippableHeaderSize;
352 memset(zfhPtr, 0,
sizeof(*zfhPtr));
354 zfhPtr->frameType = ZSTD_skippableFrame;
357 return ERROR(prefix_unknown);
362 if (srcSize < fhsize)
return fhsize;
363 zfhPtr->headerSize = (
U32)fhsize;
366 {
BYTE const fhdByte =
ip[minInputSize-1];
367 size_t pos = minInputSize;
368 U32 const dictIDSizeCode = fhdByte&3;
369 U32 const checksumFlag = (fhdByte>>2)&1;
370 U32 const singleSegment = (fhdByte>>5)&1;
371 U32 const fcsID = fhdByte>>6;
375 if ((fhdByte & 0x08) != 0)
376 return ERROR(frameParameter_unsupported);
378 if (!singleSegment) {
381 if (windowLog > ZSTD_WINDOWLOG_MAX)
382 return ERROR(frameParameter_windowTooLarge);
383 windowSize = (1
ULL << windowLog);
384 windowSize += (windowSize >> 3) * (wlByte&7);
386 switch(dictIDSizeCode)
390 case 1 : dictID =
ip[
pos];
pos++;
break;
397 case 0 :
if (singleSegment) frameContentSize =
ip[
pos];
break;
402 if (singleSegment) windowSize = frameContentSize;
404 zfhPtr->frameType = ZSTD_frame;
405 zfhPtr->frameContentSize = frameContentSize;
406 zfhPtr->windowSize = windowSize;
407 zfhPtr->blockSizeMax = (
unsigned)
MIN(windowSize, ZSTD_BLOCKSIZE_MAX);
408 zfhPtr->dictID = dictID;
409 zfhPtr->checksumFlag = checksumFlag;
433 #if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT >= 1) 434 if (ZSTD_isLegacy(
src, srcSize)) {
435 unsigned long long const ret = ZSTD_getDecompressedSize_legacy(
src, srcSize);
439 { ZSTD_frameHeader zfh;
442 if (zfh.frameType == ZSTD_skippableFrame) {
445 return zfh.frameContentSize;
456 unsigned long long totalDstSize = 0;
458 while (srcSize >= ZSTD_frameHeaderSize_prefix) {
461 if ((magicNumber & 0xFFFFFFF0U) == ZSTD_MAGIC_SKIPPABLE_START) {
462 size_t skippableSize;
463 if (srcSize < ZSTD_skippableHeaderSize)
464 return ERROR(srcSize_wrong);
466 + ZSTD_skippableHeaderSize;
467 if (srcSize < skippableSize) {
472 srcSize -= skippableSize;
489 srcSize -= frameSrcSize;
523 return ERROR(dictionary_wrong);
540 U32 const cSize = cBlockHeader >> 3;
552 const void*
src,
size_t srcSize)
555 if (srcSize > dstCapacity)
return ERROR(dstSize_tooSmall);
562 const void*
src,
size_t srcSize,
565 if (srcSize != 1)
return ERROR(srcSize_wrong);
566 if (regenSize > dstCapacity)
return ERROR(dstSize_tooSmall);
573 const void*
src,
size_t srcSize);
578 const void*
src,
size_t srcSize)
592 if (srcSize < 5)
return ERROR(corruption_detected);
593 {
size_t lhSize, litSize, litCSize;
595 U32 const lhlCode = (istart[0] >> 2) & 3;
599 case 0:
case 1:
default:
601 singleStream = !lhlCode;
603 litSize = (lhc >> 4) & 0x3FF;
604 litCSize = (lhc >> 14) & 0x3FF;
609 litSize = (lhc >> 4) & 0x3FFF;
610 litCSize = lhc >> 18;
615 litSize = (lhc >> 4) & 0x3FFFF;
616 litCSize = (lhc >> 22) + (istart[4] << 10);
619 if (litSize > ZSTD_BLOCKSIZE_MAX)
return ERROR(corruption_detected);
620 if (litCSize + lhSize > srcSize)
return ERROR(corruption_detected);
636 return ERROR(corruption_detected);
643 return litCSize + lhSize;
647 {
size_t litSize, lhSize;
648 U32 const lhlCode = ((istart[0]) >> 2) & 3;
651 case 0:
case 2:
default:
653 litSize = istart[0] >> 3;
666 if (litSize+lhSize > srcSize)
return ERROR(corruption_detected);
671 return lhSize+litSize;
674 dctx->
litPtr = istart+lhSize;
676 return lhSize+litSize;
680 {
U32 const lhlCode = ((istart[0]) >> 2) & 3;
681 size_t litSize, lhSize;
684 case 0:
case 2:
default:
686 litSize = istart[0] >> 3;
695 if (srcSize<4)
return ERROR(corruption_detected);
698 if (litSize > ZSTD_BLOCKSIZE_MAX)
return ERROR(corruption_detected);
705 return ERROR(corruption_detected);
723 { 0, 0, 4, 0}, { 16, 0, 4, 0},
724 { 32, 0, 5, 1}, { 0, 0, 5, 3},
725 { 0, 0, 5, 4}, { 0, 0, 5, 6},
726 { 0, 0, 5, 7}, { 0, 0, 5, 9},
727 { 0, 0, 5, 10}, { 0, 0, 5, 12},
728 { 0, 0, 6, 14}, { 0, 1, 5, 16},
729 { 0, 1, 5, 20}, { 0, 1, 5, 22},
730 { 0, 2, 5, 28}, { 0, 3, 5, 32},
731 { 0, 4, 5, 48}, { 32, 6, 5, 64},
732 { 0, 7, 5, 128}, { 0, 8, 6, 256},
733 { 0, 10, 6, 1024}, { 0, 12, 6, 4096},
734 { 32, 0, 4, 0}, { 0, 0, 4, 1},
735 { 0, 0, 5, 2}, { 32, 0, 5, 4},
736 { 0, 0, 5, 5}, { 32, 0, 5, 7},
737 { 0, 0, 5, 8}, { 32, 0, 5, 10},
738 { 0, 0, 5, 11}, { 0, 0, 6, 13},
739 { 32, 1, 5, 16}, { 0, 1, 5, 18},
740 { 32, 1, 5, 22}, { 0, 2, 5, 24},
741 { 32, 3, 5, 32}, { 0, 3, 5, 40},
742 { 0, 6, 4, 64}, { 16, 6, 4, 64},
743 { 32, 7, 5, 128}, { 0, 9, 6, 512},
744 { 0, 11, 6, 2048}, { 48, 0, 4, 0},
745 { 16, 0, 4, 1}, { 32, 0, 5, 2},
746 { 32, 0, 5, 3}, { 32, 0, 5, 5},
747 { 32, 0, 5, 6}, { 32, 0, 5, 8},
748 { 32, 0, 5, 9}, { 32, 0, 5, 11},
749 { 32, 0, 5, 12}, { 0, 0, 6, 15},
750 { 32, 1, 5, 18}, { 32, 1, 5, 20},
751 { 32, 2, 5, 24}, { 32, 2, 5, 28},
752 { 32, 3, 5, 40}, { 32, 4, 5, 48},
753 { 0, 16, 6,65536}, { 0, 15, 6,32768},
754 { 0, 14, 6,16384}, { 0, 13, 6, 8192},
761 { 0, 0, 5, 0}, { 0, 6, 4, 61},
762 { 0, 9, 5, 509}, { 0, 15, 5,32765},
763 { 0, 21, 5,2097149}, { 0, 3, 5, 5},
764 { 0, 7, 4, 125}, { 0, 12, 5, 4093},
765 { 0, 18, 5,262141}, { 0, 23, 5,8388605},
766 { 0, 5, 5, 29}, { 0, 8, 4, 253},
767 { 0, 14, 5,16381}, { 0, 20, 5,1048573},
768 { 0, 2, 5, 1}, { 16, 7, 4, 125},
769 { 0, 11, 5, 2045}, { 0, 17, 5,131069},
770 { 0, 22, 5,4194301}, { 0, 4, 5, 13},
771 { 16, 8, 4, 253}, { 0, 13, 5, 8189},
772 { 0, 19, 5,524285}, { 0, 1, 5, 1},
773 { 16, 6, 4, 61}, { 0, 10, 5, 1021},
774 { 0, 16, 5,65533}, { 0, 28, 5,268435453},
775 { 0, 27, 5,134217725}, { 0, 26, 5,67108861},
776 { 0, 25, 5,33554429}, { 0, 24, 5,16777213},
784 { 0, 0, 6, 3}, { 0, 0, 4, 4},
785 { 32, 0, 5, 5}, { 0, 0, 5, 6},
786 { 0, 0, 5, 8}, { 0, 0, 5, 9},
787 { 0, 0, 5, 11}, { 0, 0, 6, 13},
788 { 0, 0, 6, 16}, { 0, 0, 6, 19},
789 { 0, 0, 6, 22}, { 0, 0, 6, 25},
790 { 0, 0, 6, 28}, { 0, 0, 6, 31},
791 { 0, 0, 6, 34}, { 0, 1, 6, 37},
792 { 0, 1, 6, 41}, { 0, 2, 6, 47},
793 { 0, 3, 6, 59}, { 0, 4, 6, 83},
794 { 0, 7, 6, 131}, { 0, 9, 6, 515},
795 { 16, 0, 4, 4}, { 0, 0, 4, 5},
796 { 32, 0, 5, 6}, { 0, 0, 5, 7},
797 { 32, 0, 5, 9}, { 0, 0, 5, 10},
798 { 0, 0, 6, 12}, { 0, 0, 6, 15},
799 { 0, 0, 6, 18}, { 0, 0, 6, 21},
800 { 0, 0, 6, 24}, { 0, 0, 6, 27},
801 { 0, 0, 6, 30}, { 0, 0, 6, 33},
802 { 0, 1, 6, 35}, { 0, 1, 6, 39},
803 { 0, 2, 6, 43}, { 0, 3, 6, 51},
804 { 0, 4, 6, 67}, { 0, 5, 6, 99},
805 { 0, 8, 6, 259}, { 32, 0, 4, 4},
806 { 48, 0, 4, 4}, { 16, 0, 4, 5},
807 { 32, 0, 5, 7}, { 32, 0, 5, 8},
808 { 32, 0, 5, 10}, { 32, 0, 5, 11},
809 { 0, 0, 6, 14}, { 0, 0, 6, 17},
810 { 0, 0, 6, 20}, { 0, 0, 6, 23},
811 { 0, 0, 6, 26}, { 0, 0, 6, 29},
812 { 0, 0, 6, 32}, { 0, 16, 6,65539},
813 { 0, 15, 6,32771}, { 0, 14, 6,16387},
814 { 0, 13, 6, 8195}, { 0, 12, 6, 4099},
815 { 0, 11, 6, 2051}, { 0, 10, 6, 1027},
840 const short* normalizedCounter,
unsigned maxSymbolValue,
841 const U32* baseValue,
const U32* nbAdditionalBits,
847 U32 const maxSV1 = maxSymbolValue + 1;
848 U32 const tableSize = 1 << tableLog;
849 U32 highThreshold = tableSize-1;
859 {
S16 const largeLimit= (
S16)(1 << (tableLog-1));
861 for (
s=0;
s<maxSV1;
s++) {
862 if (normalizedCounter[
s]==-1) {
866 if (normalizedCounter[
s] >= largeLimit) DTableH.
fastMode=0;
867 symbolNext[
s] = normalizedCounter[
s];
869 memcpy(dt, &DTableH,
sizeof(DTableH));
873 {
U32 const tableMask = tableSize-1;
874 U32 const step = FSE_TABLESTEP(tableSize);
876 for (
s=0;
s<maxSV1;
s++) {
878 for (
i=0;
i<normalizedCounter[
s];
i++) {
880 position = (position + step) & tableMask;
881 while (position > highThreshold) position = (position + step) & tableMask;
888 for (
u=0;
u<tableSize;
u++) {
890 U32 const nextState = symbolNext[symbol]++;
892 tableDecode[
u].
nextState = (
U16) ( (nextState << tableDecode[
u].nbBits) - tableSize);
893 assert(nbAdditionalBits[symbol] < 255);
905 const void*
src,
size_t srcSize,
906 const U32* baseValue,
const U32* nbAdditionalBits,
908 int ddictIsCold,
int nbSeq)
913 if (!srcSize)
return ERROR(srcSize_wrong);
916 U32 const baseline = baseValue[symbol];
917 U32 const nbBits = nbAdditionalBits[symbol];
920 *DTablePtr = DTableSpace;
923 *DTablePtr = defaultTable;
926 if (!flagRepeatTable)
return ERROR(corruption_detected);
928 if (ddictIsCold && (nbSeq > 24 )) {
929 const void*
const pStart = *DTablePtr;
939 if (tableLog > maxLog)
return ERROR(corruption_detected);
941 *DTablePtr = DTableSpace;
946 return ERROR(GENERIC);
951 0, 1, 2, 3, 4, 5, 6, 7,
952 8, 9, 10, 11, 12, 13, 14, 15,
953 16, 18, 20, 22, 24, 28, 32, 40,
954 48, 64, 0x80, 0x100, 0x200, 0x400, 0x800, 0x1000,
955 0x2000, 0x4000, 0x8000, 0x10000 };
958 0, 1, 1, 5, 0xD, 0x1D, 0x3D, 0x7D,
959 0xFD, 0x1FD, 0x3FD, 0x7FD, 0xFFD, 0x1FFD, 0x3FFD, 0x7FFD,
960 0xFFFD, 0x1FFFD, 0x3FFFD, 0x7FFFD, 0xFFFFD, 0x1FFFFD, 0x3FFFFD, 0x7FFFFD,
961 0xFFFFFD, 0x1FFFFFD, 0x3FFFFFD, 0x7FFFFFD, 0xFFFFFFD, 0x1FFFFFFD, 0x3FFFFFFD, 0x7FFFFFFD };
964 0, 1, 2, 3, 4, 5, 6, 7,
965 8, 9, 10, 11, 12, 13, 14, 15,
966 16, 17, 18, 19, 20, 21, 22, 23,
967 24, 25, 26, 27, 28, 29, 30, 31 };
970 3, 4, 5, 6, 7, 8, 9, 10,
971 11, 12, 13, 14, 15, 16, 17, 18,
972 19, 20, 21, 22, 23, 24, 25, 26,
973 27, 28, 29, 30, 31, 32, 33, 34,
974 35, 37, 39, 41, 43, 47, 51, 59,
975 67, 83, 99, 0x83, 0x103, 0x203, 0x403, 0x803,
976 0x1003, 0x2003, 0x4003, 0x8003, 0x10003 };
980 const void*
src,
size_t srcSize);
983 const void*
src,
size_t srcSize)
986 const BYTE*
const iend = istart + srcSize;
989 DEBUGLOG(5,
"ZSTD_decodeSeqHeaders");
996 if (!nbSeq) { *nbSeqPtr=0;
return 1; }
999 if (
ip+2 > iend)
return ERROR(srcSize_wrong);
1002 if (
ip >= iend)
return ERROR(srcSize_wrong);
1003 nbSeq = ((nbSeq-0x80)<<8) + *
ip++;
1009 if (
ip+4 > iend)
return ERROR(srcSize_wrong);
1050 size_t const psmin =
MIN(dictSize, (
size_t)(64*nbSeq) );
1051 size_t const pSize =
MIN(psmin, 128
KB );
1052 const void*
const pStart = (
const char*)dctx->
dictEnd - pSize;
1088 const BYTE** litPtr,
const BYTE*
const litLimit,
1089 const BYTE*
const base,
const BYTE*
const vBase,
const BYTE*
const dictEnd)
1093 BYTE*
const oMatchEnd =
op + sequenceLength;
1095 const BYTE*
const iLitEnd = *litPtr +
sequence.litLength;
1099 if (oMatchEnd>oend)
return ERROR(dstSize_tooSmall);
1100 if (iLitEnd > litLimit)
return ERROR(corruption_detected);
1101 if (oLitEnd <= oend_w)
return ERROR(GENERIC);
1106 *litPtr += oend_w -
op;
1109 while (
op < oLitEnd) *
op++ = *(*litPtr)++;
1114 if (
sequence.offset > (
size_t)(oLitEnd - vBase))
return ERROR(corruption_detected);
1118 return sequenceLength;
1121 {
size_t const length1 = dictEnd -
match;
1123 op = oLitEnd + length1;
1127 while (
op < oMatchEnd) *
op++ = *
match++;
1128 return sequenceLength;
1135 const BYTE** litPtr,
const BYTE*
const litLimit,
1136 const BYTE*
const prefixStart,
const BYTE*
const virtualStart,
const BYTE*
const dictEnd)
1140 BYTE*
const oMatchEnd =
op + sequenceLength;
1142 const BYTE*
const iLitEnd = *litPtr +
sequence.litLength;
1146 if (oMatchEnd>oend)
return ERROR(dstSize_tooSmall);
1147 if (iLitEnd > litLimit)
return ERROR(corruption_detected);
1158 if (
sequence.offset > (
size_t)(oLitEnd - prefixStart)) {
1160 if (
sequence.offset > (
size_t)(oLitEnd - virtualStart))
1161 return ERROR(corruption_detected);
1165 return sequenceLength;
1168 {
size_t const length1 = dictEnd -
match;
1170 op = oLitEnd + length1;
1172 match = prefixStart;
1176 return sequenceLength;
1184 static const U32 dec32table[] = { 0, 1, 2, 1, 4, 4, 4, 4 };
1185 static const int dec64table[] = { 8, 8, 8, 7, 8, 9,10,11 };
1186 int const sub2 = dec64table[
sequence.offset];
1199 if (oMatchEnd > oend-(16-
MINMATCH)) {
1205 while (
op < oMatchEnd) *
op++ = *
match++;
1209 return sequenceLength;
1216 const BYTE** litPtr,
const BYTE*
const litLimit,
1217 const BYTE*
const prefixStart,
const BYTE*
const dictStart,
const BYTE*
const dictEnd)
1221 BYTE*
const oMatchEnd =
op + sequenceLength;
1223 const BYTE*
const iLitEnd = *litPtr +
sequence.litLength;
1227 if (oMatchEnd > oend)
return ERROR(dstSize_tooSmall);
1228 if (iLitEnd > litLimit)
return ERROR(corruption_detected);
1239 if (
sequence.offset > (
size_t)(oLitEnd - prefixStart)) {
1241 if (
sequence.offset > (
size_t)(oLitEnd - dictStart))
return ERROR(corruption_detected);
1244 return sequenceLength;
1247 {
size_t const length1 = dictEnd -
match;
1249 op = oLitEnd + length1;
1251 match = prefixStart;
1255 return sequenceLength;
1264 static const U32 dec32table[] = { 0, 1, 2, 1, 4, 4, 4, 4 };
1265 static const int dec64table[] = { 8, 8, 8, 7, 8, 9,10,11 };
1266 int const sub2 = dec64table[
sequence.offset];
1279 if (oMatchEnd > oend-(16-
MINMATCH)) {
1285 while (
op < oMatchEnd) *
op++ = *
match++;
1289 return sequenceLength;
1295 const void*
ptr = dt;
1298 DEBUGLOG(6,
"ZSTD_initFseState : val=%u using %u bits",
1301 DStatePtr->
table = dt + 1;
1318 #define LONG_OFFSETS_MAX_EXTRA_BITS_32 \ 1319 (ZSTD_WINDOWLOG_MAX_32 > STREAM_ACCUMULATOR_MIN_32 \ 1320 ? ZSTD_WINDOWLOG_MAX_32 - STREAM_ACCUMULATOR_MIN_32 \ 1332 U32 const totalBits = llBits+mlBits+ofBits;
1390 DEBUGLOG(6,
"seq: litL=%u, matchL=%u, offset=%u",
1404 void*
dst,
size_t maxDstSize,
1405 const void* seqStart,
size_t seqSize,
int nbSeq,
1409 const BYTE*
const iend =
ip + seqSize;
1411 BYTE*
const oend = ostart + maxDstSize;
1414 const BYTE*
const litEnd = litPtr + dctx->
litSize;
1418 DEBUGLOG(5,
"ZSTD_decompressSequences_body");
1434 DEBUGLOG(6,
"regenerated sequence size : %u", (
U32)oneSeqSize);
1440 DEBUGLOG(5,
"ZSTD_decompressSequences_body: after decode loop, remaining nbSeq : %i", nbSeq);
1441 if (nbSeq)
return ERROR(corruption_detected);
1447 {
size_t const lastLLSize = litEnd - litPtr;
1448 if (lastLLSize > (
size_t)(oend-
op))
return ERROR(dstSize_tooSmall);
1458 void*
dst,
size_t maxDstSize,
1459 const void* seqStart,
size_t seqSize,
int nbSeq,
1474 U32 const totalBits = llBits+mlBits+ofBits;
1548 void*
dst,
size_t maxDstSize,
1549 const void* seqStart,
size_t seqSize,
int nbSeq,
1553 const BYTE*
const iend =
ip + seqSize;
1555 BYTE*
const oend = ostart + maxDstSize;
1558 const BYTE*
const litEnd = litPtr + dctx->
litSize;
1565 #define STORED_SEQS 4 1566 #define STOSEQ_MASK (STORED_SEQS-1) 1567 #define ADVANCED_SEQS 4 1586 if (seqNb<seqAdvance)
return ERROR(corruption_detected);
1597 if (seqNb<nbSeq)
return ERROR(corruption_detected);
1600 seqNb -= seqAdvance;
1601 for ( ; seqNb<nbSeq ; seqNb++) {
1611 #undef ADVANCED_SEQS 1615 {
size_t const lastLLSize = litEnd - litPtr;
1616 if (lastLLSize > (
size_t)(oend-
op))
return ERROR(dstSize_tooSmall);
1626 void*
dst,
size_t maxDstSize,
1627 const void* seqStart,
size_t seqSize,
int nbSeq,
1638 ZSTD_decompressSequences_bmi2(
ZSTD_DCtx* dctx,
1639 void*
dst,
size_t maxDstSize,
1640 const void* seqStart,
size_t seqSize,
int nbSeq,
1647 ZSTD_decompressSequencesLong_bmi2(
ZSTD_DCtx* dctx,
1648 void*
dst,
size_t maxDstSize,
1649 const void* seqStart,
size_t seqSize,
int nbSeq,
1659 const void *seqStart,
size_t seqSize,
int nbSeq,
1663 const void* seqStart,
size_t seqSize,
int nbSeq,
1666 DEBUGLOG(5,
"ZSTD_decompressSequences");
1669 return ZSTD_decompressSequences_bmi2(dctx,
dst, maxDstSize, seqStart, seqSize, nbSeq, isLongOffset);
1676 void*
dst,
size_t maxDstSize,
1677 const void* seqStart,
size_t seqSize,
int nbSeq,
1680 DEBUGLOG(5,
"ZSTD_decompressSequencesLong");
1683 return ZSTD_decompressSequencesLong_bmi2(dctx,
dst, maxDstSize, seqStart, seqSize, nbSeq, isLongOffset);
1696 const void*
ptr = offTable;
1699 U32 const max = 1 << tableLog;
1701 DEBUGLOG(5,
"ZSTD_getLongOffsetsShare: (tableLog=%u)", tableLog);
1716 void*
dst,
size_t dstCapacity,
1717 const void*
src,
size_t srcSize,
const int frame)
1727 DEBUGLOG(5,
"ZSTD_decompressBlock_internal (size : %u)", (
U32)srcSize);
1729 if (srcSize >= ZSTD_BLOCKSIZE_MAX)
return ERROR(srcSize_wrong);
1733 DEBUGLOG(5,
"ZSTD_decodeLiteralsBlock : %u", (
U32)litCSize);
1736 srcSize -= litCSize;
1744 srcSize -= seqHSize;
1746 if ( (!frame || dctx->
fParams.windowSize > (1<<24))
1750 if (shareLongOffsets >= minShare)
1770 void*
dst,
size_t dstCapacity,
1771 const void*
src,
size_t srcSize)
1793 if (
length > dstCapacity)
return ERROR(dstSize_tooSmall);
1805 #if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT >= 1) 1806 if (ZSTD_isLegacy(
src, srcSize))
1807 return ZSTD_findFrameCompressedSizeLegacy(
src, srcSize);
1809 if ( (srcSize >= ZSTD_skippableHeaderSize)
1810 && (
MEM_readLE32(
src) & 0xFFFFFFF0U) == ZSTD_MAGIC_SKIPPABLE_START ) {
1814 const BYTE*
const ipstart =
ip;
1815 size_t remainingSize = srcSize;
1816 ZSTD_frameHeader zfh;
1821 if (
ret > 0)
return ERROR(srcSize_wrong);
1824 ip += zfh.headerSize;
1825 remainingSize -= zfh.headerSize;
1834 return ERROR(srcSize_wrong);
1842 if (zfh.checksumFlag) {
1843 if (remainingSize < 4)
return ERROR(srcSize_wrong);
1847 return ip - ipstart;
1854 void*
dst,
size_t dstCapacity,
1855 const void** srcPtr,
size_t *srcSizePtr)
1859 BYTE*
const oend = ostart + dstCapacity;
1861 size_t remainingSize = *srcSizePtr;
1865 return ERROR(srcSize_wrong);
1869 if (
ZSTD_isError(frameHeaderSize))
return frameHeaderSize;
1871 return ERROR(srcSize_wrong);
1873 ip += frameHeaderSize; remainingSize -= frameHeaderSize;
1885 if (cBlockSize > remainingSize)
return ERROR(srcSize_wrong);
1900 return ERROR(corruption_detected);
1904 if (dctx->
fParams.checksumFlag)
1908 remainingSize -= cBlockSize;
1913 if ((
U64)(
op-ostart) != dctx->
fParams.frameContentSize) {
1914 return ERROR(corruption_detected);
1916 if (dctx->
fParams.checksumFlag) {
1919 if (remainingSize<4)
return ERROR(checksum_wrong);
1921 if (checkRead != checkCalc)
return ERROR(checksum_wrong);
1928 *srcSizePtr = remainingSize;
1933 void*
dst,
size_t dstCapacity,
1934 const void*
src,
size_t srcSize,
1935 const void* dict,
size_t dictSize,
1938 void*
const dststart =
dst;
1939 int moreThan1Frame = 0;
1941 DEBUGLOG(5,
"ZSTD_decompressMultiFrame");
1949 while (srcSize >= ZSTD_frameHeaderSize_prefix) {
1951 #if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT >= 1) 1952 if (ZSTD_isLegacy(
src, srcSize)) {
1954 size_t const frameSize = ZSTD_findFrameCompressedSizeLegacy(
src, srcSize);
1959 decodedSize = ZSTD_decompressLegacy(
dst, dstCapacity,
src, frameSize, dict, dictSize);
1962 dstCapacity -= decodedSize;
1965 srcSize -= frameSize;
1972 DEBUGLOG(4,
"reading magic number %08X (expecting %08X)",
1973 (
U32)magicNumber, (
U32)ZSTD_MAGICNUMBER);
1974 if ((magicNumber & 0xFFFFFFF0U) == ZSTD_MAGIC_SKIPPABLE_START) {
1975 size_t skippableSize;
1976 if (srcSize < ZSTD_skippableHeaderSize)
1977 return ERROR(srcSize_wrong);
1979 + ZSTD_skippableHeaderSize;
1980 if (srcSize < skippableSize)
return ERROR(srcSize_wrong);
1983 srcSize -= skippableSize;
2000 && (moreThan1Frame==1) ) {
2010 return ERROR(srcSize_wrong);
2020 if (srcSize)
return ERROR(srcSize_wrong);
2026 void*
dst,
size_t dstCapacity,
2027 const void*
src,
size_t srcSize,
2028 const void* dict,
size_t dictSize)
2042 #if defined(ZSTD_HEAPMODE) && (ZSTD_HEAPMODE>=1) 2045 if (dctx==
NULL)
return ERROR(memory_allocation);
2070 return ZSTDnit_frameHeader;
2072 return ZSTDnit_blockHeader;
2074 return ZSTDnit_block;
2076 return ZSTDnit_lastBlock;
2078 return ZSTDnit_checksum;
2081 return ZSTDnit_skippableFrame;
2093 DEBUGLOG(5,
"ZSTD_decompressContinue (srcSize:%u)", (
U32)srcSize);
2098 switch (dctx->
stage)
2102 if (dctx->
format == ZSTD_f_zstd1) {
2104 if ((
MEM_readLE32(
src) & 0xFFFFFFF0U) == ZSTD_MAGIC_SKIPPABLE_START) {
2106 dctx->
expected = ZSTD_skippableHeaderSize - srcSize;
2138 if (dctx->
fParams.checksumFlag) {
2154 DEBUGLOG(5,
"ZSTD_decompressContinue: case ZSTDds_decompressBlock");
2159 DEBUGLOG(5,
"ZSTD_decompressContinue: case bt_compressed");
2170 return ERROR(corruption_detected);
2173 DEBUGLOG(5,
"ZSTD_decompressContinue: decoded size from block : %u", (
U32)rSize);
2181 return ERROR(corruption_detected);
2183 if (dctx->
fParams.checksumFlag) {
2202 DEBUGLOG(4,
"ZSTD_decompressContinue: checksum : calculated %08X :: %08X read", h32, check32);
2203 if (check32 != h32)
return ERROR(checksum_wrong);
2211 assert(srcSize <= ZSTD_skippableHeaderSize);
2223 return ERROR(GENERIC);
2241 const void*
const dict,
size_t const dictSize)
2243 const BYTE* dictPtr = (
const BYTE*)dict;
2244 const BYTE*
const dictEnd = dictPtr + dictSize;
2246 if (dictSize <= 8)
return ERROR(dictionary_corrupted);
2253 {
void*
const workspace = &entropy->
LLTable;
2254 size_t const workspaceSize =
sizeof(entropy->
LLTable) +
sizeof(entropy->
OFTable) +
sizeof(entropy->
MLTable);
2256 dictPtr, dictEnd - dictPtr,
2257 workspace, workspaceSize);
2262 {
short offcodeNCount[
MaxOff+1];
2263 U32 offcodeMaxValue =
MaxOff, offcodeLog;
2264 size_t const offcodeHeaderSize =
FSE_readNCount(offcodeNCount, &offcodeMaxValue, &offcodeLog, dictPtr, dictEnd-dictPtr);
2266 if (offcodeMaxValue >
MaxOff)
return ERROR(dictionary_corrupted);
2269 offcodeNCount, offcodeMaxValue,
2272 dictPtr += offcodeHeaderSize;
2275 {
short matchlengthNCount[
MaxML+1];
2276 unsigned matchlengthMaxValue =
MaxML, matchlengthLog;
2277 size_t const matchlengthHeaderSize =
FSE_readNCount(matchlengthNCount, &matchlengthMaxValue, &matchlengthLog, dictPtr, dictEnd-dictPtr);
2278 if (
FSE_isError(matchlengthHeaderSize))
return ERROR(dictionary_corrupted);
2279 if (matchlengthMaxValue >
MaxML)
return ERROR(dictionary_corrupted);
2280 if (matchlengthLog >
MLFSELog)
return ERROR(dictionary_corrupted);
2282 matchlengthNCount, matchlengthMaxValue,
2285 dictPtr += matchlengthHeaderSize;
2288 {
short litlengthNCount[
MaxLL+1];
2289 unsigned litlengthMaxValue =
MaxLL, litlengthLog;
2290 size_t const litlengthHeaderSize =
FSE_readNCount(litlengthNCount, &litlengthMaxValue, &litlengthLog, dictPtr, dictEnd-dictPtr);
2292 if (litlengthMaxValue >
MaxLL)
return ERROR(dictionary_corrupted);
2293 if (litlengthLog >
LLFSELog)
return ERROR(dictionary_corrupted);
2295 litlengthNCount, litlengthMaxValue,
2298 dictPtr += litlengthHeaderSize;
2301 if (dictPtr+12 > dictEnd)
return ERROR(dictionary_corrupted);
2303 size_t const dictContentSize = (
size_t)(dictEnd - (dictPtr+12));
2304 for (
i=0;
i<3;
i++) {
2306 if (rep==0 || rep >= dictContentSize)
return ERROR(dictionary_corrupted);
2307 entropy->
rep[
i] = rep;
2310 return dictPtr - (
const BYTE*)dict;
2317 if (
magic != ZSTD_MAGIC_DICTIONARY) {
2325 dict = (
const char*)dict + eSize;
2359 if (dict && dictSize)
2391 DEBUGLOG(4,
"ZSTD_decompressBegin_usingDDict");
2425 ZSTD_dictContentType_e dictContentType)
2429 if (dictContentType == ZSTD_dct_rawContent)
return 0;
2432 if (dictContentType == ZSTD_dct_fullDict)
2433 return ERROR(dictionary_corrupted);
2437 if (
magic != ZSTD_MAGIC_DICTIONARY) {
2438 if (dictContentType == ZSTD_dct_fullDict)
2439 return ERROR(dictionary_corrupted);
2448 dictionary_corrupted );
2455 const void* dict,
size_t dictSize,
2456 ZSTD_dictLoadMethod_e dictLoadMethod,
2457 ZSTD_dictContentType_e dictContentType)
2459 if ((dictLoadMethod == ZSTD_dlm_byRef) || (!dict) || (!dictSize)) {
2462 if (!dict) dictSize = 0;
2467 if (!internalBuffer)
return ERROR(memory_allocation);
2468 memcpy(internalBuffer, dict, dictSize);
2480 ZSTD_dictLoadMethod_e dictLoadMethod,
2481 ZSTD_dictContentType_e dictContentType,
2482 ZSTD_customMem customMem)
2484 if (!customMem.customAlloc ^ !customMem.customFree)
return NULL;
2488 ddict->
cMem = customMem;
2491 dictLoadMethod, dictContentType);
2522 void* sBuffer,
size_t sBufferSize,
2523 const void* dict,
size_t dictSize,
2524 ZSTD_dictLoadMethod_e dictLoadMethod,
2525 ZSTD_dictContentType_e dictContentType)
2527 size_t const neededSpace =
sizeof(
ZSTD_DDict)
2528 + (dictLoadMethod == ZSTD_dlm_byRef ? 0 : dictSize);
2532 if ((
size_t)sBuffer & 7)
return NULL;
2533 if (sBufferSize < neededSpace)
return NULL;
2534 if (dictLoadMethod == ZSTD_dlm_byCopy) {
2535 memcpy(ddict+1, dict, dictSize);
2540 ZSTD_dlm_byRef, dictContentType) ))
2548 if (ddict==
NULL)
return 0;
2549 { ZSTD_customMem
const cMem = ddict->
cMem;
2561 return sizeof(
ZSTD_DDict) + (dictLoadMethod == ZSTD_dlm_byRef ? 0 : dictSize);
2566 if (ddict==
NULL)
return 0;
2576 if (dictSize < 8)
return 0;
2577 if (
MEM_readLE32(dict) != ZSTD_MAGIC_DICTIONARY)
return 0;
2587 if (ddict==
NULL)
return 0;
2606 ZSTD_frameHeader zfp = { 0, 0, 0, ZSTD_frame, 0, 0, 0 };
2617 void*
dst,
size_t dstCapacity,
2618 const void*
src,
size_t srcSize,
2660 const void* dict,
size_t dictSize,
2661 ZSTD_dictLoadMethod_e dictLoadMethod,
2662 ZSTD_dictContentType_e dictContentType)
2666 if (dict && dictSize >= 8) {
2702 DEBUGLOG(4,
"ZSTD_initDStream_usingDict");
2706 return ZSTD_frameHeaderSize_prefix;
2722 dctx->
ddict = ddict;
2736 return ZSTD_frameHeaderSize_prefix;
2740 ZSTD_DStreamParameter_e paramType,
unsigned paramValue)
2745 default :
return ERROR(parameter_unsupported);
2746 case DStream_p_maxWindowSize :
2747 DEBUGLOG(4,
"setting maxWindowSize = %u KB", paramValue >> 10);
2757 dctx->
ddict = ddict;
2784 size_t const blockSize = (
size_t)
MIN(windowSize, ZSTD_BLOCKSIZE_MAX);
2785 unsigned long long const neededRBSize = windowSize + blockSize + (
WILDCOPY_OVERLENGTH * 2);
2786 unsigned long long const neededSize =
MIN(frameContentSize, neededRBSize);
2787 size_t const minRBSize = (
size_t) neededSize;
2788 if ((
unsigned long long)minRBSize != neededSize)
return ERROR(frameParameter_windowTooLarge);
2794 size_t const blockSize =
MIN(windowSize, ZSTD_BLOCKSIZE_MAX);
2795 size_t const inBuffSize = blockSize;
2802 U32 const windowSizeMax = 1
U << ZSTD_WINDOWLOG_MAX;
2803 ZSTD_frameHeader zfh;
2806 if (
err>0)
return ERROR(srcSize_wrong);
2807 if (zfh.windowSize > windowSizeMax)
2808 return ERROR(frameParameter_windowTooLarge);
2817 size_t const length =
MIN(dstCapacity, srcSize);
2825 const char*
const istart = (
const char*)(
input->src) +
input->pos;
2826 const char*
const iend = (
const char*)(
input->src) +
input->size;
2827 const char*
ip = istart;
2828 char*
const ostart = (
char*)(
output->dst) +
output->pos;
2829 char*
const oend = (
char*)(
output->dst) +
output->size;
2831 U32 someMoreWork = 1;
2833 DEBUGLOG(5,
"ZSTD_decompressStream");
2835 DEBUGLOG(5,
"in: pos: %u vs size: %u",
2837 return ERROR(srcSize_wrong);
2840 DEBUGLOG(5,
"out: pos: %u vs size: %u",
2842 return ERROR(dstSize_tooSmall);
2846 while (someMoreWork) {
2850 DEBUGLOG(5,
"stage zdss_init => transparent reset ");
2855 DEBUGLOG(5,
"stage zdss_loadHeader (srcSize : %u)", (
U32)(iend -
ip));
2856 #if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT>=1) 2868 #if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT>=1) 2869 U32 const legacyVersion = ZSTD_isLegacy(istart, iend-istart);
2870 if (legacyVersion) {
2873 DEBUGLOG(5,
"ZSTD_decompressStream: detected legacy version v0.%u", legacyVersion);
2888 size_t const toLoad = hSize - zds->
lhSize;
2889 size_t const remainingInput = (
size_t)(iend-
ip);
2891 if (toLoad > remainingInput) {
2892 if (remainingInput > 0) {
2894 zds->
lhSize += remainingInput;
2906 && (
U64)(
size_t)(oend-
op) >= zds->
fParams.frameContentSize) {
2908 if (cSize <= (
size_t)(iend-istart)) {
2911 if (
ZSTD_isError(decompressedSize))
return decompressedSize;
2912 DEBUGLOG(4,
"shortcut to single-pass ZSTD_decompress_usingDDict()")
2913 ip = istart + cSize;
2914 op += decompressedSize;
2935 DEBUGLOG(4,
"Control max memory usage (%u KB <= max %u KB)",
2942 {
size_t const neededInBuffSize =
MAX(zds->
fParams.blockSizeMax, 4 );
2945 size_t const bufferSize = neededInBuffSize + neededOutBuffSize;
2946 DEBUGLOG(4,
"inBuff : from %u to %u",
2948 DEBUGLOG(4,
"outBuff : from %u to %u",
2954 return ERROR(memory_allocation);
2972 DEBUGLOG(5,
"neededInSize = %u", (
U32)neededInSize);
2973 if (neededInSize==0) {
2978 if ((
size_t)(iend-
ip) >= neededInSize) {
2985 if (!decodedSize && !isSkipFrame)
break;
2990 if (
ip==iend) { someMoreWork = 0;
break; }
2996 size_t const toLoad = neededInSize - zds->
inPos;
3000 loadedSize =
MIN(toLoad, (
size_t)(iend-
ip));
3006 zds->
inPos += loadedSize;
3007 if (loadedSize < toLoad) { someMoreWork = 0;
break; }
3012 zds->
inBuff, neededInSize);
3026 if (flushedSize == toFlushSize) {
3030 DEBUGLOG(5,
"restart filling outBuff from beginning (left:%i, needed:%u)",
3041 default:
return ERROR(GENERIC);
3047 if ((
ip==istart) && (
op==ostart)) {
3050 if (
op==oend)
return ERROR(dstSize_tooSmall);
3051 if (
ip==iend)
return ERROR(srcSize_wrong);
3058 if (!nextSrcSizeHint) {
3078 nextSrcSizeHint -= zds->
inPos;
3079 return nextSrcSizeHint;
3091 void*
dst,
size_t dstCapacity,
size_t* dstPos,
3092 const void*
src,
size_t srcSize,
size_t* srcPos)
3099 *srcPos =
input.pos;
3106 dctx->
format = ZSTD_f_zstd1;
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble * u
const void * previousDstEnd
#define WILDCOPY_OVERLENGTH
#define ZSTD_NO_FORWARD_PROGRESS_MAX
static const U32 OF_base[MaxOff+1]
#define memmove(s1, s2, n)
size_t(* ZSTD_decompressSequences_t)(ZSTD_DCtx *dctx, void *dst, size_t maxDstSize, const void *seqStart, size_t seqSize, int nbSeq, const ZSTD_longOffset_e isLongOffset)
#define SEQSYMBOL_TABLE_SIZE(log)
size_t ZSTD_DCtx_refPrefix_advanced(ZSTD_DCtx *dctx, const void *prefix, size_t prefixSize, ZSTD_dictContentType_e dictContentType)
size_t ZSTD_sizeof_DCtx(const ZSTD_DCtx *dctx)
static UCHAR ULONG UCHAR ULONG UCHAR * output
static const U32 OF_bits[MaxOff+1]
ZSTD_DCtx * ZSTD_createDCtx(void)
const ZSTD_DDict * ZSTD_initStaticDDict(void *sBuffer, size_t sBufferSize, const void *dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType)
unsigned ZSTD_getDictID_fromDDict(const ZSTD_DDict *ddict)
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
struct ZSTD_DDict_s ZSTD_DDict
static void ZSTD_copy8(void *dst, const void *src)
#define ZSTD_CONTENTSIZE_UNKNOWN
ZSTD_ErrorCode ZSTD_getErrorCode(size_t code)
_Tp _STLP_CALL norm(const complex< _Tp > &__z)
#define LL_DEFAULTNORMLOG
size_t ZSTD_initDStream_usingDict(ZSTD_DStream *zds, const void *dict, size_t dictSize)
static size_t ZSTD_startingInputLength(ZSTD_format_e format)
size_t ZSTD_decodeLiteralsBlock(ZSTD_DCtx *dctx, const void *src, size_t srcSize)
ZSTD_nextInputType_e ZSTD_nextInputType(ZSTD_DCtx *dctx)
size_t ZSTD_DCtx_setFormat(ZSTD_DCtx *dctx, ZSTD_format_e format)
ZSTD_DStream * ZSTD_initStaticDStream(void *workspace, size_t workspaceSize)
#define TARGET_ATTRIBUTE(target)
size_t HUF_readDTableX2_wksp(HUF_DTable *DTable, const void *src, size_t srcSize, void *workSpace, size_t wkspSize)
size_t ZSTD_frameHeaderSize(const void *src, size_t srcSize)
ZSTD_dStreamStage streamStage
size_t FSE_readNCount(short *normalizedCounter, unsigned *maxSVPtr, unsigned *tableLogPtr, const void *headerBuffer, size_t hbSize)
size_t ZSTD_DCtx_refPrefix(ZSTD_DCtx *dctx, const void *prefix, size_t prefixSize)
void ZSTD_free(void *ptr, ZSTD_customMem customMem)
static int ZSTD_isSkipFrame(ZSTD_DCtx *dctx)
static const U32 LL_bits[MaxLL+1]
FORCE_INLINE_TEMPLATE size_t ZSTD_decompressSequences_body(ZSTD_DCtx *dctx, void *dst, size_t maxDstSize, const void *seqStart, size_t seqSize, int nbSeq, const ZSTD_longOffset_e isLongOffset)
MEM_STATIC U32 MEM_readLE32(const void *memPtr)
ZSTD_entropyDTables_t entropy
struct XXH64_state_s XXH64_state_t
const ZSTD_seqSymbol * OFTptr
BYTE litBuffer[ZSTD_BLOCKSIZE_MAX+WILDCOPY_OVERLENGTH]
#define ZSTD_WINDOWLOG_ABSOLUTEMIN
#define OF_DEFAULTNORMLOG
size_t ZSTD_decompressBegin(ZSTD_DCtx *dctx)
#define ZSTD_MAXWINDOWSIZE_DEFAULT
MEM_STATIC size_t BIT_initDStream(BIT_DStream_t *bitD, const void *srcBuffer, size_t srcSize)
MEM_STATIC unsigned MEM_32bits(void)
#define LONG_OFFSETS_MAX_EXTRA_BITS_32
static const ZSTD_seqSymbol OF_defaultDTable[(1<< OF_DEFAULTNORMLOG)+1]
static size_t ZSTD_buildSeqTable(ZSTD_seqSymbol *DTableSpace, const ZSTD_seqSymbol **DTablePtr, symbolEncodingType_e type, U32 max, U32 maxLog, const void *src, size_t srcSize, const U32 *baseValue, const U32 *nbAdditionalBits, const ZSTD_seqSymbol *defaultTable, U32 flagRepeatTable, int ddictIsCold, int nbSeq)
size_t ZSTD_setDStreamParameter(ZSTD_DStream *dctx, ZSTD_DStreamParameter_e paramType, unsigned paramValue)
ZSTD_seqSymbol OFTable[SEQSYMBOL_TABLE_SIZE(OffFSELog)]
size_t ZSTD_sizeof_DStream(const ZSTD_DStream *dctx)
static size_t ZSTD_refDictContent(ZSTD_DCtx *dctx, const void *dict, size_t dictSize)
static size_t ZSTD_decompressMultiFrame(ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const void *dict, size_t dictSize, const ZSTD_DDict *ddict)
MEM_STATIC ZSTD_cpuid_t ZSTD_cpuid(void)
ZSTD_DStream * ZSTD_createDStream(void)
ZSTD_DCtx * ZSTD_initStaticDCtx(void *workspace, size_t workspaceSize)
unsigned ZSTD_getDictID_fromFrame(const void *src, size_t srcSize)
static const U32 ML_base[MaxML+1]
static void ZSTD_checkContinuity(ZSTD_DCtx *dctx, const void *dst)
MEM_STATIC BIT_DStream_status BIT_reloadDStream(BIT_DStream_t *bitD)
MEM_STATIC U64 MEM_readLE64(const void *memPtr)
MEM_STATIC unsigned MEM_64bits(void)
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
static unsigned ZSTD_getLongOffsetsShare(const ZSTD_seqSymbol *offTable)
MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t *bitD, unsigned nbBits)
XXH_PUBLIC_API unsigned long long XXH64_digest(const XXH64_state_t *state_in)
size_t ZSTD_decompressBegin_usingDict(ZSTD_DCtx *dctx, const void *dict, size_t dictSize)
#define ZSTD_STATIC_ASSERT(c)
static const size_t ZSTD_fcs_fieldSize[4]
const void * virtualStart
MEM_STATIC unsigned BIT_highbit32(U32 val)
static size_t ZSTD_decompressBlock_internal(ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const int frame)
static size_t ZSTD_DDictDictSize(const ZSTD_DDict *ddict)
const ZSTD_seqSymbol * table
size_t ZSTD_nextSrcSizeToDecompress(ZSTD_DCtx *dctx)
size_t HUF_decompress4X_usingDTable_bmi2(void *dst, size_t maxDstSize, const void *cSrc, size_t cSrcSize, const HUF_DTable *DTable, int bmi2)
static const size_t ZSTD_blockHeaderSize
size_t ZSTD_estimateDDictSize(size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod)
FORCE_NOINLINE size_t ZSTD_execSequenceLast7(BYTE *op, BYTE *const oend, seq_t sequence, const BYTE **litPtr, const BYTE *const litLimit, const BYTE *const base, const BYTE *const vBase, const BYTE *const dictEnd)
U32 workspace[HUF_DECOMPRESS_WORKSPACE_SIZE_U32]
size_t ZSTD_decompressDCtx(ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize)
size_t ZSTD_getFrameHeader_advanced(ZSTD_frameHeader *zfhPtr, const void *src, size_t srcSize, ZSTD_format_e format)
size_t ZSTD_estimateDCtxSize(void)
GLenum GLuint GLenum GLsizei length
static const void * ZSTD_DDictDictContent(const ZSTD_DDict *ddict)
static void ZSTD_copy4(void *dst, const void *src)
size_t ZSTD_freeDStream(ZSTD_DStream *zds)
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_sizeof_DDict(const ZSTD_DDict *ddict)
ZSTD_DStream * ZSTD_createDStream_advanced(ZSTD_customMem customMem)
size_t ZSTD_decompressBegin_usingDDict(ZSTD_DCtx *dctx, const ZSTD_DDict *ddict)
size_t ZSTD_resetDStream(ZSTD_DStream *dctx)
#define offsetof(TYPE, MEMBER)
MEM_STATIC void ZSTD_wildcopy(void *dst, const void *src, ptrdiff_t length)
static const U32 repStartValue[ZSTD_REP_NUM]
static size_t ZSTD_decompress_insertDictionary(ZSTD_DCtx *dctx, const void *dict, size_t dictSize)
ZSTDLIB_API size_t ZSTD_insertBlock(ZSTD_DCtx *dctx, const void *blockStart, size_t blockSize)
#define MIN_SEQUENCES_SIZE
size_t ZSTD_initDStream(ZSTD_DStream *zds)
FORCE_INLINE_TEMPLATE seq_t ZSTD_decodeSequence(seqState_t *seqState, const ZSTD_longOffset_e longOffsets)
#define PREFETCH_AREA(p, s)
size_t ZSTD_estimateDStreamSize(size_t windowSize)
BYTE headerBuffer[ZSTD_FRAMEHEADERSIZE_MAX]
size_t ZSTD_decompress(void *dst, size_t dstCapacity, const void *src, size_t srcSize)
const ZSTD_seqSymbol * LLTptr
MEM_STATIC size_t ZSTD_limitCopy(void *dst, size_t dstCapacity, const void *src, size_t srcSize)
FORCE_INLINE_TEMPLATE size_t ZSTD_decompressSequencesLong_body(ZSTD_DCtx *dctx, void *dst, size_t maxDstSize, const void *seqStart, size_t seqSize, int nbSeq, const ZSTD_longOffset_e isLongOffset)
#define ML_DEFAULTNORMLOG
static void ZSTD_initFseState(ZSTD_fseState *DStatePtr, BIT_DStream_t *bitD, const ZSTD_seqSymbol *dt)
FORCE_INLINE_TEMPLATE void ZSTD_updateFseState(ZSTD_fseState *DStatePtr, BIT_DStream_t *bitD)
static size_t ZSTD_decodeFrameHeader(ZSTD_DCtx *dctx, const void *src, size_t headerSize)
const ZSTD_seqSymbol * MLTptr
MEM_STATIC U16 MEM_readLE16(const void *memPtr)
size_t HUF_decompress4X_hufOnly_wksp_bmi2(HUF_DTable *dctx, void *dst, size_t dstSize, const void *cSrc, size_t cSrcSize, void *workSpace, size_t wkspSize, int bmi2)
static void ZSTD_buildFSETable(ZSTD_seqSymbol *dt, const short *normalizedCounter, unsigned maxSymbolValue, const U32 *baseValue, const U32 *nbAdditionalBits, unsigned tableLog)
size_t ZSTD_decompressStream(ZSTD_DStream *zds, ZSTD_outBuffer *output, ZSTD_inBuffer *input)
size_t ZSTD_decompress_generic(ZSTD_DCtx *dctx, ZSTD_outBuffer *output, ZSTD_inBuffer *input)
size_t HUF_decompress1X1_DCtx_wksp_bmi2(HUF_DTable *dctx, void *dst, size_t dstSize, const void *cSrc, size_t cSrcSize, void *workSpace, size_t wkspSize, int bmi2)
static void ZSTD_buildSeqTable_rle(ZSTD_seqSymbol *dt, U32 baseValue, U32 nbAddBits)
ZSTD_entropyDTables_t entropy
ZSTD_seqSymbol MLTable[SEQSYMBOL_TABLE_SIZE(MLFSELog)]
XXH_PUBLIC_API XXH_errorcode XXH64_update(XXH64_state_t *state_in, const void *input, size_t len)
size_t ZSTD_decompress_usingDDict(ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize, const ZSTD_DDict *ddict)
static size_t ZSTD_generateNxBytes(void *dst, size_t dstCapacity, BYTE value, size_t length)
static size_t ZSTD_decompressFrame(ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, const void **srcPtr, size_t *srcSizePtr)
HUF_DTable hufTable[HUF_DTABLE_SIZE(HufLog)]
size_t ZSTD_findFrameCompressedSize(const void *src, size_t srcSize)
size_t ZSTD_decompress_generic_simpleArgs(ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, size_t *dstPos, const void *src, size_t srcSize, size_t *srcPos)
static const size_t ZSTD_did_fieldSize[4]
unsigned long long ZSTD_findDecompressedSize(const void *src, size_t srcSize)
#define STREAM_ACCUMULATOR_MIN_32
static size_t ZSTD_decompressSequences_default(ZSTD_DCtx *dctx, void *dst, size_t maxDstSize, const void *seqStart, size_t seqSize, int nbSeq, const ZSTD_longOffset_e isLongOffset)
#define STREAM_ACCUMULATOR_MIN_64
static struct message * sequence
size_t ZSTD_getFrameHeader(ZSTD_frameHeader *zfhPtr, const void *src, size_t srcSize)
ZSTD_DDict * ZSTD_createDDict_advanced(const void *dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType, ZSTD_customMem customMem)
#define memcpy(s1, s2, n)
size_t ZSTD_freeDCtx(ZSTD_DCtx *dctx)
void * ZSTD_malloc(size_t size, ZSTD_customMem customMem)
static size_t ZSTD_setRleBlock(void *dst, size_t dstCapacity, const void *src, size_t srcSize, size_t regenSize)
static void ZSTD_initDCtx_internal(ZSTD_DCtx *dctx)
unsigned ZSTD_isFrame(const void *buffer, size_t size)
#define STREAM_ACCUMULATOR_MIN
size_t ZSTD_initDStream_usingDDict(ZSTD_DStream *dctx, const ZSTD_DDict *ddict)
size_t ZSTD_decodeSeqHeaders(ZSTD_DCtx *dctx, int *nbSeqPtr, const void *src, size_t srcSize)
U32 previousLegacyVersion
static size_t ZSTD_decompressSequencesLong(ZSTD_DCtx *dctx, void *dst, size_t maxDstSize, const void *seqStart, size_t seqSize, int nbSeq, const ZSTD_longOffset_e isLongOffset)
size_t ZSTD_DStreamOutSize(void)
static size_t ZSTD_initDDict_internal(ZSTD_DDict *ddict, const void *dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType)
ZSTD_DCtx * ZSTD_createDCtx_advanced(ZSTD_customMem customMem)
size_t ZSTD_decompressContinue(ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize)
GLenum GLenum GLenum input
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
MEM_STATIC size_t BIT_readBits(BIT_DStream_t *bitD, unsigned nbBits)
void ZSTD_DCtx_reset(ZSTD_DCtx *dctx)
static const ZSTD_seqSymbol LL_defaultDTable[(1<< LL_DEFAULTNORMLOG)+1]
ZSTD_DDict * ZSTD_createDDict(const void *dict, size_t dictSize)
size_t ZSTD_DStreamInSize(void)
HINT_INLINE size_t ZSTD_execSequence(BYTE *op, BYTE *const oend, seq_t sequence, const BYTE **litPtr, const BYTE *const litLimit, const BYTE *const prefixStart, const BYTE *const virtualStart, const BYTE *const dictEnd)
size_t ZSTD_estimateDStreamSize_fromFrame(const void *src, size_t srcSize)
ZSTD_seqSymbol LLTable[SEQSYMBOL_TABLE_SIZE(LLFSELog)]
size_t ZSTD_DCtx_refDDict(ZSTD_DCtx *dctx, const ZSTD_DDict *ddict)
static size_t ZSTD_loadEntropy_inDDict(ZSTD_DDict *ddict, ZSTD_dictContentType_e dictContentType)
static const U32 ML_bits[MaxML+1]
struct ZSTD_DCtx_s ZSTD_DCtx
size_t prevOffset[ZSTD_REP_NUM]
__kernel_ptrdiff_t ptrdiff_t
unsigned long long ZSTD_getDecompressedSize(const void *src, size_t srcSize)
ZSTD_DDict * ZSTD_createDDict_byReference(const void *dictBuffer, size_t dictSize)
unsigned long long ZSTD_getFrameContentSize(const void *src, size_t srcSize)
static size_t ZSTD_decompressSequences(ZSTD_DCtx *dctx, void *dst, size_t maxDstSize, const void *seqStart, size_t seqSize, int nbSeq, const ZSTD_longOffset_e isLongOffset)
size_t ZSTD_DCtx_loadDictionary(ZSTD_DCtx *dctx, const void *dict, size_t dictSize)
static size_t ZSTD_copyRawBlock(void *dst, size_t dstCapacity, const void *src, size_t srcSize)
size_t HUF_decompress1X_usingDTable_bmi2(void *dst, size_t maxDstSize, const void *cSrc, size_t cSrcSize, const HUF_DTable *DTable, int bmi2)
size_t ZSTD_DCtx_loadDictionary_byReference(ZSTD_DCtx *dctx, const void *dict, size_t dictSize)
size_t ZSTD_decodingBufferSize_min(unsigned long long windowSize, unsigned long long frameContentSize)
size_t ZSTD_DCtx_setMaxWindowSize(ZSTD_DCtx *dctx, size_t maxWindowSize)
size_t ZSTD_freeDDict(ZSTD_DDict *ddict)
const HUF_DTable * HUFptr
size_t ZSTD_getcBlockSize(const void *src, size_t srcSize, blockProperties_t *bpPtr)
static size_t ZSTD_decompressSequencesLong_default(ZSTD_DCtx *dctx, void *dst, size_t maxDstSize, const void *seqStart, size_t seqSize, int nbSeq, const ZSTD_longOffset_e isLongOffset)
XXH_PUBLIC_API XXH_errorcode XXH64_reset(XXH64_state_t *statePtr, unsigned long long seed)
void ZSTD_copyDCtx(ZSTD_DCtx *dstDCtx, const ZSTD_DCtx *srcDCtx)
GLuint GLuint GLsizei GLenum type
#define ZSTD_CONTENTSIZE_ERROR
static const U32 LL_base[MaxLL+1]
HINT_INLINE size_t ZSTD_execSequenceLong(BYTE *op, BYTE *const oend, seq_t sequence, const BYTE **litPtr, const BYTE *const litLimit, const BYTE *const prefixStart, const BYTE *const dictStart, const BYTE *const dictEnd)
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)
static size_t ZSTD_loadEntropy(ZSTD_entropyDTables_t *entropy, const void *const dict, size_t const dictSize)
static size_t ZSTD_frameHeaderSize_internal(const void *src, size_t srcSize, ZSTD_format_e format)
static unsigned(__cdecl *hash_bstr)(bstr_t s)
unsigned ZSTD_getDictID_fromDict(const void *dict, size_t dictSize)
MEM_STATIC U32 MEM_readLE24(const void *memPtr)
#define FORCE_INLINE_TEMPLATE
FORCE_INLINE_TEMPLATE seq_t ZSTD_decodeSequenceLong(seqState_t *seqState, ZSTD_longOffset_e const longOffsets)
size_t ZSTD_decompressBlock(ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, const void *src, size_t srcSize)
static const ZSTD_seqSymbol ML_defaultDTable[(1<< ML_DEFAULTNORMLOG)+1]