Skip to content

Commit

Permalink
fix: ensure ExecutionStack cannot exceed MAX_STACK_SIZE
Browse files Browse the repository at this point in the history
  • Loading branch information
sdbondi committed Nov 16, 2021
1 parent a5defb7 commit a7bbd35
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/script/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,18 +250,18 @@ impl ExecutionStack {
}

pub fn from_bytes(bytes: &[u8]) -> Result<Self, ScriptError> {
let mut items = Vec::new();
let mut stack = ExecutionStack { items };
let mut byte_str = bytes;
while !byte_str.is_empty() {
match StackItem::read_next(byte_str) {
Some((item, b)) => {
items.push(item);
stack.push(item)?;
byte_str = b;
},
None => return Err(ScriptError::InvalidInput),
}
}
Ok(ExecutionStack { items })
Ok(stack)
}

/// Pushes the item onto the top of the stack. This function will only error if the new stack size exceeds the
Expand Down
5 changes: 5 additions & 0 deletions src/script/tari_script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ impl TariScript {
}
}

/// Returns the number of script op codes
pub fn size(&self) -> usize {
self.script.len()
}

fn should_execute(&self, opcode: &Opcode, state: &ExecutionState) -> Result<bool, ScriptError> {
use Opcode::*;
match opcode {
Expand Down

0 comments on commit a7bbd35

Please sign in to comment.