Use ZSTD Error codes, improve explanation of ZSTD_loadCEntropy() and ZSTD_loadDEntropy()
This commit is contained in:
parent
04fb42b4f3
commit
c787b351ea
@ -2772,7 +2772,7 @@ size_t ZSTD_loadCEntropy(ZSTD_compressedBlockState_t* bs, void* workspace,
|
|||||||
short* offcodeNCount, unsigned* offcodeMaxValue,
|
short* offcodeNCount, unsigned* offcodeMaxValue,
|
||||||
const void* const dict, size_t dictSize)
|
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;
|
const BYTE* const dictEnd = dictPtr + dictSize;
|
||||||
|
|
||||||
{ unsigned maxSymbolValue = 255;
|
{ unsigned maxSymbolValue = 255;
|
||||||
@ -2869,7 +2869,7 @@ static size_t ZSTD_loadZstdDictionary(ZSTD_compressedBlockState_t* bs,
|
|||||||
dictID = params->fParams.noDictIDFlag ? 0 : MEM_readLE32(dictPtr);
|
dictID = params->fParams.noDictIDFlag ? 0 : MEM_readLE32(dictPtr);
|
||||||
dictPtr += 4;
|
dictPtr += 4;
|
||||||
|
|
||||||
dictPtr += eSize - 8; /* size of header + magic number already accounted for */
|
dictPtr += eSize - 8;
|
||||||
|
|
||||||
{ size_t const dictContentSize = (size_t)(dictEnd - dictPtr);
|
{ size_t const dictContentSize = (size_t)(dictEnd - dictPtr);
|
||||||
U32 offcodeMax = MaxOff;
|
U32 offcodeMax = MaxOff;
|
||||||
|
@ -931,13 +931,13 @@ MEM_STATIC void ZSTD_debugTable(const U32* table, U32 max)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
/* ===============================================================
|
/* ===============================================================
|
||||||
* Public declarations
|
* Shared internal declarations
|
||||||
* These prototypes may be called from sources not in lib/compress
|
* These prototypes may be called from sources not in lib/compress
|
||||||
* =============================================================== */
|
* =============================================================== */
|
||||||
|
|
||||||
/* ZSTD_loadCEntropy() :
|
/* ZSTD_loadCEntropy() :
|
||||||
* dict : must point at beginning of a valid zstd dictionary.
|
* 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,
|
size_t ZSTD_loadCEntropy(ZSTD_compressedBlockState_t* bs, void* workspace,
|
||||||
short* offcodeNCount, unsigned* offcodeMaxValue,
|
short* offcodeNCount, unsigned* offcodeMaxValue,
|
||||||
const void* const dict, size_t dictSize);
|
const void* const dict, size_t dictSize);
|
||||||
|
@ -160,7 +160,7 @@ struct ZSTD_DCtx_s
|
|||||||
|
|
||||||
/*! ZSTD_loadDEntropy() :
|
/*! ZSTD_loadDEntropy() :
|
||||||
* dict : must point at beginning of a valid zstd dictionary.
|
* 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,
|
size_t ZSTD_loadDEntropy(ZSTD_entropyDTables_t* entropy,
|
||||||
const void* const dict, size_t const dictSize);
|
const void* const dict, size_t const dictSize);
|
||||||
|
|
||||||
|
@ -102,22 +102,22 @@ unsigned ZDICT_getDictID(const void* dictBuffer, size_t dictSize)
|
|||||||
|
|
||||||
size_t ZDICT_getDictHeaderSize(const void* dictBuffer, size_t 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;
|
{ size_t headerSize;
|
||||||
unsigned offcodeMaxValue = MaxOff;
|
unsigned offcodeMaxValue = MaxOff;
|
||||||
ZSTD_compressedBlockState_t* dummyBs = (ZSTD_compressedBlockState_t*)malloc(sizeof(ZSTD_compressedBlockState_t));
|
ZSTD_compressedBlockState_t* dummyBs = (ZSTD_compressedBlockState_t*)malloc(sizeof(ZSTD_compressedBlockState_t));
|
||||||
U32* wksp = (U32*)malloc(HUF_WORKSPACE_SIZE);
|
U32* wksp = (U32*)malloc(HUF_WORKSPACE_SIZE);
|
||||||
short* offcodeNCount = (short*)malloc((MaxOff+1)*sizeof(short));
|
short* offcodeNCount = (short*)malloc((MaxOff+1)*sizeof(short));
|
||||||
if (!dummyBs || !wksp) {
|
if (!dummyBs || !wksp || !offcodeNCount) {
|
||||||
return 0;
|
return ERROR(memory_allocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
headerSize = ZSTD_loadCEntropy(dummyBs, wksp, offcodeNCount, &offcodeMaxValue, dictBuffer, dictSize);
|
headerSize = ZSTD_loadCEntropy(dummyBs, wksp, offcodeNCount, &offcodeMaxValue, dictBuffer, dictSize);
|
||||||
free(dummyBs);
|
free(dummyBs);
|
||||||
free(wksp);
|
free(wksp);
|
||||||
free(offcodeNCount);
|
free(offcodeNCount);
|
||||||
return headerSize;
|
return headerSize; /* this may be an error value if ZSTD_loadCEntropy() encountered an error */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ ZDICTLIB_API size_t ZDICT_trainFromBuffer(void* dictBuffer, size_t dictBufferCap
|
|||||||
|
|
||||||
/*====== Helper functions ======*/
|
/*====== 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 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 unsigned ZDICT_isError(size_t errorCode);
|
||||||
ZDICTLIB_API const char* ZDICT_getErrorName(size_t errorCode);
|
ZDICTLIB_API const char* ZDICT_getErrorName(size_t errorCode);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user