diff options
Diffstat (limited to 'testsuite')
-rw-r--r-- | testsuite/COPYING.lz | bin | 0 -> 11540 bytes | |||
-rwxr-xr-x | testsuite/check.sh | 67 | ||||
-rw-r--r-- | testsuite/unzcrash.cc | 85 |
3 files changed, 152 insertions, 0 deletions
diff --git a/testsuite/COPYING.lz b/testsuite/COPYING.lz Binary files differnew file mode 100644 index 0000000..a09b1e8 --- /dev/null +++ b/testsuite/COPYING.lz diff --git a/testsuite/check.sh b/testsuite/check.sh new file mode 100755 index 0000000..83ebc6f --- /dev/null +++ b/testsuite/check.sh @@ -0,0 +1,67 @@ +#! /bin/sh +# check script for Lzip - A data compressor based on the LZMA algorithm +# Copyright (C) 2008, 2009 Antonio Diaz Diaz. +# +# This script is free software: you have unlimited permission +# to copy, distribute and modify it. + +objdir=`pwd` +testdir=`cd "$1" ; pwd` +LZIP="${objdir}"/lzip +framework_failure() { echo 'failure in testing framework'; exit 1; } + +if [ ! -x "${LZIP}" ] ; then + echo "${LZIP}: cannot execute" + exit 1 +fi + +if [ -d tmp ] ; then rm -r tmp ; fi +mkdir tmp +echo -n "testing lzip..." +cd "${objdir}"/tmp + +cat "${testdir}"/../COPYING > in || framework_failure +fail=0 + +"${LZIP}" -cd "${testdir}"/COPYING.lz > copy || fail=1 +cmp in copy || fail=1 + +for i in 1 2 3 4 5 6 7 8 9; do + "${LZIP}" -k -$i in || fail=1 + mv -f in.lz copy.lz || fail=1 + echo -n "garbage" >> copy.lz || fail=1 + "${LZIP}" -df copy.lz || fail=1 + cmp in copy || fail=1 + echo -n . +done + +for i in 1 2 3 4 5 6 7 8 9; do + "${LZIP}" -c -$i in > out || fail=1 + echo -n "g" >> out || fail=1 + "${LZIP}" -cd out > copy || fail=1 + cmp in copy || fail=1 + echo -n . +done + +for i in 1 2 3 4 5 6 7 8 9; do + "${LZIP}" -c -$i < in > out || fail=1 + "${LZIP}" -d < out > copy || fail=1 + cmp in copy || fail=1 + echo -n . +done + +for i in 1 2 3 4 5 6 7 8 9; do + "${LZIP}" -f -$i -o out < in || fail=1 + "${LZIP}" -df -o copy < out.lz || fail=1 + cmp in copy || fail=1 + echo -n . +done + +echo +if test ${fail} = 0; then + echo "tests completed successfully." + if cd "${objdir}" ; then rm -r tmp ; fi +else + echo "tests failed." +fi +exit ${fail} diff --git a/testsuite/unzcrash.cc b/testsuite/unzcrash.cc new file mode 100644 index 0000000..bf44628 --- /dev/null +++ b/testsuite/unzcrash.cc @@ -0,0 +1,85 @@ +/* Unzcrash - A test program written to test robustness to + decompression of corrupted data. + Inspired by unzcrash.c from Julian Seward's bzip2. + Copyright (C) 2008, 2009 Antonio Diaz Diaz. + + This program is free software: you have unlimited permission + to copy, distribute and modify it. + + Usage is: + unzcrash "lzip -tv" filename.lz + + This program reads the specified file and then repeatedly + decompresses it, increasing 256 times each byte of the compressed + data, so as to test all possible one-byte errors. This should not + cause any invalid memory accesses. If it does, please, report it as + a bug. + + Compile this file with the command: + g++ -O2 -Wall -W -o unzcrash testsuite/unzcrash.cc +*/ + +#include <cstdio> +#include <cstdlib> +#include <stdint.h> +#include <signal.h> +#include <unistd.h> + + +int main( const int argc, const char * argv[] ) + { + if( argc < 3 ) + { + std::fprintf( stderr, "Usage: unzcrash \"lzip -tv\" filename.lz\n" ); + return 1; + } + + FILE *f = std::fopen( argv[2], "rb" ); + if( !f ) + { + std::fprintf( stderr, "Can't open file `%s' for reading\n", argv[2] ); + return 1; + } + + const int buffer_size = 1 << 20; + uint8_t buffer[buffer_size]; + const int size = std::fread( buffer, 1, buffer_size, f ); + if( size >= buffer_size ) + { + std::fprintf( stderr, "input file `%s' too big.\n", argv[2] ); + return 1; + } + std::fclose( f ); + + f = popen( argv[1], "w" ); + if( !f ) + { + std::fprintf( stderr, "incorrect parameters or too many files.\n" ); + return 1; + } + const int wr = std::fwrite( buffer, 1, size, f ); + if( wr != size || pclose( f ) != 0 ) + { + std::fprintf( stderr, "Could not run `%s' or other error.\n", argv[1] ); + return 1; + } + + signal( SIGPIPE, SIG_IGN ); + + for( int byte = 0; byte < size; ++byte ) + { + std::fprintf( stderr, "byte %d\n", byte ); + for( int i = 0; i < 255; ++i ) + { + ++buffer[byte]; + f = popen( argv[1], "w" ); + if( !f ) + { std::fprintf( stderr, "Can't open pipe.\n" ); return 1; } + std::fwrite( buffer, 1, size, f ); + pclose( f ); + } + ++buffer[byte]; + } + + return 0; + } |