From: Sen Huang Date: Thu, 7 Nov 2019 16:32:08 +0000 (-0500) Subject: Integrated refactor into getDictHeaderSize, now passes tests X-Git-Tag: v1.4.5^2~157^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=04fb42b4f35b256b61108dcf0167cf21d81fcfbe;p=thirdparty%2Fzstd.git Integrated refactor into getDictHeaderSize, now passes tests --- diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index 0ebbf1926..3c04718e3 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -2772,8 +2772,8 @@ size_t ZSTD_loadCEntropy(ZSTD_compressedBlockState_t* bs, void* workspace, short* offcodeNCount, unsigned* offcodeMaxValue, const void* const dict, size_t dictSize) { - const BYTE* dictPtr = (const BYTE*)dict; - const BYTE* const dictEnd = dictPtr + dictSize - 8; + const BYTE* dictPtr = (const BYTE*)dict + 8; + const BYTE* const dictEnd = dictPtr + dictSize; { unsigned maxSymbolValue = 255; size_t const hufHeaderSize = HUF_readCTable((HUF_CElt*)bs->entropy.huf.CTable, &maxSymbolValue, dictPtr, dictEnd-dictPtr); @@ -2852,15 +2852,17 @@ static size_t ZSTD_loadZstdDictionary(ZSTD_compressedBlockState_t* bs, ZSTD_dictTableLoadMethod_e dtlm, void* workspace) { - size_t dictID; - size_t eSize; const BYTE* dictPtr = (const BYTE*)dict; const BYTE* const dictEnd = dictPtr + dictSize; short offcodeNCount[MaxOff+1]; unsigned offcodeMaxValue = MaxOff; + size_t dictID; + size_t eSize; + ZSTD_STATIC_ASSERT(HUF_WORKSPACE_SIZE >= (1< 8); assert(MEM_readLE32(dictPtr) == ZSTD_MAGIC_DICTIONARY); + eSize = ZSTD_loadCEntropy(bs, workspace, offcodeNCount, &offcodeMaxValue, dict, dictSize); dictPtr += 4; /* skip magic number */ diff --git a/lib/dictBuilder/zdict.c b/lib/dictBuilder/zdict.c index 6db57b144..6d76fb521 100644 --- a/lib/dictBuilder/zdict.c +++ b/lib/dictBuilder/zdict.c @@ -48,7 +48,7 @@ # define ZDICT_STATIC_LINKING_ONLY #endif #include "zdict.h" -#include "decompress/zstd_decompress_internal.h" /* ZSTD_entropyDTables_t */ +#include "compress/zstd_compress_internal.h" /* ZSTD_loadCEntropy() */ /*-************************************* @@ -105,14 +105,19 @@ size_t ZDICT_getDictHeaderSize(const void* dictBuffer, size_t dictSize) if (dictSize <= 8 || MEM_readLE32(dictBuffer) != ZSTD_MAGIC_DICTIONARY) return 0; { size_t headerSize; - ZSTD_entropyDTables_t* dummyEntropyTables = (ZSTD_entropyDTables_t*)malloc(sizeof(ZSTD_entropyDTables_t)); - if (!dummyEntropyTables) { + 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; } - dummyEntropyTables->hufTable[0] = (HUF_DTable)((HufLog)*0x1000001); - headerSize = ZSTD_loadDEntropy(dummyEntropyTables, dictBuffer, dictSize); - free(dummyEntropyTables); - return ZSTD_isError(headerSize) ? 0 : headerSize; + + headerSize = ZSTD_loadCEntropy(dummyBs, wksp, offcodeNCount, &offcodeMaxValue, dictBuffer, dictSize); + free(dummyBs); + free(wksp); + free(offcodeNCount); + return headerSize; } }