patricia.PatriciaTree.Insert loses an existing key when a proper prefix of it is inserted later:
var pt PatriciaTree
pt.Insert([]byte("0000"), []byte{48})
pt.Insert([]byte("0"), []byte{})
pt.root.get([]byte("0000")) // -> nil, false (was inserted!)
pt.root.get([]byte("0")) // -> [], true
All three MatchFinders walk the same tree, so the seg compressor silently drops dictionary patterns that have a shorter prefix-nested pattern inserted after them — slightly worse compression ratio, no corruption.
Repro: fuzz corpus entry db/seg/patricia/testdata/fuzz/FuzzLongestMatch/34174f1279b62c1e (added in #21625). The entry passes today only because the AC matcher is validated against a brute-force oracle instead of the tree-based matchers.
Found while working on #21625; the Aho-Corasick matcher introduced there is unaffected, but PatriciaTree.Insert itself (and MF1/MF2/MF3 consumers, e.g. pt.root.get) still has the bug.
patricia.PatriciaTree.Insertloses an existing key when a proper prefix of it is inserted later:All three MatchFinders walk the same tree, so the seg compressor silently drops dictionary patterns that have a shorter prefix-nested pattern inserted after them — slightly worse compression ratio, no corruption.
Repro: fuzz corpus entry
db/seg/patricia/testdata/fuzz/FuzzLongestMatch/34174f1279b62c1e(added in #21625). The entry passes today only because the AC matcher is validated against a brute-force oracle instead of the tree-based matchers.Found while working on #21625; the Aho-Corasick matcher introduced there is unaffected, but
PatriciaTree.Insertitself (and MF1/MF2/MF3 consumers, e.g.pt.root.get) still has the bug.