Skip to content

Commit

Permalink
fix: crash due to VarStack exceeding its capacity
Browse files Browse the repository at this point in the history
  • Loading branch information
plusvic committed Nov 21, 2023
1 parent e73db53 commit 48fc7ae
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
6 changes: 4 additions & 2 deletions yara-x/src/compiler/ir/ast2ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -818,8 +818,10 @@ fn for_in_expr_from_ast(
}

// Create stack frame with capacity for the loop variables, plus 4
// temporary variables used for controlling the loop.
let mut stack_frame = ctx.vars.new_frame(loop_vars.len() as i32 + 4);
// temporary variables used for controlling the loop (see emit_for),
// plus one additional variable used in loops over arrays and maps
// (see emit_for_in_array and emit_for_in_map).
let mut stack_frame = ctx.vars.new_frame(loop_vars.len() as i32 + 5);
let mut symbols = SymbolTable::new();
let mut variables = Vec::new();

Expand Down
18 changes: 18 additions & 0 deletions yara-x/src/modules/test_proto2/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,18 @@ fn test_proto2_module() {
)"#
);

condition_true!(
r#"for 1 s in test_proto2.array_struct : (
s.nested_int32_zero == 0
)"#
);

condition_false!(
r#"for 2 s in test_proto2.array_struct : (
s.nested_int32_zero == 0
)"#
);

condition_true!(
r#"for any s in test_proto2.array_struct : (
s.nested_int32_zero == 0 and
Expand All @@ -174,6 +186,12 @@ fn test_proto2_module() {
)"#
);

condition_true!(
r#"for 1 key, value in test_proto2.map_int64_int64 : (
key == 100 and value == 1000
)"#
);

condition_true!(
r#"for any key, value in test_proto2.map_int64_string : (
key == 100 and value == "one thousand"
Expand Down

0 comments on commit 48fc7ae

Please sign in to comment.