diff --git a/adaptive_compress.c b/adaptive_compress.c index 259d9b1..836da25 100644 --- a/adaptive_compress.c +++ b/adaptive_compress.c @@ -129,14 +129,17 @@ adapt2_init(void **data, int *level, int nthreads, ssize_t chunksize, adat = (struct adapt_data *)slab_alloc(NULL, sizeof (struct adapt_data)); adat->adapt_mode = 2; adat->ppmd_data = NULL; + adat->bsc_data = NULL; lv = *level; rv = ppmd_init(&(adat->ppmd_data), &lv, nthreads, chunksize, file_version, op); lv = *level; if (rv == 0) rv = lzma_init(&(adat->lzma_data), &lv, nthreads, chunksize, file_version, op); lv = *level; +#ifdef ENABLE_PC_LIBBSC if (rv == 0) rv = libbsc_init(&(adat->bsc_data), &lv, nthreads, chunksize, file_version, op); +#endif *data = adat; if (*level > 9) *level = 9; } @@ -203,11 +206,13 @@ adapt_compress(void *src, size_t srclen, void *dst, } else { if (adat->bsc_data && tagcnt > ONE_PCT(srclen)) { +#ifdef ENABLE_PC_LIBBSC rv = libbsc_compress(src, srclen, dst, dstlen, level, chdr, adat->bsc_data); if (rv < 0) return (rv); rv = COMPRESS_BSC; bsc_count++; +#endif } else { rv = ppmd_compress(src, srclen, dst, dstlen, level, chdr, adat->ppmd_data); if (rv < 0) @@ -239,7 +244,12 @@ adapt_decompress(void *src, size_t srclen, void *dst, return (ppmd_decompress(src, srclen, dst, dstlen, level, chdr, adat->ppmd_data)); } else if (cmp_flags == COMPRESS_BSC) { +#ifdef ENABLE_PC_LIBBSC return (libbsc_decompress(src, srclen, dst, dstlen, level, chdr, adat->bsc_data)); +#else + fprintf(stderr, "Cannot decompress chunk. Libbsc support not present.\n"); + return (-1); +#endif } else { fprintf(stderr, "Unrecognized compression mode: %d, file corrupt.\n", cmp_flags); diff --git a/test/t9.tst b/test/t9.tst index 38b7164..fcfbc60 100644 --- a/test/t9.tst +++ b/test/t9.tst @@ -1,9 +1,9 @@ # # Out of range parameters # -echo "#################################################" -echo "# Test out of range parameters" -echo "#################################################" +echo "####################################################" +echo "# Test out of range parameters and error conditions." +echo "####################################################" for feat in "-L" "-L -D" "-L -D -E" "-L -B5" "-L -D -E -B2" "-F" "-F -L" do @@ -102,11 +102,62 @@ do rm -f combined.dat.1.pz exit 1 fi + + rm -f combined.dat.1 combined.dat.1.pz combined.dat.pz + echo "plainpass" > /tmp/pwf + cmd="../../pcompress -c zlib -l3 -s1m -e -w /tmp/pwf $feat combined.dat" + echo "Running $cmd" + eval $cmd + if [ $? -ne 0 ] + then + echo "${cmd} errored." + rm -f combined.dat.pz + exit 1 + fi + pw=`cat /tmp/pwf` + if [ "$pw" = "plainpasswd" ] + then + echo "ERROR: Password file was not zeroed" + rm -f /tmp/pwf combined.dat.pz + exit 1 + fi + + cp combined.dat.pz combined.dat.1.pz + echo "Corrupting file ..." + dd if=/dev/urandom conv=notrunc of=combined.dat.pz bs=4 seek=115 count=1 + echo "plainpass" > /tmp/pwf + cmd="../../pcompress -d -w /tmp/pwf combined.dat.pz combined.dat.1" + eval $cmd + if [ $? -eq 0 ] + then + echo "${cmd} DID NOT ERROR where expected." + rm -f combined.dat.pz + rm -f combined.dat.1 + rm -f combined.dat.1.pz + exit 1 + fi + + cp combined.dat.1.pz combined.dat.pz + rm -f combined.dat.1 + echo "Corrupting file header ..." + dd if=/dev/urandom conv=notrunc of=combined.dat.pz bs=4 seek=10 count=1 + echo "plainpass" > /tmp/pwf + cmd="../../pcompress -d -w /tmp/pwf combined.dat.pz combined.dat.1" + eval $cmd + if [ $? -eq 0 ] + then + echo "${cmd} DID NOT ERROR where expected." + rm -f combined.dat.pz + rm -f combined.dat.1 + rm -f combined.dat.1.pz + exit 1 + fi done rm -f combined.dat.1.pz rm -f combined.dat.pz rm -f combined.dat.1 +rm -f /tmp/pwf echo "#################################################" echo ""