short* offcodeNCount, unsigned* offcodeMaxValue,
const void* const dict, size_t dictSize)
{
- const BYTE* dictPtr = (const BYTE*)dict + 8;
+ const BYTE* dictPtr = (const BYTE*)dict + 8; /* skip magic num and dict ID */
const BYTE* const dictEnd = dictPtr + dictSize;
{ unsigned maxSymbolValue = 255;
dictID = params->fParams.noDictIDFlag ? 0 : MEM_readLE32(dictPtr);
dictPtr += 4;
- dictPtr += eSize - 8; /* size of header + magic number already accounted for */
+ dictPtr += eSize - 8;
{ size_t const dictContentSize = (size_t)(dictEnd - dictPtr);
U32 offcodeMax = MaxOff;
}
#endif
/* ===============================================================
- * Public declarations
+ * Shared internal declarations
* These prototypes may be called from sources not in lib/compress
* =============================================================== */
/* ZSTD_loadCEntropy() :
* dict : must point at beginning of a valid zstd dictionary.
- * return : size of entropy tables read */
+ * return : size of dictionary header (size of magic number + dict ID + entropy tables) */
size_t ZSTD_loadCEntropy(ZSTD_compressedBlockState_t* bs, void* workspace,
short* offcodeNCount, unsigned* offcodeMaxValue,
const void* const dict, size_t dictSize);
/*! ZSTD_loadDEntropy() :
* dict : must point at beginning of a valid zstd dictionary.
- * @return : size of entropy tables read */
+ * @return : size of dictionary header (size of magic number + dict ID + entropy tables) */
size_t ZSTD_loadDEntropy(ZSTD_entropyDTables_t* entropy,
const void* const dict, size_t const dictSize);
size_t ZDICT_getDictHeaderSize(const void* dictBuffer, size_t dictSize)
{
- if (dictSize <= 8 || MEM_readLE32(dictBuffer) != ZSTD_MAGIC_DICTIONARY) return 0;
+ if (dictSize <= 8 || MEM_readLE32(dictBuffer) != ZSTD_MAGIC_DICTIONARY) return ERROR(dictionary_corrupted);
{ size_t headerSize;
unsigned offcodeMaxValue = MaxOff;
ZSTD_compressedBlockState_t* dummyBs = (ZSTD_compressedBlockState_t*)malloc(sizeof(ZSTD_compressedBlockState_t));
U32* wksp = (U32*)malloc(HUF_WORKSPACE_SIZE);
short* offcodeNCount = (short*)malloc((MaxOff+1)*sizeof(short));
- if (!dummyBs || !wksp) {
- return 0;
+ if (!dummyBs || !wksp || !offcodeNCount) {
+ return ERROR(memory_allocation);
}
headerSize = ZSTD_loadCEntropy(dummyBs, wksp, offcodeNCount, &offcodeMaxValue, dictBuffer, dictSize);
free(dummyBs);
free(wksp);
free(offcodeNCount);
- return headerSize;
+ return headerSize; /* this may be an error value if ZSTD_loadCEntropy() encountered an error */
}
}
/*====== Helper functions ======*/
ZDICTLIB_API unsigned ZDICT_getDictID(const void* dictBuffer, size_t dictSize); /**< extracts dictID; @return zero if error (not a valid dictionary) */
-ZDICTLIB_API size_t ZDICT_getDictHeaderSize(const void* dictBuffer, size_t dictSize); /* returns dict header size; returns zero if error (not a valid dictionary or mem alloc failure) */
+ZDICTLIB_API size_t ZDICT_getDictHeaderSize(const void* dictBuffer, size_t dictSize); /* returns dict header size; returns a ZSTD error code on failure */
ZDICTLIB_API unsigned ZDICT_isError(size_t errorCode);
ZDICTLIB_API const char* ZDICT_getErrorName(size_t errorCode);