summaryrefslogtreecommitdiffstats
path: root/fuzzer.c
diff options
context:
space:
mode:
authoryann.collet.73@gmail.com <yann.collet.73@gmail.com@650e7d94-2a16-8b24-b05c-7c0b3f6821cd>2013-03-30 21:11:40 (GMT)
committeryann.collet.73@gmail.com <yann.collet.73@gmail.com@650e7d94-2a16-8b24-b05c-7c0b3f6821cd>2013-03-30 21:11:40 (GMT)
commit647baabcef0effcfcb3cc0dadb2970db681c9d52 (patch)
treee1b075d6997600f677f39cb3a61b6182e5988f46 /fuzzer.c
parent633c51904ebc1e3d3f51d4793d24f4f39ce579cf (diff)
downloadlz4-647baabcef0effcfcb3cc0dadb2970db681c9d52.zip
lz4-647baabcef0effcfcb3cc0dadb2970db681c9d52.tar.gz
lz4-647baabcef0effcfcb3cc0dadb2970db681c9d52.tar.bz2
Updated : cmake/CMakeLists.txt, by Nobuhiro Iwamatsu
Updated : cmake/pack/CMakeLists.txt, by Dmitry Cherepanov lz4demo : CLI accept aggregated commands lz4demo : detect overwrite output lz4demo : new commands options (-hc, -y) git-svn-id: https://lz4.googlecode.com/svn/trunk@91 650e7d94-2a16-8b24-b05c-7c0b3f6821cd
Diffstat (limited to 'fuzzer.c')
-rw-r--r--fuzzer.c115
1 files changed, 58 insertions, 57 deletions
diff --git a/fuzzer.c b/fuzzer.c
index 11697fd..0a57f77 100644
--- a/fuzzer.c
+++ b/fuzzer.c
@@ -1,8 +1,8 @@
/*
fuzzer.c - Fuzzer test tool for LZ4
Copyright (C) Andrew Mahone - Yann Collet 2012
- Original code by Andrew Mahone / Modified by Yann Collet
- GPL v2 License
+ Original code by Andrew Mahone / Modified by Yann Collet
+ GPL v2 License
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -18,9 +18,9 @@
with this program; if not, write to the Free Software Foundation, Inc.,
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/
+ You can contact the author at :
+ - LZ4 homepage : http://fastcompression.blogspot.com/p/lz4.html
+ - LZ4 source repository : http://code.google.com/p/lz4/
*/
//**************************************
@@ -36,6 +36,7 @@
#include <stdio.h> // fgets, sscanf
#include <sys/timeb.h> // timeb
#include "lz4.h"
+#include "lz4hc.h"
//**************************************
@@ -79,8 +80,8 @@ static int FUZ_GetMilliSpan( int nTimeStart )
unsigned int FUZ_rand(unsigned int* src)
{
- *src = ((*src) * PRIME1) + PRIME2;
- return *src;
+ *src = ((*src) * PRIME1) + PRIME2;
+ return *src;
}
@@ -110,7 +111,7 @@ int FUZ_SecurityTest()
free(input);
free(output);
- printf(" Completed (r=%i)\n",r);
+ printf(" Completed (return = %i < 0)\n",r);
return 0;
}
@@ -125,30 +126,30 @@ int main() {
# define FUZ_avail ROUND_PAGE(FUZ_max)
const int off_full = FUZ_avail - FUZ_max;
unsigned char cbuf[FUZ_avail + PAGE_SIZE];
- unsigned int seed, cur_seq=PRIME3, seeds[NUM_SEQ], timestamp=FUZ_GetMilliStart();
+ unsigned int seed, cur_seq=PRIME3, seeds[NUM_SEQ], timestamp=FUZ_GetMilliStart();
int i, j, k, ret, len;
- char userInput[30] = {0};
+ char userInput[30] = {0};
- printf("starting LZ4 fuzzer\n");
- printf("Select an Initialisation number (default : random) : ");
- fflush(stdout);
- if ( fgets(userInput, sizeof userInput, stdin) )
- {
- if ( sscanf(userInput, "%d", &seed) == 1 ) {}
- else seed = FUZ_GetMilliSpan(timestamp);
- }
- printf("Seed = %u\n", seed);
+ printf("starting LZ4 fuzzer\n");
+ printf("Select an Initialisation number (default : random) : ");
+ fflush(stdout);
+ if ( fgets(userInput, sizeof userInput, stdin) )
+ {
+ if ( sscanf(userInput, "%d", &seed) == 1 ) {}
+ else seed = FUZ_GetMilliSpan(timestamp);
+ }
+ printf("Seed = %u\n", seed);
- FUZ_SecurityTest();
+ FUZ_SecurityTest();
- for (i = 0; i < 2048; i++)
+ for (i = 0; i < 2048; i++)
cbuf[FUZ_avail + i] = cbuf[FUZ_avail + 2048 + i] = FUZ_rand(&seed) >> 16;
for (i = 0; i < NB_ATTEMPTS; i++)
{
- printf("\r%7i /%7i\r", i, NB_ATTEMPTS);
-
- FUZ_rand(&seed);
+ printf("\r%7i /%7i\r", i, NB_ATTEMPTS);
+
+ FUZ_rand(&seed);
for (j = 0; j < NUM_SEQ; j++) {
seeds[j] = FUZ_rand(&seed) << 8;
seeds[j] ^= (FUZ_rand(&seed) >> 8) & 65535;
@@ -165,63 +166,63 @@ int main() {
buf[j] = FUZ_rand(&cur_seq) >> 16;
}
- // Test compression
+ // Test compression
ret = LZ4_compress_limitedOutput((const char*)buf, (char*)&cbuf[off_full], LEN, FUZ_max);
- if (ret == 0) { printf("compression failed despite sufficient space: seed %u, len %d\n", seed, LEN); goto _output_error; }
+ if (ret == 0) { printf("compression failed despite sufficient space: seed %u, len %d\n", seed, LEN); goto _output_error; }
len = ret;
- // Test decoding with output size being exactly what's necessary => must work
- ret = LZ4_uncompress((char*)&cbuf[off_full], (char*)testOut, LEN);
- if (ret<0) { printf("decompression failed despite correct space: seed %u, len %d\n", seed, LEN); goto _output_error; }
+ // Test decoding with output size being exactly what's necessary => must work
+ ret = LZ4_uncompress((char*)&cbuf[off_full], (char*)testOut, LEN);
+ if (ret<0) { printf("decompression failed despite correct space: seed %u, len %d\n", seed, LEN); goto _output_error; }
- // Test decoding with one byte missing => must fail
- ret = LZ4_uncompress((char*)&cbuf[off_full], (char*)testOut, LEN-1);
- if (ret>=0) { printf("decompression should have failed, due to Output Size being too small : seed %u, len %d\n", seed, LEN); goto _output_error; }
+ // Test decoding with one byte missing => must fail
+ ret = LZ4_uncompress((char*)&cbuf[off_full], (char*)testOut, LEN-1);
+ if (ret>=0) { printf("decompression should have failed, due to Output Size being too small : seed %u, len %d\n", seed, LEN); goto _output_error; }
- // Test decoding with one byte too much => must fail
- ret = LZ4_uncompress((char*)&cbuf[off_full], (char*)testOut, LEN+1);
- if (ret>=0) { printf("decompression should have failed, due to Output Size being too large : seed %u, len %d\n", seed, LEN); goto _output_error; }
+ // Test decoding with one byte too much => must fail
+ ret = LZ4_uncompress((char*)&cbuf[off_full], (char*)testOut, LEN+1);
+ if (ret>=0) { printf("decompression should have failed, due to Output Size being too large : seed %u, len %d\n", seed, LEN); goto _output_error; }
- // Test decoding with enough output size => must work
- ret = LZ4_uncompress_unknownOutputSize((char*)&cbuf[off_full], (char*)testOut, len, LEN+1);
- if (ret<0) { printf("decompression failed despite sufficient space: seed %u, len %d\n", seed, LEN); goto _output_error; }
+ // Test decoding with enough output size => must work
+ ret = LZ4_uncompress_unknownOutputSize((char*)&cbuf[off_full], (char*)testOut, len, LEN+1);
+ if (ret<0) { printf("decompression failed despite sufficient space: seed %u, len %d\n", seed, LEN); goto _output_error; }
- // Test decoding with output size being exactly what's necessary => must work
- ret = LZ4_uncompress_unknownOutputSize((char*)&cbuf[off_full], (char*)testOut, len, LEN);
- if (ret<0) { printf("decompression failed despite sufficient space: seed %u, len %d\n", seed, LEN); goto _output_error; }
+ // Test decoding with output size being exactly what's necessary => must work
+ ret = LZ4_uncompress_unknownOutputSize((char*)&cbuf[off_full], (char*)testOut, len, LEN);
+ if (ret<0) { printf("decompression failed despite sufficient space: seed %u, len %d\n", seed, LEN); goto _output_error; }
- // Test decoding with output size being one byte too short => must fail
- ret = LZ4_uncompress_unknownOutputSize((char*)&cbuf[off_full], (char*)testOut, len, LEN-1);
- if (ret>=0) { printf("decompression should have failed, due to Output Size being too small : seed %u, len %d\n", seed, LEN); goto _output_error; }
+ // Test decoding with output size being one byte too short => must fail
+ ret = LZ4_uncompress_unknownOutputSize((char*)&cbuf[off_full], (char*)testOut, len, LEN-1);
+ if (ret>=0) { printf("decompression should have failed, due to Output Size being too small : seed %u, len %d\n", seed, LEN); goto _output_error; }
- // Test decoding with input size being one byte too short => must fail
- ret = LZ4_uncompress_unknownOutputSize((char*)&cbuf[off_full], (char*)testOut, len-1, LEN);
- if (ret>=0) { printf("decompression should have failed, due to input size being too small : seed %u, len %d\n", seed, LEN); goto _output_error; }
+ // Test decoding with input size being one byte too short => must fail
+ ret = LZ4_uncompress_unknownOutputSize((char*)&cbuf[off_full], (char*)testOut, len-1, LEN);
+ if (ret>=0) { printf("decompression should have failed, due to input size being too small : seed %u, len %d\n", seed, LEN); goto _output_error; }
- // Test decoding with input size being one byte too large => must fail
- ret = LZ4_uncompress_unknownOutputSize((char*)&cbuf[off_full], (char*)testOut, len+1, LEN);
- if (ret>=0) { printf("decompression should have failed, due to input size being too large : seed %u, len %d\n", seed, LEN); goto _output_error; }
+ // Test decoding with input size being one byte too large => must fail
+ ret = LZ4_uncompress_unknownOutputSize((char*)&cbuf[off_full], (char*)testOut, len+1, LEN);
+ if (ret>=0) { printf("decompression should have failed, due to input size being too large : seed %u, len %d\n", seed, LEN); goto _output_error; }
- // Test compression with output size being exactly what's necessary (should work)
+ // Test compression with output size being exactly what's necessary (should work)
ret = LZ4_compress_limitedOutput((const char*)buf, (char*)&cbuf[FUZ_avail-len], LEN, len);
if (!test_canary(&cbuf[FUZ_avail])) { printf("compression overran output buffer: seed %u, len %d, olen %d\n", seed, LEN, len); goto _output_error; }
if (ret == 0) { printf("compression failed despite sufficient space: seed %u, len %d\n", seed, LEN); goto _output_error; }
- // Test compression with just one missing byte into output buffer => must fail
+ // Test compression with just one missing byte into output buffer => must fail
ret = LZ4_compress_limitedOutput((const char*)buf, (char*)&cbuf[FUZ_avail-(len-1)], LEN, len-1);
if (ret) { printf("compression overran output buffer: seed %u, len %d, olen %d => ret %d", seed, LEN, len-1, ret); goto _output_error; }
if (!test_canary(&cbuf[FUZ_avail])) { printf("compression overran output buffer: seed %u, len %d, olen %d", seed, LEN, len-1); goto _output_error; }
- bytes += LEN;
+ bytes += LEN;
cbytes += len;
}
- printf("all tests completed successfully \n");
+ printf("all tests completed successfully \n");
printf("compression ratio: %0.3f%%\n", (double)cbytes/bytes*100);
- getchar();
+ getchar();
return 0;
_output_error:
- getchar();
- return 1;
+ getchar();
+ return 1;
}