Enforce a combined max stack depth of 1000 after every opcode.
This limit is for the sum of main and alt stacks. Found by bitcoind negative tests.
This commit is contained in:
parent
d6d755e411
commit
dec16d7ff2
1 changed files with 12 additions and 0 deletions
12
script.go
12
script.go
|
@ -116,8 +116,16 @@ var (
|
||||||
// StackErrNonPushOnly is returned when ScriptInfo is called with a
|
// StackErrNonPushOnly is returned when ScriptInfo is called with a
|
||||||
// pkScript that peforms operations other that pushing data to the stack.
|
// pkScript that peforms operations other that pushing data to the stack.
|
||||||
StackErrNonPushOnly = errors.New("SigScript is non pushonly")
|
StackErrNonPushOnly = errors.New("SigScript is non pushonly")
|
||||||
|
|
||||||
|
// StackErrOverflow is returned when stack and altstack combined depth
|
||||||
|
// is over the limit.
|
||||||
|
StackErrOverflow = errors.New("Stacks overflowed")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// maxStackSize is the maximum combined height of stack and alt stack during
|
||||||
|
// execution.
|
||||||
|
const maxStackSize = 1000
|
||||||
|
|
||||||
// ErrUnsupportedAddress is returned when a concrete type that implements
|
// ErrUnsupportedAddress is returned when a concrete type that implements
|
||||||
// a btcutil.Address is not a supported type.
|
// a btcutil.Address is not a supported type.
|
||||||
var ErrUnsupportedAddress = errors.New("unsupported address type")
|
var ErrUnsupportedAddress = errors.New("unsupported address type")
|
||||||
|
@ -599,6 +607,10 @@ func (m *Script) Step() (done bool, err error) {
|
||||||
return true, err
|
return true, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if m.dstack.Depth() + m.astack.Depth() > maxStackSize {
|
||||||
|
return false, StackErrOverflow
|
||||||
|
}
|
||||||
|
|
||||||
// prepare for next instruction
|
// prepare for next instruction
|
||||||
m.scriptoff++
|
m.scriptoff++
|
||||||
if m.scriptoff >= len(m.scripts[m.scriptidx]) {
|
if m.scriptoff >= len(m.scripts[m.scriptidx]) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue