From 8e9c04523a00bde0ddbd9ca417e115a77c1af496 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Wed, 8 Nov 2023 10:28:14 -0500 Subject: [PATCH] Fix overflow bug in hashed Member-of max_off calculation --- src/singeli/src/search.singeli | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/singeli/src/search.singeli b/src/singeli/src/search.singeli index 825bcaa8..89507f37 100644 --- a/src/singeli/src/search.singeli +++ b/src/singeli/src/search.singeli @@ -384,7 +384,7 @@ fn hashtab{T, name}(rp:*rty{name}, iv:*void, m:usz, fv:*void, n:usz, links:ity{n } } } - try_vec_memb{T, hash, sz+ext, sh, maxh, has_maxh, swap, rp, fp, n, abort} + try_vec_memb{T, hash, sz, sh, maxh, has_maxh, swap, rp, fp, n, abort} if (has_maxh) { while (load{hash,end}!=maxh) ++end } else end += promote{T,ext} # Unreachable } @@ -516,20 +516,25 @@ fn hashtab{T, name}(rp:*rty{name}, iv:*void, m:usz, fv:*void, n:usz, links:ity{n } def try_vec_memb{..._} = {} -def try_vec_memb{T, hash, hashlen, sh, maxh, has_maxh, swap, rp, fp, n, done +def try_vec_memb{T, hash, sz, sh, maxh, has_maxh, swap, rp, fp, n, done & hasarch{'SSE4.2'} & T==u32} = { # Hash h wants bin h>>sh, so the offset for h in slot i is (in infite-precision ints) # i-h>>sh = i+((1<>sh = (((i+1)<>sh # We maintain io = (i+1)< (o+k)< T~~k<> sh - vswap := base{256,vl**1} * promote{T,swap} + # sz==1<=sz the above overflows + # And we have to handle maxh specially anyway + def mx{i,h} = { max_off = max{max_off, i-h>>sh} } + i:T=sz; h:T=i; while ((h=load{hash,i})