From 95cc6cef6444b202a93ba414b7a9996eb2c72ca3 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Tue, 16 Dec 2014 02:13:19 +0100 Subject: Fixed : bug within LZ4 HC streaming mode, reported by James Boyle --- NEWS | 3 ++- lib/lz4.c | 2 +- lib/lz4hc.c | 1 + programs/Makefile | 1 + programs/datagen.c | 41 ++++++++++++++++++++++------------------- 5 files changed, 27 insertions(+), 21 deletions(-) diff --git a/NEWS b/NEWS index 67f63a4..21c54dc 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,7 @@ r126: New : lz4frame API is now integrated into liblz4 -Fixed : GCC 4.9 bug on highest performance settings, reported by Greg Slazinski +Fixed : GCC 4.9 bug on highest performance settings, reported by Greg Slazinski +Fixed : bug within LZ4 HC streaming mode, reported by James Boyle r125: Changed : endian and alignment code diff --git a/lib/lz4.c b/lib/lz4.c index d622584..a365375 100644 --- a/lib/lz4.c +++ b/lib/lz4.c @@ -541,7 +541,7 @@ static int LZ4_compress_generic( break; } if ((tableType == byU16) && (inputSize>=LZ4_64Klimit)) return 0; /* Size too large (not within 64K limit) */ - if (inputSizebase = streamPtr->end - endIndex; streamPtr->dictLimit = endIndex - dictSize; streamPtr->lowLimit = endIndex - dictSize; + if (streamPtr->nextToUpdate < streamPtr->dictLimit) streamPtr->nextToUpdate = streamPtr->dictLimit; } return dictSize; } diff --git a/programs/Makefile b/programs/Makefile index f097d06..67218c1 100644 --- a/programs/Makefile +++ b/programs/Makefile @@ -142,6 +142,7 @@ test-travis: $(TRAVIS_TARGET) test-lz4: lz4 datagen ./datagen -g16KB | ./lz4 -9 | ./lz4 -vdq > $(VOID) ./datagen | ./lz4 | ./lz4 -vdq > $(VOID) + ./datagen -g6M -p100 | ./lz4 -9BD | ./lz4 -vdq > $(VOID) ./datagen -g256MB | ./lz4 -vqB4D | ./lz4 -vdq > $(VOID) ./datagen -g6GB | ./lz4 -vqB5D | ./lz4 -vdq > $(VOID) # test frame concatenation with null-length frame diff --git a/programs/datagen.c b/programs/datagen.c index 706c30f..0f07477 100644 --- a/programs/datagen.c +++ b/programs/datagen.c @@ -1,6 +1,7 @@ /* datagen.c - compressible data generator test tool - Copyright (C) Yann Collet 2012-2014 + Copyright (C) Yann Collet 2012-2015 + GPL v2 License This program is free software; you can redistribute it and/or modify @@ -18,8 +19,9 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. You can contact the author at : - - LZ4 homepage : http://fastcompression.blogspot.com/p/lz4.html - - LZ4 source repository : http://code.google.com/p/lz4/ + - LZ4 source repository : http://code.google.com/p/lz4 + - LZ4 source mirror : https://github.com/Cyan4973/lz4 + - LZ4 public forum : https://groups.google.com/forum/#!forum/lz4c */ /************************************** @@ -31,7 +33,6 @@ /************************************** Includes **************************************/ -//#include #include // fgets, sscanf #include // strcmp @@ -59,11 +60,11 @@ Constants **************************************/ #ifndef LZ4_VERSION -# define LZ4_VERSION "rc118" +# define LZ4_VERSION "r125" #endif -#define KB *(1U<<10) -#define MB *(1U<<20) +#define KB *(1 <<10) +#define MB *(1 <<20) #define GB *(1U<<30) #define CDG_SIZE_DEFAULT (64 KB) @@ -83,13 +84,13 @@ /************************************** Local Parameters **************************************/ -static int no_prompt = 0; -static char* programName; -static int displayLevel = 2; +static unsigned no_prompt = 0; +static char* programName; +static unsigned displayLevel = 2; /********************************************************* - Fuzzer functions + functions *********************************************************/ #define CDG_rotl32(x,r) ((x << r) | (x >> (32 - r))) @@ -113,10 +114,11 @@ static void CDG_generate(U64 size, U32* seed, double proba) BYTE* buff = fullbuff + 32 KB; U64 total=0; U32 P32 = (U32)(32768 * proba); - U32 pos=0; + U32 pos=1; U32 genBlockSize = 128 KB; // Build initial prefix + fullbuff[0] = CDG_RANDCHAR; while (pos<32 KB) { // Select : Literal (char) or Match (within 32K) @@ -135,9 +137,7 @@ static void CDG_generate(U64 size, U32* seed, double proba) else { // Literal (noise) - U32 d; - int length = CDG_RANDLENGTH; - d = pos + length; + U32 d = pos + CDG_RANDLENGTH; while (pos < d) fullbuff[pos++] = CDG_RANDCHAR; } } @@ -175,8 +175,10 @@ static void CDG_generate(U64 size, U32* seed, double proba) while (pos < d) buff[pos++] = CDG_RANDCHAR; } } + // output datagen pos=0; - for (;pos+512<=genBlockSize;pos+=512) printf("%512.512s", buff+pos); + for (;pos+512<=genBlockSize;pos+=512) + printf("%512.512s", buff+pos); for (;pos