summaryrefslogtreecommitdiffstats
path: root/programs
diff options
context:
space:
mode:
authorYann Collet <yann.collet.73@gmail.com>2015-04-20 08:24:25 (GMT)
committerYann Collet <yann.collet.73@gmail.com>2015-04-20 08:24:25 (GMT)
commit197982ec6cf449734f78d849ed4a845e075b2cf4 (patch)
tree3fd9399b710a25c3542c235da89d619b326041d8 /programs
parent409f816267b00e2307fabc59cc6ddffcc605a1ec (diff)
downloadlz4-197982ec6cf449734f78d849ed4a845e075b2cf4.zip
lz4-197982ec6cf449734f78d849ed4a845e075b2cf4.tar.gz
lz4-197982ec6cf449734f78d849ed4a845e075b2cf4.tar.bz2
Fixed unfinished frame (issue #75)
Diffstat (limited to 'programs')
-rw-r--r--programs/Makefile8
-rw-r--r--programs/frametest.c14
-rw-r--r--programs/lz4io.c21
3 files changed, 34 insertions, 9 deletions
diff --git a/programs/Makefile b/programs/Makefile
index 910516f..b0e30d8 100644
--- a/programs/Makefile
+++ b/programs/Makefile
@@ -207,7 +207,13 @@ test-lz4-multiple: lz4 datagen
./lz4 -f -m tmp1 notHere tmp2; echo $$?
@rm tmp*
-test-lz4: lz4 datagen test-lz4-multiple test-lz4-sparse test-lz4-contentSize test-lz4-frame-concatenation
+# test-lz4-multiple test-lz4-sparse test-lz4-contentSize test-lz4-frame-concatenation
+test-lz4: lz4 datagen
+ @echo ---- test erroneous data ----
+ ./datagen -s1 | ./lz4 -vf - tmp
+ tmpSize= $(stat -c%s "tmp")
+ echo "Size of tmp = $tmpSize bytes."
+ rm tmp*
@echo ---- test lz4 basic compression/decompression ----
./datagen -g0 | ./lz4 -v | ./lz4 -t
./datagen -g16KB | ./lz4 -9 | ./lz4 -t
diff --git a/programs/frametest.c b/programs/frametest.c
index ed131d2..237fd4a 100644
--- a/programs/frametest.c
+++ b/programs/frametest.c
@@ -279,6 +279,20 @@ int basicTests(U32 seed, double compressibility)
DISPLAYLEVEL(4, "Reusing decompression context \n");
{
+ size_t iSize = compressedBufferSize - 4;
+ DISPLAYLEVEL(3, "Missing last 4 bytes : ");
+ errorCode = LZ4F_decompress(dCtx, decodedBuffer, &decodedBufferSize, compressedBuffer, &iSize, NULL);
+ if (LZ4F_isError(errorCode)) goto _output_error;
+ if (!errorCode) goto _output_error;
+ DISPLAYLEVEL(3, "indeed, request %u bytes \n", (unsigned)errorCode);
+ iSize = errorCode;
+ errorCode = LZ4F_decompress(dCtx, decodedBuffer, &decodedBufferSize, compressedBuffer, &iSize, NULL);
+ if (errorCode != 0) goto _output_error;
+ crcDest = XXH64(decodedBuffer, COMPRESSIBLE_NOISE_LENGTH, 1);
+ if (crcDest != crcOrig) goto _output_error;
+ }
+
+ {
size_t oSize = 0;
size_t iSize = 0;
LZ4F_frameInfo_t fi;
diff --git a/programs/lz4io.c b/programs/lz4io.c
index e0c69d8..cbf366b 100644
--- a/programs/lz4io.c
+++ b/programs/lz4io.c
@@ -807,7 +807,7 @@ static void LZ4IO_freeDResources(dRess_t ress)
static unsigned long long LZ4IO_decompressLZ4F(dRess_t ress, FILE* srcFile, FILE* dstFile)
{
unsigned long long filesize = 0;
- LZ4F_errorCode_t errorCode;
+ LZ4F_errorCode_t nextToLoad;
unsigned storedSkips = 0;
/* Init feed with magic number (already consumed from FILE* sFile) */
@@ -815,8 +815,8 @@ static unsigned long long LZ4IO_decompressLZ4F(dRess_t ress, FILE* srcFile, FILE
size_t inSize = MAGICNUMBER_SIZE;
size_t outSize= 0;
LZ4IO_writeLE32(ress.srcBuffer, LZ4IO_MAGICNUMBER);
- errorCode = LZ4F_decompress(ress.dCtx, ress.dstBuffer, &outSize, ress.srcBuffer, &inSize, NULL);
- if (LZ4F_isError(errorCode)) EXM_THROW(62, "Header error : %s", LZ4F_getErrorName(errorCode));
+ nextToLoad = LZ4F_decompress(ress.dCtx, ress.dstBuffer, &outSize, ress.srcBuffer, &inSize, NULL);
+ if (LZ4F_isError(nextToLoad)) EXM_THROW(62, "Header error : %s", LZ4F_getErrorName(nextToLoad));
}
/* Main Loop */
@@ -824,18 +824,20 @@ static unsigned long long LZ4IO_decompressLZ4F(dRess_t ress, FILE* srcFile, FILE
{
size_t readSize;
size_t pos = 0;
+ size_t decodedBytes = ress.dstBufferSize;
/* Read input */
readSize = fread(ress.srcBuffer, 1, ress.srcBufferSize, srcFile);
- if (!readSize) break; /* empty file or stream */
+ if (!readSize)
+ break; /* empty file or stream */
- while (pos < readSize)
+ while (nextToLoad && ((pos < readSize) || (decodedBytes == ress.dstBufferSize))) /* still to read, or still to flush */
{
/* Decode Input (at least partially) */
size_t remaining = readSize - pos;
- size_t decodedBytes = ress.dstBufferSize;
- errorCode = LZ4F_decompress(ress.dCtx, ress.dstBuffer, &decodedBytes, (char*)(ress.srcBuffer)+pos, &remaining, NULL);
- if (LZ4F_isError(errorCode)) EXM_THROW(66, "Decompression error : %s", LZ4F_getErrorName(errorCode));
+ decodedBytes = ress.dstBufferSize;
+ nextToLoad = LZ4F_decompress(ress.dCtx, ress.dstBuffer, &decodedBytes, (char*)(ress.srcBuffer)+pos, &remaining, NULL);
+ if (LZ4F_isError(nextToLoad)) EXM_THROW(66, "Decompression error : %s", LZ4F_getErrorName(nextToLoad));
pos += remaining;
if (decodedBytes)
@@ -850,6 +852,9 @@ static unsigned long long LZ4IO_decompressLZ4F(dRess_t ress, FILE* srcFile, FILE
LZ4IO_fwriteSparseEnd(dstFile, storedSkips);
+ if (nextToLoad!=0)
+ EXM_THROW(67, "Unfinished stream");
+
return filesize;
}