diff --git a/asan.lst b/asan.lst index 24a94348b..0ee73b408 100644 --- a/asan.lst +++ b/asan.lst @@ -35,7 +35,7 @@ fjs hash3 hash5 hash8 -#tsw +tsw #graspm #ssef aut diff --git a/sanitizer.log b/sanitizer.log index 1bc0bb109..3be86c084 100644 --- a/sanitizer.log +++ b/sanitizer.log @@ -38,46 +38,7 @@ hash3 hash5 hash8 tsw -AddressSanitizer:DEADLYSIGNAL -================================================================= -==3586985==ERROR: AddressSanitizer: SEGV on unknown address 0x7f2c9a15efff (pc 0x000000403d73 bp 0x7ffe6e399280 sp 0x7ffe6e317dc0 T0) -==3586985==The signal is caused by a READ memory access. - #0 0x403d73 in search source/algos/tsw.c:72 - #1 0x4017ba in main source/algos/include/main.h:125 - #2 0x7f2c9d046149 in __libc_start_call_main (/lib64/libc.so.6+0x28149) (BuildId: 7ea8d85df0e89b90c63ac7ed2b3578b2e7728756) - #3 0x7f2c9d04620a in __libc_start_main_impl (/lib64/libc.so.6+0x2820a) (BuildId: 7ea8d85df0e89b90c63ac7ed2b3578b2e7728756) - #4 0x401e84 in _start (/home/rurban/Software/smart/bin/asan/tsw+0x401e84) (BuildId: 1ae7608d7493a33edb8c4e9881f69c7ba7bee3b0) - -AddressSanitizer can not provide additional info. -SUMMARY: AddressSanitizer: SEGV source/algos/tsw.c:72 in search -==3586985==ABORTING -AddressSanitizer:DEADLYSIGNAL -================================================================= -==3587157==ERROR: AddressSanitizer: SEGV on unknown address 0x7f101455efff (pc 0x000000403dbf bp 0x7ffeaf8d81b0 sp 0x7ffeaf856cf0 T0) -==3587157==The signal is caused by a READ memory access. - #0 0x403dbf in search source/algos/tsw.c:72 - #1 0x4017ba in main source/algos/include/main.h:125 - #2 0x7f1017446149 in __libc_start_call_main (/lib64/libc.so.6+0x28149) (BuildId: 7ea8d85df0e89b90c63ac7ed2b3578b2e7728756) - #3 0x7f101744620a in __libc_start_main_impl (/lib64/libc.so.6+0x2820a) (BuildId: 7ea8d85df0e89b90c63ac7ed2b3578b2e7728756) - #4 0x401e84 in _start (/home/rurban/Software/smart/bin/asan/tsw+0x401e84) (BuildId: 1ae7608d7493a33edb8c4e9881f69c7ba7bee3b0) - -AddressSanitizer can not provide additional info. -SUMMARY: AddressSanitizer: SEGV source/algos/tsw.c:72 in search -==3587157==ABORTING -AddressSanitizer:DEADLYSIGNAL -================================================================= -==3587228==ERROR: AddressSanitizer: SEGV on unknown address 0x7f0d11d5efff (pc 0x000000403dbf bp 0x7ffee9699e10 sp 0x7ffee9618950 T0) -==3587228==The signal is caused by a READ memory access. - #0 0x403dbf in search source/algos/tsw.c:72 - #1 0x4017ba in main source/algos/include/main.h:125 - #2 0x7f0d14c46149 in __libc_start_call_main (/lib64/libc.so.6+0x28149) (BuildId: 7ea8d85df0e89b90c63ac7ed2b3578b2e7728756) - #3 0x7f0d14c4620a in __libc_start_main_impl (/lib64/libc.so.6+0x2820a) (BuildId: 7ea8d85df0e89b90c63ac7ed2b3578b2e7728756) - #4 0x401e84 in _start (/home/rurban/Software/smart/bin/asan/tsw+0x401e84) (BuildId: 1ae7608d7493a33edb8c4e9881f69c7ba7bee3b0) - -AddressSanitizer can not provide additional info. -SUMMARY: AddressSanitizer: SEGV source/algos/tsw.c:72 in search -==3587228==ABORTING -graspm +raspm AddressSanitizer:DEADLYSIGNAL ================================================================= ==3587252==ERROR: AddressSanitizer: SEGV on unknown address 0x7f1bfacfefff (pc 0x000000403927 bp 0xffffffffffffffff sp 0x7ffd58dd27a0 T0) diff --git a/source/algorithms.h b/source/algorithms.h index 073340651..f5bb3770f 100644 --- a/source/algorithms.h +++ b/source/algorithms.h @@ -319,7 +319,7 @@ const struct algo ALGOS[] = { // L. Vespa and N. Weng, SWM: Simplified Wu-Manber for GPU-based Deep Packet // Inspection, in Proceedings of the 2012 International Conference on // Security and Management, 2012. - [_TSW] = {_TSW, OK, "tsw", "Two-Sliding-Window", 0, 0}, + [_TSW] = {_TSW, OK, "tsw", "Two-Sliding-Window", 0, 0}, // m < n - 3 [_BMH2] = {_BMH2, 0, "bmh2", "Boyer-Moore-Horspool with q-grams (BMH2)", 2, MISSING}, [_BMH4] = {_BMH4, 0, "bmh4", "Boyer-Moore-Horspool with q-grams (BMH4)", 4, MISSING}, [_GRASPm] = {_GRASPm, OK, "graspm", "Genomic Rapid Algorithm for String Pattern-match", 0, 0}, diff --git a/source/algos/tsw.c b/source/algos/tsw.c index a0691944b..9299c2eff 100644 --- a/source/algos/tsw.c +++ b/source/algos/tsw.c @@ -20,10 +20,14 @@ * in A. Hudaib and R. Al-Khalid and D. Suleiman and M. Itriq and A. Al-Anani. * A Fast Pattern Matching Algorithm with Two Sliding Windows (TSW). J. Comput. * Sci., vol.4, n.5, pp.393--401, (2008). + * + * Undocumented constraints: m < n - 3 */ +#include #include "include/define.h" #include "include/main.h" +#include "include/search_small.h" void preBrBc(unsigned char *x, int m, int brBc[SIGMA][SIGMA]) { int a, b, i; @@ -43,11 +47,14 @@ int search(unsigned char *x, int m, unsigned char *y, int n) { int i, a, b; int count; unsigned char x1[XSIZE]; - for (i = m - 1, j = 0; i >= 0; i--, j++) - x1[j] = x[i]; + if (m >= n - 3) + return search_small(x, m, y, n); + assert(m < n - 2); /* Preprocessing */ BEGIN_PREPROCESSING + for (i = m - 1, j = 0; i >= 0; i--, j++) + x1[j] = x[i]; preBrBc(x, m, brBc_left); preBrBc(x1, m, brBc_right); count = 0; @@ -68,6 +75,10 @@ int search(unsigned char *x, int m, unsigned char *y, int n) { if (b >= m && j < a) OUTPUT(a); + assert(j + m + 1 < n); + assert(a - 1 < n); + //if (a - 2 < 0) fprintf(stderr, "%s %d %x %d\n", x, m, y, n); + assert(a - 2 >= 0); j += brBc_left[y[j + m]][y[j + m + 1]]; a -= brBc_right[y[a - 1]][y[a - 2]]; }