As reported in #24860 (review), the current code to construct a miniscript::Node
could cause a blowup on large fuzzer inputs. This is because:
- The duplicate key check is redundantly done at parsing time, since we will recursively create miniscript nodes and the constructor will unconditionally look for duplicate across this node’s keys and all its sub-nodes'.
- We don’t put an upper bound on the size of the inputs to consider for parsing.
To avoid wasteful computation, and prevent the blowup on some fuzzer inputs, limit the size of reasonable inputs and only perform the check for duplicate keys once when parsing.
Regarding the duplicate key check bypass in the constructor we iterated on different approaches, and eventually settled on passing a dummy argument. Albeit less elegant, all other approaches required getting rid of std::make_shared
and adding an allocation per node created.
This PR contains code from Pieter Wuille (see commits).
Fixes #25824.