Skip to content

Commit

Permalink
Fix CI failures
Browse files Browse the repository at this point in the history
  • Loading branch information
binhdvo committed Jan 19, 2022
1 parent c345bb7 commit 62230dd
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
8 changes: 4 additions & 4 deletions lib/compress/fse_compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -658,11 +658,11 @@ size_t FSE_estimateCompressedSize(const FSE_CTable* ct, const unsigned* count, u
const FSE_symbolCompressionTransform* const symbolTT = (const FSE_symbolCompressionTransform*)(FSCT);

size_t nbBits = 0;
int s;
for (s = 0; s <= (int)maxSymbolValue; ++s) {
nbBits += symbolTT[s].deltaNbBits * count[s];
U32 s;
for (s = 0; s <= maxSymbolValue; ++s) {
nbBits += FSE_bitCost(symbolTT, tableLog, s, 8 /* accuracyLog */) * count[s];
}
return nbBits >> 3;
return nbBits >> (8 + 3); /* accuracyLog + bit->byte */
}


Expand Down
9 changes: 4 additions & 5 deletions lib/compress/huf_compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
****************************************************************/

#define IMPROVEMENT_THRESHOLD 5 /* estimation can be off by 4 bytes, only shift if we're sure we're winning */
#define ESTIMATE_SIZE(c, result) CHECK_F(HUF_buildCTable(ct, count, maxSymbolValue, c)); \
#define ESTIMATE_SIZE(c, result) HUF_buildCTable(ct, count, maxSymbolValue, c); \
result = HUF_estimateCompressedSize(ct, count, maxSymbolValue) + HUF_getCTableSize(ct, maxSymbolValue, c);
unsigned HUF_optimalTableLog(unsigned maxTableLog, size_t srcSize, const unsigned* count, unsigned maxSymbolValue)
{
Expand All @@ -55,7 +55,7 @@ unsigned HUF_optimalTableLog(unsigned maxTableLog, size_t srcSize, const unsigne
U32 tableLog = maxTableLog;
size_t estimatedSize = 0;
size_t proposedSize = 0;
HUF_CElt ct[HUF_SYMBOLVALUE_MAX+1];
HUF_CElt ct[HUF_CTABLE_SIZE(HUF_SYMBOLVALUE_MAX)];
unsigned movedUp = 0;

/* initial bounds */
Expand Down Expand Up @@ -150,7 +150,6 @@ static size_t HUF_getWeightsSize(const void* weightTable, size_t wtSize, void* w
tableLog = FSE_optimalTableLog(tableLog, wtSize, maxSymbolValue);
CHECK_F(FSE_normalizeCount(wksp->norm, tableLog, wksp->count, wtSize, maxSymbolValue, /* useLowProbCount */ 0));
CHECK_F(FSE_buildCTable_wksp(wksp->CTable, wksp->norm, maxSymbolValue, tableLog, wksp->scratchBuffer, sizeof(wksp->scratchBuffer)));
/* table header estimation can be improved */
result += FSE_estimateNCountSize(wksp->norm, maxSymbolValue, tableLog) + FSE_estimateCompressedSize(wksp->CTable, wksp->count, maxSymbolValue, tableLog);

return result;
Expand Down Expand Up @@ -1441,17 +1440,17 @@ size_t HUF_compress4X_repeat (void* dst, size_t dstSize,
hufTable, repeat, preferRepeat, bmi2, suspectUncompressible);
}

#ifndef ZSTD_NO_UNUSED_FUNCTIONS
/** HUF_buildCTable() :
* @return : maxNbBits
* Note : count is used before tree is written, so they can safely overlap
*/
size_t HUF_buildCTable (HUF_CElt* tree, const unsigned* count, unsigned maxSymbolValue, unsigned maxNbBits)
size_t HUF_buildCTable(HUF_CElt* tree, const unsigned* count, unsigned maxSymbolValue, unsigned maxNbBits)
{
HUF_buildCTable_wksp_tables workspace;
return HUF_buildCTable_wksp(tree, count, maxSymbolValue, maxNbBits, &workspace, sizeof(workspace));
}

#ifndef ZSTD_NO_UNUSED_FUNCTIONS
size_t HUF_compress1X (void* dst, size_t dstSize,
const void* src, size_t srcSize,
unsigned maxSymbolValue, unsigned huffLog)
Expand Down
6 changes: 6 additions & 0 deletions lib/decompress/huf_decompress.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include "../common/error_private.h"
#include "../common/zstd_internal.h"

#include <stdio.h>

/* **************************************************************
* Constants
****************************************************************/
Expand Down Expand Up @@ -349,8 +351,10 @@ size_t HUF_readDTableX1_wksp_bmi2(HUF_DTable* DTable, const void* src, size_t sr
HUF_ReadDTableX1_Workspace* wksp = (HUF_ReadDTableX1_Workspace*)workSpace;

DEBUG_STATIC_ASSERT(HUF_DECOMPRESS_WORKSPACE_SIZE >= sizeof(*wksp));
fprintf(stderr, "bar a \n");
if (sizeof(*wksp) > wkspSize) return ERROR(tableLog_tooLarge);

fprintf(stderr, "bar b \n");
DEBUG_STATIC_ASSERT(sizeof(DTableDesc) == sizeof(HUF_DTable));
/* ZSTD_memset(huffWeight, 0, sizeof(huffWeight)); */ /* is not necessary, even though some analyzer complain ... */

Expand All @@ -363,7 +367,9 @@ size_t HUF_readDTableX1_wksp_bmi2(HUF_DTable* DTable, const void* src, size_t sr
U32 const maxTableLog = dtd.maxTableLog + 1;
U32 const targetTableLog = MIN(maxTableLog, HUF_DECODER_FAST_TABLELOG);
tableLog = HUF_rescaleStats(wksp->huffWeight, wksp->rankVal, nbSymbols, tableLog, targetTableLog);
fprintf(stderr, "bar c %d %d\n", tableLog, dtd.maxTableLog);
if (tableLog > (U32)(dtd.maxTableLog+1)) return ERROR(tableLog_tooLarge); /* DTable too small, Huffman tree cannot fit in */
fprintf(stderr, "bar d \n");
dtd.tableType = 0;
dtd.tableLog = (BYTE)tableLog;
ZSTD_memcpy(DTable, &dtd, sizeof(dtd));
Expand Down
6 changes: 4 additions & 2 deletions tests/fuzz/huf_round_trip.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,16 @@ int LLVMFuzzerTestOneInput(const uint8_t *src, size_t size)
void* rBuf = FUZZ_malloc(size);
void* cBuf = FUZZ_malloc(cBufSize);
HUF_CElt* ct = (HUF_CElt*)FUZZ_malloc(HUF_CTABLE_SIZE(maxSymbol));
tableLog = HUF_optimalTableLog(tableLog, size, count, maxSymbol);
FUZZ_ASSERT(tableLog <= 12);
HUF_DTable* dt = (HUF_DTable*)FUZZ_malloc(HUF_DTABLE_SIZE(tableLog) * sizeof(HUF_DTable));
dt[0] = tableLog * 0x01000001;

tableLog = HUF_optimalTableLog(tableLog, size, maxSymbol);
FUZZ_ASSERT(tableLog <= 12);
tableLog = HUF_buildCTable_wksp(ct, count, maxSymbol, tableLog, wksp, wkspSize);
fprintf(stderr, "foo a %zu\n", tableLog);
FUZZ_ZASSERT(tableLog);
size_t const tableSize = HUF_writeCTable_wksp(cBuf, cBufSize, ct, maxSymbol, tableLog, wksp, wkspSize);
fprintf(stderr, "foo b %zu\n", tableSize);
if (ERR_isError(tableSize)) {
/* Errors on uncompressible data or cBufSize too small */
goto _out;
Expand Down

0 comments on commit 62230dd

Please sign in to comment.