From d7399232a4d547d7183c193997e17d534d000f52 Mon Sep 17 00:00:00 2001 From: "W. Felix Handte" Date: Wed, 5 Aug 2020 12:46:32 -0400 Subject: Remove Extraneous Reset in LZ4_attach_dictionary() Nothing internally sets dirty anymore. The only way to get that is if you use an uninitialized context, in which case your warranty is void anyways. --- lib/lz4.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/lib/lz4.c b/lib/lz4.c index ae50d54..46c8e11 100644 --- a/lib/lz4.c +++ b/lib/lz4.c @@ -1455,12 +1455,6 @@ void LZ4_attach_dictionary(LZ4_stream_t* workingStream, const LZ4_stream_t* dict workingStream, dictionaryStream, dictCtx != NULL ? dictCtx->dictSize : 0); - /* Calling LZ4_resetStream_fast() here makes sure that changes will not be - * erased by subsequent calls to LZ4_resetStream_fast() in case stream was - * marked as having dirty context, e.g. requiring full reset. - */ - LZ4_resetStream_fast(workingStream); - if (dictCtx != NULL) { /* If the current offset is zero, we will never look in the * external dictionary context, since there is no value a table -- cgit v0.12 From 9af86f084101b08e87e7c1509e19aa05d27271ed Mon Sep 17 00:00:00 2001 From: "W. Felix Handte" Date: Thu, 6 Aug 2020 16:06:40 -0400 Subject: Remove dirty Field From LZ4_stream_t --- lib/lz4.c | 10 ---------- lib/lz4.h | 6 ++---- tests/fuzzer.c | 4 ---- 3 files changed, 2 insertions(+), 18 deletions(-) diff --git a/lib/lz4.c b/lib/lz4.c index 46c8e11..148827e 100644 --- a/lib/lz4.c +++ b/lib/lz4.c @@ -758,15 +758,6 @@ LZ4_FORCE_INLINE void LZ4_prepareTable(LZ4_stream_t_internal* const cctx, const int inputSize, const tableType_t tableType) { - /* If compression failed during the previous step, then the context - * is marked as dirty, therefore, it has to be fully reset. - */ - if (cctx->dirty) { - DEBUGLOG(5, "LZ4_prepareTable: Full reset for %p", cctx); - MEM_INIT(cctx, 0, sizeof(LZ4_stream_t_internal)); - return; - } - /* If the table hasn't been used, it's guaranteed to be zeroed out, and is * therefore safe to use no matter what mode we're in. Otherwise, we figure * out if it's safe to leave as is or whether it needs to be reset. @@ -1506,7 +1497,6 @@ int LZ4_compress_fast_continue (LZ4_stream_t* LZ4_stream, DEBUGLOG(5, "LZ4_compress_fast_continue (inputSize=%i)", inputSize); - if (streamPtr->dirty) { return 0; } /* Uninitialized structure detected */ LZ4_renormDictT(streamPtr, inputSize); /* avoid index overflow */ if (acceleration < 1) acceleration = ACCELERATION_DEFAULT; diff --git a/lib/lz4.h b/lib/lz4.h index 32108e2..9b3d758 100644 --- a/lib/lz4.h +++ b/lib/lz4.h @@ -564,8 +564,7 @@ typedef struct LZ4_stream_t_internal LZ4_stream_t_internal; struct LZ4_stream_t_internal { uint32_t hashTable[LZ4_HASH_SIZE_U32]; uint32_t currentOffset; - uint16_t dirty; - uint16_t tableType; + uint32_t tableType; const uint8_t* dictionary; const LZ4_stream_t_internal* dictCtx; uint32_t dictSize; @@ -584,8 +583,7 @@ typedef struct LZ4_stream_t_internal LZ4_stream_t_internal; struct LZ4_stream_t_internal { unsigned int hashTable[LZ4_HASH_SIZE_U32]; unsigned int currentOffset; - unsigned short dirty; - unsigned short tableType; + unsigned int tableType; const unsigned char* dictionary; const LZ4_stream_t_internal* dictCtx; unsigned int dictSize; diff --git a/tests/fuzzer.c b/tests/fuzzer.c index 8a095c4..3d7456a 100644 --- a/tests/fuzzer.c +++ b/tests/fuzzer.c @@ -787,7 +787,6 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c LZ4_attach_dictionary(&LZ4_stream, &LZ4dictBody); blockContinueCompressedSize = LZ4_compress_fast_continue(&LZ4_stream, block, compressedBuffer, blockSize, (int)compressedBufferSize, 1); FUZ_CHECKTEST(blockContinueCompressedSize==0, "LZ4_compress_fast_continue using extDictCtx failed"); - FUZ_CHECKTEST(LZ4_stream.internal_donotuse.dirty, "context should be good"); /* In the future, it might be desirable to let extDictCtx mode's * output diverge from the output generated by regular extDict mode. @@ -812,7 +811,6 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c FUZ_CHECKTEST(ret<=0, "LZ4_compress_fast_continue using extDictCtx should work : enough size available within output buffer"); FUZ_CHECKTEST(ret != expectedSize, "LZ4_compress_fast_continue using extDictCtx produced different-sized output"); FUZ_CHECKTEST(XXH32(compressedBuffer, (size_t)ret, 0) != expectedCrc, "LZ4_compress_fast_continue using extDictCtx produced different output"); - FUZ_CHECKTEST(LZ4_stream.internal_donotuse.dirty, "context should be good"); FUZ_DISPLAYTEST(); LZ4_resetStream_fast(&LZ4_stream); @@ -822,7 +820,6 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c FUZ_CHECKTEST(ret<=0, "LZ4_compress_fast_continue using extDictCtx with re-used context should work : enough size available within output buffer"); FUZ_CHECKTEST(ret != expectedSize, "LZ4_compress_fast_continue using extDictCtx produced different-sized output"); FUZ_CHECKTEST(XXH32(compressedBuffer, (size_t)ret, 0) != expectedCrc, "LZ4_compress_fast_continue using extDictCtx produced different output"); - FUZ_CHECKTEST(LZ4_stream.internal_donotuse.dirty, "context should be good"); } /* Decompress with dictionary as external */ @@ -1115,7 +1112,6 @@ static void FUZ_unitTests(int compressionLevel) LZ4_initStream(&streamingState, sizeof(streamingState)); result = LZ4_compress_fast_continue(&streamingState, testInput, testCompressed, testCompressedSize, testCompressedSize-1, 1); FUZ_CHECKTEST(result==0, "LZ4_compress_fast_continue() compression failed!"); - FUZ_CHECKTEST(streamingState.internal_donotuse.dirty, "context should be clean") result = LZ4_decompress_safe(testCompressed, testVerify, result, testCompressedSize); FUZ_CHECKTEST(result!=(int)testCompressedSize, "LZ4_decompress_safe() decompression failed"); -- cgit v0.12 From a78235e6ad87049f2d1c5f98ecc0ccd16ca71f95 Mon Sep 17 00:00:00 2001 From: "W. Felix Handte" Date: Mon, 10 Aug 2020 13:46:31 -0400 Subject: Fix Enum Casts Fixes `-Wsign-compare` issues. --- lib/lz4.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/lz4.c b/lib/lz4.c index 148827e..6322434 100644 --- a/lib/lz4.c +++ b/lib/lz4.c @@ -762,9 +762,9 @@ LZ4_prepareTable(LZ4_stream_t_internal* const cctx, * therefore safe to use no matter what mode we're in. Otherwise, we figure * out if it's safe to leave as is or whether it needs to be reset. */ - if (cctx->tableType != clearedTable) { + if ((tableType_t)cctx->tableType != clearedTable) { assert(inputSize >= 0); - if (cctx->tableType != tableType + if ((tableType_t)cctx->tableType != tableType || ((tableType == byU16) && cctx->currentOffset + (unsigned)inputSize >= 0xFFFFU) || ((tableType == byU32) && cctx->currentOffset > 1 GB) || tableType == byPtr @@ -773,7 +773,7 @@ LZ4_prepareTable(LZ4_stream_t_internal* const cctx, DEBUGLOG(4, "LZ4_prepareTable: Resetting table in %p", cctx); MEM_INIT(cctx->hashTable, 0, LZ4_HASHTABLESIZE); cctx->currentOffset = 0; - cctx->tableType = clearedTable; + cctx->tableType = (U32)clearedTable; } else { DEBUGLOG(4, "LZ4_prepareTable: Re-use hash table (no reset)"); } @@ -864,7 +864,7 @@ LZ4_FORCE_INLINE int LZ4_compress_generic( cctx->dictSize += (U32)inputSize; } cctx->currentOffset += (U32)inputSize; - cctx->tableType = (U16)tableType; + cctx->tableType = (U32)tableType; if (inputSizecurrentOffset; dict->dictionary = p; dict->dictSize = (U32)(dictEnd - p); - dict->tableType = tableType; + dict->tableType = (U32)tableType; while (p <= dictEnd-HASH_UNIT) { LZ4_putPosition(p, dict->hashTable, tableType, base); -- cgit v0.12