From 9d4f55040311a16b32973b284e9cdfdf843ddf66 Mon Sep 17 00:00:00 2001 From: Josh MacDonald Date: Tue, 28 Oct 2014 23:34:53 -0700 Subject: Fix an overflow in setting xd3_source.maskby --- xdelta3/run_release.sh | 10 ++--- xdelta3/testing/checksum_test.cc | 82 +++++++++------------------------------- xdelta3/xdelta3-hash.h | 4 ++ xdelta3/xdelta3.c | 2 +- 4 files changed, 27 insertions(+), 71 deletions(-) (limited to 'xdelta3') diff --git a/xdelta3/run_release.sh b/xdelta3/run_release.sh index 7e841ab..8e99c6b 100755 --- a/xdelta3/run_release.sh +++ b/xdelta3/run_release.sh @@ -4,15 +4,15 @@ CC=clang CXX=clang++ # or -#CC=gcc -#CXX=g++ +CC=gcc +CXX=g++ # These are updated below, CFLAGS= # Do not set here CXXFLAGS= # Do not set here # Place C/C++ common flags here -#COMMON=-O3 +COMMON=-O3 export CFLAGS export CXXFLAGS @@ -53,9 +53,7 @@ function buildit { D=build/$MACH/${sizebits}size-${offsetbits}off mkdir -p $D (cd $D && $SRCDIR/configure --prefix=$PWD/bin --enable-debug-symbols) - #(cd $D && make all) - #echo Running regtest. - #(cd $D && ./xdelta3regtest) + (cd $D && make all) } function buildall { diff --git a/xdelta3/testing/checksum_test.cc b/xdelta3/testing/checksum_test.cc index 353d705..53566b9 100644 --- a/xdelta3/testing/checksum_test.cc +++ b/xdelta3/testing/checksum_test.cc @@ -176,9 +176,9 @@ struct with_stream : public cksum_params { }; MEMBER -struct large64_cksum : public with_stream { +struct large_cksum : public with_stream { Word step(const uint8_t *ptr) { - return xd3_large64_cksum (&this->stream.large_hash, ptr, CksumSize); + return xd3_large_cksum (&this->stream.large_hash, ptr, CksumSize); } Word state0(const uint8_t *ptr) { @@ -187,36 +187,26 @@ struct large64_cksum : public with_stream { } Word incr(const uint8_t *ptr) { - incr_state = xd3_large64_cksum_update (&this->stream.large_hash, incr_state, ptr - 1, CksumSize); + incr_state = xd3_large_cksum_update (&this->stream.large_hash, + incr_state, ptr - 1, CksumSize); return incr_state; } Word incr_state; }; -MEMBER -struct large64_cksum_old : public with_stream { - Word step(const uint8_t *ptr) { - return xd3_large64_cksum_old (&this->stream.large_hash, ptr, CksumSize); - } - - Word state0(const uint8_t *ptr) { - incr_state = step(ptr); - return incr_state; - } - - Word incr(const uint8_t *ptr) { - incr_state = xd3_large64_cksum_update_old (&this->stream.large_hash, incr_state, ptr - 1, CksumSize); - return incr_state; - } - - Word incr_state; -}; +#if SIZEOF_USIZE_T == 4 +#define xd3_large_cksum_old xd3_large32_cksum_old +#define xd3_large_cksum_update_old xd3_large32_cksum_update_old +#elif SIZEOF_USIZE_T == 8 +#define xd3_large_cksum_old xd3_large64_cksum_old +#define xd3_large_cksum_update_old xd3_large64_cksum_update_old +#endif MEMBER -struct large32_cksum : public with_stream { +struct large_cksum_old : public with_stream { Word step(const uint8_t *ptr) { - return xd3_large32_cksum (&this->stream.large_hash, ptr, CksumSize); + return xd3_large_cksum_old (&this->stream.large_hash, ptr, CksumSize); } Word state0(const uint8_t *ptr) { @@ -225,48 +215,14 @@ struct large32_cksum : public with_stream { } Word incr(const uint8_t *ptr) { - incr_state = xd3_large32_cksum_update (&this->stream.large_hash, incr_state, ptr - 1, CksumSize); + incr_state = xd3_large_cksum_update_old (&this->stream.large_hash, + incr_state, ptr - 1, CksumSize); return incr_state; } Word incr_state; }; -MEMBER -struct large32_cksum_old : public with_stream { - Word step(const uint8_t *ptr) { - return xd3_large32_cksum_old (&this->stream.large_hash, ptr, CksumSize); - } - - Word state0(const uint8_t *ptr) { - incr_state = step(ptr); - return incr_state; - } - - Word incr(const uint8_t *ptr) { - incr_state = xd3_large32_cksum_update_old (&this->stream.large_hash, incr_state, ptr - 1, CksumSize); - return incr_state; - } - - Word incr_state; -}; - -MEMBER -struct large_cksum - : std::conditional::value, - large32_cksum, - large64_cksum>::type -{ -}; - -MEMBER -struct large_cksum_old - : std::conditional::value, - large32_cksum_old, - large64_cksum_old>::type -{ -}; - // TESTS template @@ -717,11 +673,9 @@ int main(int argc, char** argv) { _old_ ## T ## _ ## Z ## _ ## S ## _ ## C \ ("old_" #T "_" #Z "_" #S "_" #C) -#define TESTS(SIZE, SKIP) \ - TEST(uint32_t, SIZE, SKIP, 1); \ - TEST(uint32_t, SIZE, SKIP, 2); \ - TEST(uint64_t, SIZE, SKIP, 1); \ - TEST(uint64_t, SIZE, SKIP, 2) +#define TESTS(SIZE, SKIP) \ + TEST(usize_t, SIZE, SKIP, 1); \ + TEST(usize_t, SIZE, SKIP, 2) TESTS(9, 1); TESTS(9, 9); diff --git a/xdelta3/xdelta3-hash.h b/xdelta3/xdelta3-hash.h index 2919b98..c112b5a 100644 --- a/xdelta3/xdelta3-hash.h +++ b/xdelta3/xdelta3-hash.h @@ -72,6 +72,7 @@ xd3_checksum_hash (const xd3_hash_cfg *cfg, const usize_t cksum) return (cksum >> cfg->shift) ^ (cksum & cfg->mask); } +#if SIZEOF_USIZE_T == 4 inline uint32_t xd3_large32_cksum (xd3_hash_cfg *cfg, const uint8_t *base, const usize_t look) { @@ -88,7 +89,9 @@ xd3_large32_cksum_update (xd3_hash_cfg *cfg, const uint32_t cksum, { return xd3_hash_multiplier32 * cksum - cfg->multiplier * base[0] + base[look]; } +#endif +#if SIZEOF_USIZE_T == 8 inline uint64_t xd3_large64_cksum (xd3_hash_cfg *cfg, const uint8_t *base, const usize_t look) { @@ -105,6 +108,7 @@ xd3_large64_cksum_update (xd3_hash_cfg *cfg, const uint64_t cksum, { return xd3_hash_multiplier64 * cksum - cfg->multiplier * base[0] + base[look]; } +#endif static usize_t xd3_size_hashtable_bits (usize_t slots) diff --git a/xdelta3/xdelta3.c b/xdelta3/xdelta3.c index 5c79f37..612e747 100644 --- a/xdelta3/xdelta3.c +++ b/xdelta3/xdelta3.c @@ -2174,7 +2174,7 @@ xd3_set_source (xd3_stream *stream, } src->shiftby = shiftby; - src->maskby = (1 << shiftby) - 1; + src->maskby = (1ULL << shiftby) - 1ULL; if (xd3_check_pow2 (src->max_winsize, NULL) != 0) { -- cgit v1.2.3