MCPcopy Create free account
hub / github.com/F-Stack/f-stack / ZSTD_loadCEntropy

Function ZSTD_loadCEntropy

freebsd/contrib/openzfs/module/zstd/lib/zstd.c:15986–16061  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15984}
15985
15986size_t ZSTD_loadCEntropy(ZSTD_compressedBlockState_t* bs, void* workspace,
15987 short* offcodeNCount, unsigned* offcodeMaxValue,
15988 const void* const dict, size_t dictSize)
15989{
15990 const BYTE* dictPtr = (const BYTE*)dict; /* skip magic num and dict ID */
15991 const BYTE* const dictEnd = dictPtr + dictSize;
15992 dictPtr += 8;
15993 bs->entropy.huf.repeatMode = HUF_repeat_check;
15994
15995 { unsigned maxSymbolValue = 255;
15996 unsigned hasZeroWeights = 1;
15997 size_t const hufHeaderSize = HUF_readCTable((HUF_CElt*)bs->entropy.huf.CTable, &maxSymbolValue, dictPtr,
15998 dictEnd-dictPtr, &hasZeroWeights);
15999
16000 /* We only set the loaded table as valid if it contains all non-zero
16001 * weights. Otherwise, we set it to check */
16002 if (!hasZeroWeights)
16003 bs->entropy.huf.repeatMode = HUF_repeat_valid;
16004
16005 RETURN_ERROR_IF(HUF_isError(hufHeaderSize), dictionary_corrupted, "");
16006 RETURN_ERROR_IF(maxSymbolValue < 255, dictionary_corrupted, "");
16007 dictPtr += hufHeaderSize;
16008 }
16009
16010 { unsigned offcodeLog;
16011 size_t const offcodeHeaderSize = FSE_readNCount(offcodeNCount, offcodeMaxValue, &offcodeLog, dictPtr, dictEnd-dictPtr);
16012 RETURN_ERROR_IF(FSE_isError(offcodeHeaderSize), dictionary_corrupted, "");
16013 RETURN_ERROR_IF(offcodeLog > OffFSELog, dictionary_corrupted, "");
16014 /* Defer checking offcodeMaxValue because we need to know the size of the dictionary content */
16015 /* fill all offset symbols to avoid garbage at end of table */
16016 RETURN_ERROR_IF(FSE_isError(FSE_buildCTable_wksp(
16017 bs->entropy.fse.offcodeCTable,
16018 offcodeNCount, MaxOff, offcodeLog,
16019 workspace, HUF_WORKSPACE_SIZE)),
16020 dictionary_corrupted, "");
16021 dictPtr += offcodeHeaderSize;
16022 }
16023
16024 { short matchlengthNCount[MaxML+1];
16025 unsigned matchlengthMaxValue = MaxML, matchlengthLog;
16026 size_t const matchlengthHeaderSize = FSE_readNCount(matchlengthNCount, &matchlengthMaxValue, &matchlengthLog, dictPtr, dictEnd-dictPtr);
16027 RETURN_ERROR_IF(FSE_isError(matchlengthHeaderSize), dictionary_corrupted, "");
16028 RETURN_ERROR_IF(matchlengthLog > MLFSELog, dictionary_corrupted, "");
16029 /* Every match length code must have non-zero probability */
16030 FORWARD_IF_ERROR( ZSTD_checkDictNCount(matchlengthNCount, matchlengthMaxValue, MaxML), "");
16031 RETURN_ERROR_IF(FSE_isError(FSE_buildCTable_wksp(
16032 bs->entropy.fse.matchlengthCTable,
16033 matchlengthNCount, matchlengthMaxValue, matchlengthLog,
16034 workspace, HUF_WORKSPACE_SIZE)),
16035 dictionary_corrupted, "");
16036 dictPtr += matchlengthHeaderSize;
16037 }
16038
16039 { short litlengthNCount[MaxLL+1];
16040 unsigned litlengthMaxValue = MaxLL, litlengthLog;
16041 size_t const litlengthHeaderSize = FSE_readNCount(litlengthNCount, &litlengthMaxValue, &litlengthLog, dictPtr, dictEnd-dictPtr);
16042 RETURN_ERROR_IF(FSE_isError(litlengthHeaderSize), dictionary_corrupted, "");
16043 RETURN_ERROR_IF(litlengthLog > LLFSELog, dictionary_corrupted, "");

Callers 1

ZSTD_loadZstdDictionaryFunction · 0.70

Calls 7

ZSTD_checkDictNCountFunction · 0.85
HUF_readCTableFunction · 0.70
HUF_isErrorFunction · 0.70
FSE_readNCountFunction · 0.70
FSE_isErrorFunction · 0.70
FSE_buildCTable_wkspFunction · 0.70
MEM_readLE32Function · 0.70

Tested by

no test coverage detected