Dictionary format : * See : * https://github.com/facebook/zstd/blob/master/doc/zstd_compression_format.md#dictionary-format */ ! ZSTD_loadZstdDictionary() : * @return : dictID, or an error code * assumptions : magic number supposed already checked * dictSize supposed >= 8 */
| 16070 | * dictSize supposed >= 8 |
| 16071 | */ |
| 16072 | static size_t ZSTD_loadZstdDictionary(ZSTD_compressedBlockState_t* bs, |
| 16073 | ZSTD_matchState_t* ms, |
| 16074 | ZSTD_cwksp* ws, |
| 16075 | ZSTD_CCtx_params const* params, |
| 16076 | const void* dict, size_t dictSize, |
| 16077 | ZSTD_dictTableLoadMethod_e dtlm, |
| 16078 | void* workspace) |
| 16079 | { |
| 16080 | const BYTE* dictPtr = (const BYTE*)dict; |
| 16081 | const BYTE* const dictEnd = dictPtr + dictSize; |
| 16082 | short offcodeNCount[MaxOff+1]; |
| 16083 | unsigned offcodeMaxValue = MaxOff; |
| 16084 | size_t dictID; |
| 16085 | size_t eSize; |
| 16086 | |
| 16087 | ZSTD_STATIC_ASSERT(HUF_WORKSPACE_SIZE >= (1<<MAX(MLFSELog,LLFSELog))); |
| 16088 | assert(dictSize >= 8); |
| 16089 | assert(MEM_readLE32(dictPtr) == ZSTD_MAGIC_DICTIONARY); |
| 16090 | |
| 16091 | dictID = params->fParams.noDictIDFlag ? 0 : MEM_readLE32(dictPtr + 4 /* skip magic number */ ); |
| 16092 | eSize = ZSTD_loadCEntropy(bs, workspace, offcodeNCount, &offcodeMaxValue, dict, dictSize); |
| 16093 | FORWARD_IF_ERROR(eSize, "ZSTD_loadCEntropy failed"); |
| 16094 | dictPtr += eSize; |
| 16095 | |
| 16096 | { size_t const dictContentSize = (size_t)(dictEnd - dictPtr); |
| 16097 | U32 offcodeMax = MaxOff; |
| 16098 | if (dictContentSize <= ((U32)-1) - 128 KB) { |
| 16099 | U32 const maxOffset = (U32)dictContentSize + 128 KB; /* The maximum offset that must be supported */ |
| 16100 | offcodeMax = ZSTD_highbit32(maxOffset); /* Calculate minimum offset code required to represent maxOffset */ |
| 16101 | } |
| 16102 | /* All offset values <= dictContentSize + 128 KB must be representable */ |
| 16103 | FORWARD_IF_ERROR(ZSTD_checkDictNCount(offcodeNCount, offcodeMaxValue, MIN(offcodeMax, MaxOff)), ""); |
| 16104 | /* All repCodes must be <= dictContentSize and != 0*/ |
| 16105 | { U32 u; |
| 16106 | for (u=0; u<3; u++) { |
| 16107 | RETURN_ERROR_IF(bs->rep[u] == 0, dictionary_corrupted, ""); |
| 16108 | RETURN_ERROR_IF(bs->rep[u] > dictContentSize, dictionary_corrupted, ""); |
| 16109 | } } |
| 16110 | |
| 16111 | bs->entropy.fse.offcode_repeatMode = FSE_repeat_valid; |
| 16112 | bs->entropy.fse.matchlength_repeatMode = FSE_repeat_valid; |
| 16113 | bs->entropy.fse.litlength_repeatMode = FSE_repeat_valid; |
| 16114 | FORWARD_IF_ERROR(ZSTD_loadDictionaryContent( |
| 16115 | ms, NULL, ws, params, dictPtr, dictContentSize, dtlm), ""); |
| 16116 | return dictID; |
| 16117 | } |
| 16118 | } |
| 16119 | |
| 16120 | /** ZSTD_compress_insertDictionary() : |
| 16121 | * @return : dictID, or an error code */ |
no test coverage detected