Skip to content

patricia: Insert loses an existing key when its proper prefix is inserted later #21626

Description

@sudeepdino008

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions