! ZSTD_loadDEntropy() : * dict : must point at beginning of a valid zstd dictionary. * @return : size of entropy tables read */
| 25559 | * dict : must point at beginning of a valid zstd dictionary. |
| 25560 | * @return : size of entropy tables read */ |
| 25561 | size_t |
| 25562 | ZSTD_loadDEntropy(ZSTD_entropyDTables_t* entropy, |
| 25563 | const void* const dict, size_t const dictSize) |
| 25564 | { |
| 25565 | const BYTE* dictPtr = (const BYTE*)dict; |
| 25566 | const BYTE* const dictEnd = dictPtr + dictSize; |
| 25567 | |
| 25568 | RETURN_ERROR_IF(dictSize <= 8, dictionary_corrupted, "dict is too small"); |
| 25569 | assert(MEM_readLE32(dict) == ZSTD_MAGIC_DICTIONARY); /* dict must be valid */ |
| 25570 | dictPtr += 8; /* skip header = magic + dictID */ |
| 25571 | |
| 25572 | ZSTD_STATIC_ASSERT(offsetof(ZSTD_entropyDTables_t, OFTable) == offsetof(ZSTD_entropyDTables_t, LLTable) + sizeof(entropy->LLTable)); |
| 25573 | ZSTD_STATIC_ASSERT(offsetof(ZSTD_entropyDTables_t, MLTable) == offsetof(ZSTD_entropyDTables_t, OFTable) + sizeof(entropy->OFTable)); |
| 25574 | ZSTD_STATIC_ASSERT(sizeof(entropy->LLTable) + sizeof(entropy->OFTable) + sizeof(entropy->MLTable) >= HUF_DECOMPRESS_WORKSPACE_SIZE); |
| 25575 | { void* const workspace = &entropy->LLTable; /* use fse tables as temporary workspace; implies fse tables are grouped together */ |
| 25576 | size_t const workspaceSize = sizeof(entropy->LLTable) + sizeof(entropy->OFTable) + sizeof(entropy->MLTable); |
| 25577 | #ifdef HUF_FORCE_DECOMPRESS_X1 |
| 25578 | /* in minimal huffman, we always use X1 variants */ |
| 25579 | size_t const hSize = HUF_readDTableX1_wksp(entropy->hufTable, |
| 25580 | dictPtr, dictEnd - dictPtr, |
| 25581 | workspace, workspaceSize); |
| 25582 | #else |
| 25583 | size_t const hSize = HUF_readDTableX2_wksp(entropy->hufTable, |
| 25584 | dictPtr, dictEnd - dictPtr, |
| 25585 | workspace, workspaceSize); |
| 25586 | #endif |
| 25587 | RETURN_ERROR_IF(HUF_isError(hSize), dictionary_corrupted, ""); |
| 25588 | dictPtr += hSize; |
| 25589 | } |
| 25590 | |
| 25591 | { short offcodeNCount[MaxOff+1]; |
| 25592 | unsigned offcodeMaxValue = MaxOff, offcodeLog; |
| 25593 | size_t const offcodeHeaderSize = FSE_readNCount(offcodeNCount, &offcodeMaxValue, &offcodeLog, dictPtr, dictEnd-dictPtr); |
| 25594 | RETURN_ERROR_IF(FSE_isError(offcodeHeaderSize), dictionary_corrupted, ""); |
| 25595 | RETURN_ERROR_IF(offcodeMaxValue > MaxOff, dictionary_corrupted, ""); |
| 25596 | RETURN_ERROR_IF(offcodeLog > OffFSELog, dictionary_corrupted, ""); |
| 25597 | ZSTD_buildFSETable( entropy->OFTable, |
| 25598 | offcodeNCount, offcodeMaxValue, |
| 25599 | OF_base, OF_bits, |
| 25600 | offcodeLog); |
| 25601 | dictPtr += offcodeHeaderSize; |
| 25602 | } |
| 25603 | |
| 25604 | { short matchlengthNCount[MaxML+1]; |
| 25605 | unsigned matchlengthMaxValue = MaxML, matchlengthLog; |
| 25606 | size_t const matchlengthHeaderSize = FSE_readNCount(matchlengthNCount, &matchlengthMaxValue, &matchlengthLog, dictPtr, dictEnd-dictPtr); |
| 25607 | RETURN_ERROR_IF(FSE_isError(matchlengthHeaderSize), dictionary_corrupted, ""); |
| 25608 | RETURN_ERROR_IF(matchlengthMaxValue > MaxML, dictionary_corrupted, ""); |
| 25609 | RETURN_ERROR_IF(matchlengthLog > MLFSELog, dictionary_corrupted, ""); |
| 25610 | ZSTD_buildFSETable( entropy->MLTable, |
| 25611 | matchlengthNCount, matchlengthMaxValue, |
| 25612 | ML_base, ML_bits, |
| 25613 | matchlengthLog); |
| 25614 | dictPtr += matchlengthHeaderSize; |
| 25615 | } |
| 25616 | |
| 25617 | { short litlengthNCount[MaxLL+1]; |
| 25618 | unsigned litlengthMaxValue = MaxLL, litlengthLog; |
no test coverage detected