summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh MacDonald <josh.macdonald@gmail.com>2014-10-28 23:34:53 -0700
committerJosh MacDonald <josh.macdonald@gmail.com>2014-10-28 23:34:53 -0700
commit9d4f55040311a16b32973b284e9cdfdf843ddf66 (patch)
tree61864beb22f4ba0a85004cc537bc2694970ff513
parentb48e01a24e16084c1a4105eb094c445ec51bb461 (diff)
Fix an overflow in setting xd3_source.maskby
-rwxr-xr-xxdelta3/run_release.sh10
-rw-r--r--xdelta3/testing/checksum_test.cc82
-rw-r--r--xdelta3/xdelta3-hash.h4
-rw-r--r--xdelta3/xdelta3.c2
4 files changed, 27 insertions, 71 deletions
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 @@
4CC=clang 4CC=clang
5CXX=clang++ 5CXX=clang++
6# or 6# or
7#CC=gcc 7CC=gcc
8#CXX=g++ 8CXX=g++
9 9
10# These are updated below, 10# These are updated below,
11CFLAGS= # Do not set here 11CFLAGS= # Do not set here
12CXXFLAGS= # Do not set here 12CXXFLAGS= # Do not set here
13 13
14# Place C/C++ common flags here 14# Place C/C++ common flags here
15#COMMON=-O3 15COMMON=-O3
16 16
17export CFLAGS 17export CFLAGS
18export CXXFLAGS 18export CXXFLAGS
@@ -53,9 +53,7 @@ function buildit {
53 D=build/$MACH/${sizebits}size-${offsetbits}off 53 D=build/$MACH/${sizebits}size-${offsetbits}off
54 mkdir -p $D 54 mkdir -p $D
55 (cd $D && $SRCDIR/configure --prefix=$PWD/bin --enable-debug-symbols) 55 (cd $D && $SRCDIR/configure --prefix=$PWD/bin --enable-debug-symbols)
56 #(cd $D && make all) 56 (cd $D && make all)
57 #echo Running regtest.
58 #(cd $D && ./xdelta3regtest)
59} 57}
60 58
61function buildall { 59function 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<SELF> {
176}; 176};
177 177
178MEMBER 178MEMBER
179struct large64_cksum : public with_stream<SELF> { 179struct large_cksum : public with_stream<SELF> {
180 Word step(const uint8_t *ptr) { 180 Word step(const uint8_t *ptr) {
181 return xd3_large64_cksum (&this->stream.large_hash, ptr, CksumSize); 181 return xd3_large_cksum (&this->stream.large_hash, ptr, CksumSize);
182 } 182 }
183 183
184 Word state0(const uint8_t *ptr) { 184 Word state0(const uint8_t *ptr) {
@@ -187,36 +187,26 @@ struct large64_cksum : public with_stream<SELF> {
187 } 187 }
188 188
189 Word incr(const uint8_t *ptr) { 189 Word incr(const uint8_t *ptr) {
190 incr_state = xd3_large64_cksum_update (&this->stream.large_hash, incr_state, ptr - 1, CksumSize); 190 incr_state = xd3_large_cksum_update (&this->stream.large_hash,
191 incr_state, ptr - 1, CksumSize);
191 return incr_state; 192 return incr_state;
192 } 193 }
193 194
194 Word incr_state; 195 Word incr_state;
195}; 196};
196 197
197MEMBER 198#if SIZEOF_USIZE_T == 4
198struct large64_cksum_old : public with_stream<SELF> { 199#define xd3_large_cksum_old xd3_large32_cksum_old
199 Word step(const uint8_t *ptr) { 200#define xd3_large_cksum_update_old xd3_large32_cksum_update_old
200 return xd3_large64_cksum_old (&this->stream.large_hash, ptr, CksumSize); 201#elif SIZEOF_USIZE_T == 8
201 } 202#define xd3_large_cksum_old xd3_large64_cksum_old
202 203#define xd3_large_cksum_update_old xd3_large64_cksum_update_old
203 Word state0(const uint8_t *ptr) { 204#endif
204 incr_state = step(ptr);
205 return incr_state;
206 }
207
208 Word incr(const uint8_t *ptr) {
209 incr_state = xd3_large64_cksum_update_old (&this->stream.large_hash, incr_state, ptr - 1, CksumSize);
210 return incr_state;
211 }
212
213 Word incr_state;
214};
215 205
216MEMBER 206MEMBER
217struct large32_cksum : public with_stream<SELF> { 207struct large_cksum_old : public with_stream<SELF> {
218 Word step(const uint8_t *ptr) { 208 Word step(const uint8_t *ptr) {
219 return xd3_large32_cksum (&this->stream.large_hash, ptr, CksumSize); 209 return xd3_large_cksum_old (&this->stream.large_hash, ptr, CksumSize);
220 } 210 }
221 211
222 Word state0(const uint8_t *ptr) { 212 Word state0(const uint8_t *ptr) {
@@ -225,48 +215,14 @@ struct large32_cksum : public with_stream<SELF> {
225 } 215 }
226 216
227 Word incr(const uint8_t *ptr) { 217 Word incr(const uint8_t *ptr) {
228 incr_state = xd3_large32_cksum_update (&this->stream.large_hash, incr_state, ptr - 1, CksumSize); 218 incr_state = xd3_large_cksum_update_old (&this->stream.large_hash,
219 incr_state, ptr - 1, CksumSize);
229 return incr_state; 220 return incr_state;
230 } 221 }
231 222
232 Word incr_state; 223 Word incr_state;
233}; 224};
234 225
235MEMBER
236struct large32_cksum_old : public with_stream<SELF> {
237 Word step(const uint8_t *ptr) {
238 return xd3_large32_cksum_old (&this->stream.large_hash, ptr, CksumSize);
239 }
240
241 Word state0(const uint8_t *ptr) {
242 incr_state = step(ptr);
243 return incr_state;
244 }
245
246 Word incr(const uint8_t *ptr) {
247 incr_state = xd3_large32_cksum_update_old (&this->stream.large_hash, incr_state, ptr - 1, CksumSize);
248 return incr_state;
249 }
250
251 Word incr_state;
252};
253
254MEMBER
255struct large_cksum
256 : std::conditional<std::is_same<Word, uint32_t>::value,
257 large32_cksum<SELF>,
258 large64_cksum<SELF>>::type
259{
260};
261
262MEMBER
263struct large_cksum_old
264 : std::conditional<std::is_same<Word, uint32_t>::value,
265 large32_cksum_old<SELF>,
266 large64_cksum_old<SELF>>::type
267{
268};
269
270// TESTS 226// TESTS
271 227
272template <typename Word> 228template <typename Word>
@@ -717,11 +673,9 @@ int main(int argc, char** argv) {
717 _old_ ## T ## _ ## Z ## _ ## S ## _ ## C \ 673 _old_ ## T ## _ ## Z ## _ ## S ## _ ## C \
718 ("old_" #T "_" #Z "_" #S "_" #C) 674 ("old_" #T "_" #Z "_" #S "_" #C)
719 675
720#define TESTS(SIZE, SKIP) \ 676#define TESTS(SIZE, SKIP) \
721 TEST(uint32_t, SIZE, SKIP, 1); \ 677 TEST(usize_t, SIZE, SKIP, 1); \
722 TEST(uint32_t, SIZE, SKIP, 2); \ 678 TEST(usize_t, SIZE, SKIP, 2)
723 TEST(uint64_t, SIZE, SKIP, 1); \
724 TEST(uint64_t, SIZE, SKIP, 2)
725 679
726 TESTS(9, 1); 680 TESTS(9, 1);
727 TESTS(9, 9); 681 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)
72 return (cksum >> cfg->shift) ^ (cksum & cfg->mask); 72 return (cksum >> cfg->shift) ^ (cksum & cfg->mask);
73} 73}
74 74
75#if SIZEOF_USIZE_T == 4
75inline uint32_t 76inline uint32_t
76xd3_large32_cksum (xd3_hash_cfg *cfg, const uint8_t *base, const usize_t look) 77xd3_large32_cksum (xd3_hash_cfg *cfg, const uint8_t *base, const usize_t look)
77{ 78{
@@ -88,7 +89,9 @@ xd3_large32_cksum_update (xd3_hash_cfg *cfg, const uint32_t cksum,
88{ 89{
89 return xd3_hash_multiplier32 * cksum - cfg->multiplier * base[0] + base[look]; 90 return xd3_hash_multiplier32 * cksum - cfg->multiplier * base[0] + base[look];
90} 91}
92#endif
91 93
94#if SIZEOF_USIZE_T == 8
92inline uint64_t 95inline uint64_t
93xd3_large64_cksum (xd3_hash_cfg *cfg, const uint8_t *base, const usize_t look) 96xd3_large64_cksum (xd3_hash_cfg *cfg, const uint8_t *base, const usize_t look)
94{ 97{
@@ -105,6 +108,7 @@ xd3_large64_cksum_update (xd3_hash_cfg *cfg, const uint64_t cksum,
105{ 108{
106 return xd3_hash_multiplier64 * cksum - cfg->multiplier * base[0] + base[look]; 109 return xd3_hash_multiplier64 * cksum - cfg->multiplier * base[0] + base[look];
107} 110}
111#endif
108 112
109static usize_t 113static usize_t
110xd3_size_hashtable_bits (usize_t slots) 114xd3_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,
2174 } 2174 }
2175 2175
2176 src->shiftby = shiftby; 2176 src->shiftby = shiftby;
2177 src->maskby = (1 << shiftby) - 1; 2177 src->maskby = (1ULL << shiftby) - 1ULL;
2178 2178
2179 if (xd3_check_pow2 (src->max_winsize, NULL) != 0) 2179 if (xd3_check_pow2 (src->max_winsize, NULL) != 0)
2180 { 2180 {