Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
Out of bounds access in CritBitTree #11344
If the requested prefix is longer than a key, the library accesses past the end of string. E.g.:
import critbits var cb: CritBitTree[string] cb.incl("help", "help") for k in cb.keysWithPrefix("helpp"): echo k
Should print nothing since "helpp" is not the prefix of any string in the CritBitTree.
Changing the offending line of code from
if p.key[i] != key[i]: return
if i >= p.key.len or p.key[i] != key[i]: return
seems to work for me. It may also be possible to do an earlier check of
I believe this is a very old bug.