17#include "../common/allocations.h"
18#include "../common/zstd_deps.h"
19#include "../common/cpu.h"
20#include "../common/mem.h"
21#define FSE_STATIC_LINKING_ONLY
22#include "../common/fse.h"
23#include "../common/huf.h"
27#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT>=1)
28# include "../legacy/zstd_legacy.h"
60 DEBUGLOG(4,
"ZSTD_copyDDictParameters");
68#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
69 dctx->dictContentBeginForFuzzing = dctx->
prefixStart;
91 ZSTD_dictContentType_e dictContentType)
95 if (dictContentType == ZSTD_dct_rawContent)
return 0;
98 if (dictContentType == ZSTD_dct_fullDict)
99 return ERROR(dictionary_corrupted);
104 if (dictContentType == ZSTD_dct_fullDict)
105 return ERROR(dictionary_corrupted);
114 dictionary_corrupted,
"");
120static size_t ZSTD_initDDict_internal(
ZSTD_DDict* ddict,
121 const void* dict,
size_t dictSize,
122 ZSTD_dictLoadMethod_e dictLoadMethod,
123 ZSTD_dictContentType_e dictContentType)
125 if ((dictLoadMethod == ZSTD_dlm_byRef) || (!dict) || (!dictSize)) {
128 if (!dict) dictSize = 0;
133 if (!internalBuffer)
return ERROR(memory_allocation);
146 ZSTD_dictLoadMethod_e dictLoadMethod,
147 ZSTD_dictContentType_e dictContentType,
148 ZSTD_customMem customMem)
150 if ((!customMem.customAlloc) ^ (!customMem.customFree))
return NULL;
153 if (ddict == NULL)
return NULL;
154 ddict->
cMem = customMem;
155 {
size_t const initResult = ZSTD_initDDict_internal(ddict,
157 dictLoadMethod, dictContentType);
172 ZSTD_customMem
const allocator = { NULL, NULL, NULL };
182 ZSTD_customMem
const allocator = { NULL, NULL, NULL };
188 void* sBuffer,
size_t sBufferSize,
189 const void* dict,
size_t dictSize,
190 ZSTD_dictLoadMethod_e dictLoadMethod,
191 ZSTD_dictContentType_e dictContentType)
194 + (dictLoadMethod == ZSTD_dlm_byRef ? 0 : dictSize);
198 if ((
size_t)sBuffer & 7)
return NULL;
199 if (sBufferSize < neededSpace)
return NULL;
200 if (dictLoadMethod == ZSTD_dlm_byCopy) {
206 ZSTD_dlm_byRef, dictContentType) ))
214 if (ddict==NULL)
return 0;
215 { ZSTD_customMem
const cMem = ddict->
cMem;
227 return sizeof(
ZSTD_DDict) + (dictLoadMethod == ZSTD_dlm_byRef ? 0 : dictSize);
232 if (ddict==NULL)
return 0;
242 if (ddict==NULL)
return 0;
MEM_STATIC void ZSTD_customFree(void *ptr, ZSTD_customMem customMem)
MEM_STATIC void * ZSTD_customMalloc(size_t size, ZSTD_customMem customMem)
#define assert(condition)
#define FORWARD_IF_ERROR(err,...)
#define RETURN_ERROR_IF(cond, err,...)
MEM_STATIC U32 MEM_readLE32(const void *memPtr)
const HUF_DTable * HUFptr
const ZSTD_seqSymbol * MLTptr
const void * virtualStart
const ZSTD_seqSymbol * OFTptr
ZSTD_entropyDTables_t entropy
const void * previousDstEnd
const ZSTD_seqSymbol * LLTptr
ZSTD_entropyDTables_t entropy
HUF_DTable hufTable[HUF_DTABLE_SIZE(ZSTD_HUFFDTABLE_CAPACITY_LOG)]
ZSTD_seqSymbol LLTable[SEQSYMBOL_TABLE_SIZE(LLFSELog)]
ZSTD_seqSymbol MLTable[SEQSYMBOL_TABLE_SIZE(MLFSELog)]
ZSTD_seqSymbol OFTable[SEQSYMBOL_TABLE_SIZE(OffFSELog)]
#define ZSTD_MAGIC_DICTIONARY
struct ZSTD_DDict_s ZSTD_DDict
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)
size_t ZSTD_estimateDDictSize(size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod)
void ZSTD_copyDDictParameters(ZSTD_DCtx *dctx, const ZSTD_DDict *ddict)
const ZSTD_DDict * ZSTD_initStaticDDict(void *sBuffer, size_t sBufferSize, const void *dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType)
size_t ZSTD_freeDDict(ZSTD_DDict *ddict)
const void * ZSTD_DDict_dictContent(const ZSTD_DDict *ddict)
ZSTD_DDict * ZSTD_createDDict(const void *dict, size_t dictSize)
ZSTD_DDict * ZSTD_createDDict_byReference(const void *dictBuffer, size_t dictSize)
size_t ZSTD_DDict_dictSize(const ZSTD_DDict *ddict)
size_t ZSTD_sizeof_DDict(const ZSTD_DDict *ddict)
size_t ZSTD_loadDEntropy(ZSTD_entropyDTables_t *entropy, const void *const dict, size_t const dictSize)
#define ZSTD_HUFFDTABLE_CAPACITY_LOG
#define ZSTD_memcpy(d, s, l)