From 6b756eb165a72116a860874fcff3b01bd009064e Mon Sep 17 00:00:00 2001 From: Moinak Ghosh Date: Wed, 2 Jan 2013 22:56:21 +0530 Subject: [PATCH] Fix Delta2 handling for small buffers. Fix LZP handling during preprocessing. Fix type flag handling during preprocessing. Update test cases to use configurable list of test corpus files. Update some more int64_t datatypes to uint64_t Add a gitignore. --- .gitignore | 11 ++++ crypto/aes/crypto_aes.c | 4 +- crypto/aes/crypto_aes.h | 4 +- crypto/crypto_utils.c | 4 +- crypto/crypto_utils.h | 4 +- delta2/delta2.c | 10 +++- lz4/lz4.c | 1 - lzp/lzp.c | 6 +- lzp/lzp.h | 2 +- main.c | 22 +++++--- test/run_test.sh | 34 ++++++++++-- test/t1.tst | 2 +- test/t2.tst | 2 +- test/t3.tst | 6 +- test/t4.tst | 6 +- test/t5.tst | 6 +- test/t6.tst | 3 +- test/t7.tst | 2 +- test/t8.tst | 2 +- test/t9.tst | 119 +++++++++++++++++++++++----------------- 20 files changed, 158 insertions(+), 92 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f185bb8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +files.lst +*.pc* +*.o +*.so +pcompress +Makefile +test.log +test/datafiles +*~ +core.* +*.kate-swp diff --git a/crypto/aes/crypto_aes.c b/crypto/aes/crypto_aes.c index 94f7bb7..fe5a2d8 100644 --- a/crypto/aes/crypto_aes.c +++ b/crypto/aes/crypto_aes.c @@ -161,7 +161,7 @@ aes_init(aes_ctx_t *ctx, uchar_t *salt, int saltlen, uchar_t *pwd, int pwd_len, } int -aes_encrypt(aes_ctx_t *ctx, uchar_t *plaintext, uchar_t *ciphertext, ssize_t len, uint64_t id) { +aes_encrypt(aes_ctx_t *ctx, uchar_t *plaintext, uchar_t *ciphertext, uint64_t len, uint64_t id) { AES_KEY key; uchar_t *k1, *k2; struct crypto_aesctr *strm; @@ -185,7 +185,7 @@ aes_encrypt(aes_ctx_t *ctx, uchar_t *plaintext, uchar_t *ciphertext, ssize_t len } int -aes_decrypt(aes_ctx_t *ctx, uchar_t *ciphertext, uchar_t *plaintext, ssize_t len, uint64_t id) { +aes_decrypt(aes_ctx_t *ctx, uchar_t *ciphertext, uchar_t *plaintext, uint64_t len, uint64_t id) { AES_KEY key; uchar_t *k1, *k2; struct crypto_aesctr *strm; diff --git a/crypto/aes/crypto_aes.h b/crypto/aes/crypto_aes.h index b947a11..4011341 100644 --- a/crypto/aes/crypto_aes.h +++ b/crypto/aes/crypto_aes.h @@ -48,8 +48,8 @@ typedef struct { int aes_init(aes_ctx_t *ctx, uchar_t *salt, int saltlen, uchar_t *pwd, int pwd_len, uint64_t nonce, int enc); -int aes_encrypt(aes_ctx_t *ctx, uchar_t *plaintext, uchar_t *ciphertext, ssize_t len, uint64_t id); -int aes_decrypt(aes_ctx_t *ctx, uchar_t *ciphertext, uchar_t *plaintext, ssize_t len, uint64_t id); +int aes_encrypt(aes_ctx_t *ctx, uchar_t *plaintext, uchar_t *ciphertext, uint64_t len, uint64_t id); +int aes_decrypt(aes_ctx_t *ctx, uchar_t *ciphertext, uchar_t *plaintext, uint64_t len, uint64_t id); uint64_t aes_nonce(aes_ctx_t *ctx); void aes_clean_pkey(aes_ctx_t *ctx); void aes_cleanup(aes_ctx_t *ctx); diff --git a/crypto/crypto_utils.c b/crypto/crypto_utils.c index 968aab8..60af04c 100644 --- a/crypto/crypto_utils.c +++ b/crypto/crypto_utils.c @@ -74,7 +74,7 @@ extern uint64_t lzma_crc64_8bchk(const uint8_t *buf, uint64_t size, uint64_t crc, uint64_t *cnt); int -compute_checksum(uchar_t *cksum_buf, int cksum, uchar_t *buf, int64_t bytes) +compute_checksum(uchar_t *cksum_buf, int cksum, uchar_t *buf, uint64_t bytes) { DEBUG_STAT_EN(double strt, en); @@ -535,7 +535,7 @@ init_crypto(crypto_ctx_t *cctx, uchar_t *pwd, int pwd_len, int crypto_alg, } int -crypto_buf(crypto_ctx_t *cctx, uchar_t *from, uchar_t *to, int64_t bytes, uint64_t id) +crypto_buf(crypto_ctx_t *cctx, uchar_t *from, uchar_t *to, uint64_t bytes, uint64_t id) { if (cctx->crypto_alg == CRYPTO_ALG_AES) { if (cctx->enc_dec == ENCRYPT_FLAG) { diff --git a/crypto/crypto_utils.h b/crypto/crypto_utils.h index c4dfdea..30cf425 100644 --- a/crypto/crypto_utils.h +++ b/crypto/crypto_utils.h @@ -74,7 +74,7 @@ typedef struct { /* * Generic message digest functions. */ -int compute_checksum(uchar_t *cksum_buf, int cksum, uchar_t *buf, int64_t bytes); +int compute_checksum(uchar_t *cksum_buf, int cksum, uchar_t *buf, uint64_t bytes); int get_checksum_props(const char *name, int *cksum, int *cksum_bytes, int *mac_bytes); void serialize_checksum(uchar_t *checksum, uchar_t *buf, int cksum_bytes); void deserialize_checksum(uchar_t *checksum, uchar_t *buf, int cksum_bytes); @@ -84,7 +84,7 @@ void deserialize_checksum(uchar_t *checksum, uchar_t *buf, int cksum_bytes); */ int init_crypto(crypto_ctx_t *cctx, uchar_t *pwd, int pwd_len, int crypto_alg, uchar_t *salt, int saltlen, uint64_t nonce, int enc_dec); -int crypto_buf(crypto_ctx_t *cctx, uchar_t *from, uchar_t *to, int64_t bytes, uint64_t id); +int crypto_buf(crypto_ctx_t *cctx, uchar_t *from, uchar_t *to, uint64_t bytes, uint64_t id); uint64_t crypto_nonce(crypto_ctx_t *cctx); void crypto_clean_pkey(crypto_ctx_t *cctx); void cleanup_crypto(crypto_ctx_t *cctx); diff --git a/delta2/delta2.c b/delta2/delta2.c index b4f7d75..f48d41e 100644 --- a/delta2/delta2.c +++ b/delta2/delta2.c @@ -113,6 +113,9 @@ delta2_encode(uchar_t *src, uint64_t srclen, uchar_t *dst, uint64_t *dstlen, int return (-1); } + if (srclen <= (MAIN_HDR + LIT_HDR + DELTA_HDR)) + return (-1); + if (rle_thresh < MIN_THRESH) return (-1); @@ -121,7 +124,10 @@ delta2_encode(uchar_t *src, uint64_t srclen, uchar_t *dst, uint64_t *dstlen, int int rv; hdr_ovr = 0; + *((uint64_t *)dst) = LE64(srclen); + dst += MAIN_HDR; rv = delta2_encode_real(src, srclen, dst, dstlen, rle_thresh, 1, &hdr_ovr); + *dstlen += MAIN_HDR; DEBUG_STAT_EN(fprintf(stderr, "DELTA2: srclen: %" PRIu64 ", dstlen: %" PRIu64 "\n", srclen, *dstlen)); DEBUG_STAT_EN(fprintf(stderr, "DELTA2: header overhead: %d\n", hdr_ovr)); } else { @@ -456,7 +462,7 @@ delta2_decode(uchar_t *src, uint64_t srclen, uchar_t *dst, uint64_t *dstlen) rcnt = val & MSB_SETZERO_MASK; pos += sizeof (rcnt); if (out + rcnt > *dstlen) { - fprintf(stderr, "DELTA2 Decode: Destination buffer overflow. Corrupt data.\n"); + fprintf(stderr, "DELTA2 Decode(lit): Destination buffer overflow. Corrupt data.\n"); return (-1); } memcpy(pos1, pos, rcnt); @@ -473,7 +479,7 @@ delta2_decode(uchar_t *src, uint64_t srclen, uchar_t *dst, uint64_t *dstlen) delta = LE64(*((uint64_t *)pos)); pos += sizeof (delta); if (out + rcnt > *dstlen) { - fprintf(stderr, "DELTA2 Decode: Destination buffer overflow. Corrupt data.\n"); + fprintf(stderr, "DELTA2 Decode(delta): Destination buffer overflow. Corrupt data.\n"); return (-1); } diff --git a/lz4/lz4.c b/lz4/lz4.c index 00d6f95..ffd7e1e 100644 --- a/lz4/lz4.c +++ b/lz4/lz4.c @@ -648,7 +648,6 @@ _last_literals: return (int) (((char*)op)-dest); } - int LZ4_compress_limitedOutput(const char* source, char* dest, int isize, diff --git a/lzp/lzp.c b/lzp/lzp.c index 70055a3..a245f2f 100644 --- a/lzp/lzp.c +++ b/lzp/lzp.c @@ -59,9 +59,9 @@ inline int bsc_lzp_num_blocks(int64_t n) { int nb; - if (n < 256 * 1024) return 1; - if (n < 4 * 1024 * 1024) return 2; - if (n < 16 * 1024 * 1024) return 4; + if (n < 256LL * 1024LL) return 1; + if (n < 4LL * 1024LL * 1024LL) return 2; + if (n < 16LL * 1024LL * 1024LL) return 4; if (n < LZP_MAX_BLOCK) return 8; nb = n / LZP_MAX_BLOCK; diff --git a/lzp/lzp.h b/lzp/lzp.h index c7443c9..cc2ca87 100644 --- a/lzp/lzp.h +++ b/lzp/lzp.h @@ -46,7 +46,7 @@ See also the bsc and libbsc web site: #define LZP_DEFAULT_LZPHASHSIZE 16 #define LZP_DEFAULT_LZPMINLEN 128 -#define LZP_MAX_BLOCK (2000000000L) +#define LZP_MAX_BLOCK (2000000000LL) #define ALPHABET_SIZE (256) #ifdef __cplusplus diff --git a/main.c b/main.c index 4142929..35038f4 100644 --- a/main.c +++ b/main.c @@ -208,7 +208,6 @@ preproc_compress(compress_func_ptr cmp_func, void *src, uint64_t srclen, void *d if (lzp_preprocess) { int hashsize; - type = PREPROC_TYPE_LZP; hashsize = lzp_hash_size(level); result = lzp_compress((const uchar_t *)src, (uchar_t *)dst, srclen, hashsize, LZP_DEFAULT_LZPMINLEN, 0); @@ -216,6 +215,7 @@ preproc_compress(compress_func_ptr cmp_func, void *src, uint64_t srclen, void *d if (!enable_delta2_encode) return (-1); } else { + type |= PREPROC_TYPE_LZP; srclen = result; memcpy(src, dst, srclen); } @@ -223,7 +223,6 @@ preproc_compress(compress_func_ptr cmp_func, void *src, uint64_t srclen, void *d } else if (!enable_delta2_encode) { /* * Execution won't come here but just in case ... - * Even Delta2 encoding below enables LZP. */ fprintf(stderr, "Invalid preprocessing mode\n"); return (-1); @@ -241,7 +240,7 @@ preproc_compress(compress_func_ptr cmp_func, void *src, uint64_t srclen, void *d } *dest = type; - *((int64_t *)(dest + 1)) = htonll(srclen); + *((uint64_t *)(dest + 1)) = htonll(srclen); _dstlen = srclen; DEBUG_STAT_EN(strt = get_wtime_millis()); result = cmp_func(src, srclen, dest+9, &_dstlen, level, chdr, data); @@ -255,7 +254,15 @@ preproc_compress(compress_func_ptr cmp_func, void *src, uint64_t srclen, void *d DEBUG_STAT_EN(fprintf(stderr, "Chunk did not compress.\n")); memcpy(dest+1, src, srclen); *dstlen = srclen + 1; - result = 0; + /* + * If compression failed but one of the pre-processing succeeded then + * type flags will be non-zero. In that case we still indicate a success + * result so that decompression will reverse the pre-processing. The + * type flags will indicate that compression was not done and the + * decompress routine will not be called. + */ + if (type > 0) + result = 0; } return (result); @@ -274,7 +281,7 @@ preproc_decompress(compress_func_ptr dec_func, void *src, uint64_t srclen, void sorc++; srclen--; if (type & PREPROC_COMPRESSED) { - *dstlen = ntohll(*((int64_t *)(sorc))); + *dstlen = ntohll(*((uint64_t *)(sorc))); sorc += 8; srclen -= 8; DEBUG_STAT_EN(strt = get_wtime_millis()); @@ -295,7 +302,7 @@ preproc_decompress(compress_func_ptr dec_func, void *src, uint64_t srclen, void memcpy(src, dst, _dstlen); srclen = _dstlen; *dstlen = _dstlen; - } else { + } else { return (result); } } @@ -312,7 +319,7 @@ preproc_decompress(compress_func_ptr dec_func, void *src, uint64_t srclen, void *dstlen = result; } - if (!(type & (PREPROC_COMPRESSED | PREPROC_TYPE_DELTA2 | PREPROC_TYPE_LZP))) { + if (!(type & (PREPROC_COMPRESSED | PREPROC_TYPE_DELTA2 | PREPROC_TYPE_LZP)) && type > 0) { fprintf(stderr, "Invalid preprocessing flags: %d\n", type); return (-1); } @@ -1156,6 +1163,7 @@ redo: compressed_chunk = tdat->compressed_chunk + CHUNK_FLAG_SZ; rbytes = tdat->rbytes; dedupe_index_sz = 0; + tdat->rctx->valid = 0; /* Perform Dedup if enabled. */ if ((enable_rabin_scan || enable_fixed_scan)) { diff --git a/test/run_test.sh b/test/run_test.sh index 1dbce34..44c36d1 100644 --- a/test/run_test.sh +++ b/test/run_test.sh @@ -12,11 +12,35 @@ else fi PDIR=`pwd` -[ ! -f datafiles/bin.dat ] && (tar cpf - /usr/bin | dd of=datafiles/bin.dat bs=1024 count=5120; cat res/jpg/*.jpg >> datafiles/bin.dat) -[ ! -f datafiles/share.dat ] && tar cpf - /usr/share | dd of=datafiles/share.dat bs=1024 count=5120 -[ ! -f datafiles/inc.dat ] && (tar cpf - /usr/include | dd of=datafiles/inc.dat bs=1024 count=5120; cat res/xml/*.xml >> datafiles/inc.dat) -[ ! -f datafiles/combined.dat ] && cat datafiles/bin.dat datafiles/share.dat datafiles/inc.dat >> datafiles/combined.dat -[ ! -f datafiles/comb_d.dat ] && sh -c "cat datafiles/combined.dat > datafiles/comb_d.dat; cat datafiles/combined.dat >> datafiles/comb_d.dat" +if [ ! -f datafiles/files.lst ] +then + [ ! -f datafiles/bin.dat ] && (tar cpf - /usr/bin | dd of=datafiles/bin.dat bs=1024 count=5120; cat res/jpg/*.jpg >> datafiles/bin.dat) + [ ! -f datafiles/share.dat ] && tar cpf - /usr/share | dd of=datafiles/share.dat bs=1024 count=5120 + [ ! -f datafiles/inc.dat ] && (tar cpf - /usr/include | dd of=datafiles/inc.dat bs=1024 count=5120; cat res/xml/*.xml >> datafiles/inc.dat) + [ ! -f datafiles/combined.dat ] && cat datafiles/bin.dat datafiles/share.dat datafiles/inc.dat >> datafiles/combined.dat + [ ! -f datafiles/comb_d.dat ] && sh -c "cat datafiles/combined.dat > datafiles/comb_d.dat; cat datafiles/combined.dat >> datafiles/comb_d.dat" + + pdir=`pwd` + echo ${pdir}/datafiles/bin.dat > datafiles/files.lst + echo ${pdir}/datafiles/share.dat >> datafiles/files.lst + echo ${pdir}/datafiles/inc.dat >> datafiles/files.lst + echo ${pdir}/datafiles/combined.dat >> datafiles/files.lst + echo ${pdir}/datafiles/comb_d.dat >> datafiles/files.lst +else + for f in `cat datafiles/files.lst` + do + if [ ! -f ${f} ] + then + echo "Cannot find test data file: ${f}" + exit 1 + fi + dir=`dirname ${f}` + rm -f ${dir}/.pco* + rm -f ${dir}/*.pz + rm -f ${dir}/*.1 + done +fi + failures=0 diff --git a/test/t1.tst b/test/t1.tst index fd2718d..de7f41c 100644 --- a/test/t1.tst +++ b/test/t1.tst @@ -12,7 +12,7 @@ do for level in 1 3 9 14 do - for tf in bin.dat share.dat inc.dat + for tf in `cat files.lst` do for seg in 1m 100m do diff --git a/test/t2.tst b/test/t2.tst index fa2bd62..e4a50fe 100644 --- a/test/t2.tst +++ b/test/t2.tst @@ -7,7 +7,7 @@ echo "#################################################" for algo in zlib ppmd do - for tf in bin.dat share.dat inc.dat + for tf in `cat files.lst` do for cksum in CRC64 SHA256 SHA512 SKEIN256 SKEIN512 KECCAK256 KECCAK512 do diff --git a/test/t3.tst b/test/t3.tst index 4fc51e4..42e3917 100644 --- a/test/t3.tst +++ b/test/t3.tst @@ -5,7 +5,7 @@ clean() { for algo in lzfx lz4 zlib bzip2 lzma lzmaMt libbsc ppmd adapt adapt2 do - for tf in bin.dat share.dat inc.dat + for tf in `cat files.lst` do rm -f ${tf}.${algo} done @@ -22,7 +22,7 @@ do ../../pcompress 2>&1 | grep $algo > /dev/null [ $? -ne 0 ] && continue - for tf in bin.dat share.dat inc.dat + for tf in `cat files.lst` do echo "Preparing ${algo} compressed ${tf} datafile ..." cmd="../../pcompress -c ${algo} -l5 -s500k ${tf}" @@ -43,7 +43,7 @@ do for level in 1 3 9 14 do - for tf in bin.dat share.dat inc.dat + for tf in `cat files.lst` do for seg in 1m 100m do diff --git a/test/t4.tst b/test/t4.tst index 41b019a..18697e9 100644 --- a/test/t4.tst +++ b/test/t4.tst @@ -5,13 +5,11 @@ echo "#################################################" echo "# Test Deduplication, Delta Encoding and LZP" echo "#################################################" -rm -f *.pz -rm -f *.1 - for algo in lzfx lz4 adapt do - for tf in combined.dat comb_d.dat + for tf in `cat files.lst` do + rm -f ${tf}.* for feat in "-D" "-D -B3 -L" "-D -B4 -E" "-D -B2 -EE" "-D -B5 -EE -L" "-D -B2 -r" "-P" "-D -P" "-D -L -P" do for seg in 2m 100m diff --git a/test/t5.tst b/test/t5.tst index d3bc7f5..6d3b5c7 100644 --- a/test/t5.tst +++ b/test/t5.tst @@ -5,13 +5,11 @@ echo "#################################################" echo "# Crypto tests" echo "#################################################" -rm -f *.pz -rm -f *.1 - for algo in lzfx adapt2 do - for tf in comb_d.dat + for tf in `cat files.lst` do + rm -f ${tf}.* for feat in "-e" "-e -L -S SHA256" "-D -e -S SHA512" "-D -EE -L -e -S SKEIN512" "-e -S CRC64" "-e -P" "-e -L -P -S KECCAK256" "-D -e -L -S KECCAK512" do for seg in 2m 100m diff --git a/test/t6.tst b/test/t6.tst index 1bdddac..baa86a0 100644 --- a/test/t6.tst +++ b/test/t6.tst @@ -12,8 +12,9 @@ do for level in 1 3 do - for tf in combined.dat + for tf in `cat files.lst` do + rm -f ${tf}.* for seg in 1m 2m 3m do cmd="cat ${tf} | ../../pcompress -p -c ${algo} -l ${level} -s ${seg} > ${tf}.pz" diff --git a/test/t7.tst b/test/t7.tst index 90eca21..bde12bb 100644 --- a/test/t7.tst +++ b/test/t7.tst @@ -10,7 +10,7 @@ rm -f *.1 for algo in lzfx adapt2 do - for tf in comb_d.dat + for tf in `cat files.lst` do for feat in "-e" "-e -L" "-D -e" "-D -EE -L -e" "-e -S CRC64" do diff --git a/test/t8.tst b/test/t8.tst index efdc467..4e04399 100644 --- a/test/t8.tst +++ b/test/t8.tst @@ -10,7 +10,7 @@ rm -f *.1 for algo in lzfx lz4 adapt adapt2 do - for tf in combined.dat comb_d.dat + for tf in `cat files.lst` do for feat in "-F" "-F -B3 -L" "-F -B4" "-F -B5 -L" "-F -P" "-F -L -P" do diff --git a/test/t9.tst b/test/t9.tst index 7cdf1c7..4e2c703 100644 --- a/test/t9.tst +++ b/test/t9.tst @@ -5,158 +5,179 @@ echo "####################################################" echo "# Test out of range parameters and error conditions." echo "####################################################" + +# +# Select a large file from the list +# +tstf= +tsz=0 +for tf in `cat files.lst` +do + sz=`ls -l ${tf} | awk '{ print $5 }'` + if [ $sz -gt $tsz ] + then + tsz=$sz + tstf="$tf" + fi +done + for feat in "-L" "-L -D" "-L -D -E" "-L -B5" "-L -D -E -B2" "-F" "-F -L" do - cmd="../../pcompress -c dummy -l4 -s1m $feat combined.dat" + cmd="../../pcompress -c dummy -l4 -s1m $feat $tstf" echo "Running $cmd" eval $cmd if [ $? -eq 0 ] then echo "FATAL: Compression DID NOT ERROR where expected" + rm -f ${tstf}.pz exit 1 fi + rm -f ${tstf}.pz + break done for feat in "-B8 -s2m -l1" "-B0 -s2m -l1" "-D -s10k -l1" "-D -F -s2m -l1" "-p -e -s2m -l1" "-s2m -l15" do for algo in lzfx lz4 zlib bzip2 libbsc ppmd lzma do - cmd="../../pcompress -c lzfx $feat combined.dat" + cmd="../../pcompress -c lzfx $feat $tstf" echo "Running $cmd" eval $cmd if [ $? -eq 0 ] then echo "FATAL: Compression DID NOT ERROR where expected" - rm -f combined.dat.pz + rm -f ${tstf}.pz exit 1 fi + rm -f ${tstf}.pz + break done done for feat in "-S CRC64" "-S SKEIN256" "-S SKEIN512" "-S SHA256" "-S SHA512" "-S KECCAK256" "-S KECCAK512" do - rm -f combined.dat.1.pz - rm -f combined.dat.pz - rm -f combined.dat.1 + rm -f ${tstf}.* - cmd="../../pcompress -c lzfx -l3 -s1m $feat combined.dat" + cmd="../../pcompress -c lzfx -l3 -s1m $feat ${tstf}" echo "Running $cmd" eval $cmd if [ $? -ne 0 ] then echo "FATAL: Compression errored." - rm -f combined.dat.pz + rm -f ${tstf}.pz + d=`dirname ${tstf}` + rm -f ${d}/.pc* exit 1 fi echo "Corrupting file header ..." - dd if=/dev/urandom conv=notrunc of=combined.dat.pz bs=4 seek=1 count=1 - cmd="../../pcompress -d combined.dat.pz combined.dat.1" + dd if=/dev/urandom conv=notrunc of=${tstf}.pz bs=4 seek=1 count=1 + cmd="../../pcompress -d ${tstf}.pz ${tstf}.1" eval $cmd if [ $? -eq 0 ] then echo "FATAL: Decompression DID NOT ERROR where expected." - rm -f combined.dat.pz - rm -f combined.dat.1 + rm -f ${tstf}.pz + rm -f ${tstf}.1 exit 1 fi - rm -f combined.dat.pz - rm -f combined.dat.1 + rm -f ${tstf}.pz + rm -f ${tstf}.1 - cmd="../../pcompress -c zlib -l3 -s1m $feat combined.dat" + cmd="../../pcompress -c zlib -l3 -s1m $feat ${tstf}" echo "Running $cmd" eval $cmd if [ $? -ne 0 ] then echo "FATAL: Compression errored." - rm -f combined.dat.pz + rm -f ${tstf}.pz exit 1 fi - cp combined.dat.pz combined.dat.1.pz + cp ${tstf}.pz ${tstf}.1.pz echo "Corrupting file ..." - dd if=/dev/urandom conv=notrunc of=combined.dat.pz bs=4 seek=100 count=1 - cmd="../../pcompress -d combined.dat.pz combined.dat.1" + dd if=/dev/urandom conv=notrunc of=${tstf}.pz bs=4 seek=100 count=1 + cmd="../../pcompress -d ${tstf}.pz ${tstf}.1" eval $cmd if [ $? -eq 0 ] then echo "FATAL: Decompression DID NOT ERROR where expected." - rm -f combined.dat.pz - rm -f combined.dat.1 - rm -f combined.dat.1.pz + rm -f ${tstf}.pz + rm -f ${tstf}.1 + rm -f ${tstf}.1.pz exit 1 fi - rm -f combined.dat.1 - cp combined.dat.1.pz combined.dat.pz + rm -f ${tstf}.1 + cp ${tstf}.1.pz ${tstf}.pz echo "Corrupting file ..." - dd if=/dev/urandom conv=notrunc of=combined.dat.1.pz bs=4 seek=51 count=1 - cmd="../../pcompress -d combined.dat.1.pz combined.dat.1" + dd if=/dev/urandom conv=notrunc of=${tstf}.1.pz bs=4 seek=51 count=1 + cmd="../../pcompress -d ${tstf}.1.pz ${tstf}.1" eval $cmd if [ $? -eq 0 ] then echo "FATAL: Decompression DID NOT ERROR where expected." - rm -f combined.dat.pz - rm -f combined.dat.1 - rm -f combined.dat.1.pz + rm -f ${tstf}.pz + rm -f ${tstf}.1 + rm -f ${tstf}.1.pz exit 1 fi - rm -f combined.dat.1 combined.dat.1.pz combined.dat.pz + rm -f ${tstf}.1 ${tstf}.1.pz ${tstf}.pz echo "plainpass" > /tmp/pwf - cmd="../../pcompress -c zlib -l3 -s1m -e -w /tmp/pwf $feat combined.dat" + cmd="../../pcompress -c zlib -l3 -s1m -e -w /tmp/pwf $feat ${tstf}" echo "Running $cmd" eval $cmd if [ $? -ne 0 ] then echo "FATAL: Compression errored." - rm -f combined.dat.pz + rm -f ${tstf}.pz exit 1 fi pw=`cat /tmp/pwf` if [ "$pw" = "plainpasswd" ] then echo "FATAL: Password file was not zeroed" - rm -f /tmp/pwf combined.dat.pz + rm -f /tmp/pwf ${tstf}.pz exit 1 fi - cp combined.dat.pz combined.dat.1.pz + cp ${tstf}.pz ${tstf}.1.pz echo "Corrupting file ..." - dd if=/dev/urandom conv=notrunc of=combined.dat.pz bs=4 seek=115 count=1 + dd if=/dev/urandom conv=notrunc of=${tstf}.pz bs=4 seek=115 count=1 echo "plainpass" > /tmp/pwf - cmd="../../pcompress -d -w /tmp/pwf combined.dat.pz combined.dat.1" + cmd="../../pcompress -d -w /tmp/pwf ${tstf}.pz ${tstf}.1" eval $cmd if [ $? -eq 0 ] then echo "FATAL: Decompression DID NOT ERROR where expected." - rm -f combined.dat.pz - rm -f combined.dat.1 - rm -f combined.dat.1.pz + rm -f ${tstf}.pz + rm -f ${tstf}.1 + rm -f ${tstf}.1.pz exit 1 fi - cp combined.dat.1.pz combined.dat.pz - rm -f combined.dat.1 + cp ${tstf}.1.pz ${tstf}.pz + rm -f ${tstf}.1 echo "Corrupting file header ..." - dd if=/dev/urandom conv=notrunc of=combined.dat.pz bs=4 seek=10 count=1 + dd if=/dev/urandom conv=notrunc of=${tstf}.pz bs=4 seek=10 count=1 echo "plainpass" > /tmp/pwf - cmd="../../pcompress -d -w /tmp/pwf combined.dat.pz combined.dat.1" + cmd="../../pcompress -d -w /tmp/pwf ${tstf}.pz ${tstf}.1" eval $cmd if [ $? -eq 0 ] then echo "FATAL: Decompression DID NOT ERROR where expected." - rm -f combined.dat.pz - rm -f combined.dat.1 - rm -f combined.dat.1.pz + rm -f ${tstf}.pz + rm -f ${tstf}.1 + rm -f ${tstf}.1.pz exit 1 fi done -rm -f combined.dat.1.pz -rm -f combined.dat.pz -rm -f combined.dat.1 +rm -f ${tstf}.1.pz +rm -f ${tstf}.pz +rm -f ${tstf}.1 rm -f /tmp/pwf echo "#################################################"