Skip to content

Commit 39acaf1

Browse files
authored
limit the number of instructions that can be evaluated (#2459)
* limit the number of instructions that can be evaluated * code cleanup
1 parent dc9e298 commit 39acaf1

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

sqlx-sqlite/src/connection/explain.rs

+9
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ const OP_HALT: &str = "Halt";
128128
const OP_HALT_IF_NULL: &str = "HaltIfNull";
129129

130130
const MAX_LOOP_COUNT: u8 = 2;
131+
const MAX_TOTAL_INSTRUCTION_COUNT: u32 = 100_000;
131132

132133
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
133134
enum ColumnType {
@@ -428,13 +429,21 @@ pub(super) fn explain(
428429

429430
let mut visited_branch_state: HashSet<BranchStateHash> = HashSet::new();
430431

432+
let mut gas = MAX_TOTAL_INSTRUCTION_COUNT;
431433
let mut result_states = Vec::new();
432434

433435
while let Some(mut state) = states.pop() {
434436
while state.program_i < program_size {
435437
let (_, ref opcode, p1, p2, p3, ref p4) = program[state.program_i];
436438
state.history.push(state.program_i);
437439

440+
//limit the number of 'instructions' that can be evaluated
441+
if gas > 0 {
442+
gas -= 1;
443+
} else {
444+
break;
445+
}
446+
438447
if state.visited[state.program_i] > MAX_LOOP_COUNT {
439448
if logger.log_enabled() {
440449
let program_history: Vec<&(i64, String, i64, i64, i64, Vec<u8>)> =

0 commit comments

Comments
 (0)