Skip to content

Commit 4c371e6

Browse files
authored
fix: false OOB in array.fill for interp (#4645)
* cherry-pick gc spec test case * Fix false OOB in array.fill
1 parent 25c5d57 commit 4c371e6

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

core/iwasm/interpreter/wasm_interp_classic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3165,7 +3165,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
31653165

31663166
if (len > 0) {
31673167
if ((uint64)start_offset + len
3168-
>= wasm_array_obj_length(array_obj)) {
3168+
> wasm_array_obj_length(array_obj)) {
31693169
wasm_set_exception(
31703170
module, "out of bounds array access");
31713171
goto got_exception;

core/iwasm/interpreter/wasm_interp_fast.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2562,7 +2562,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
25622562

25632563
if (len > 0) {
25642564
if ((uint64)start_offset + len
2565-
>= wasm_array_obj_length(array_obj)) {
2565+
> wasm_array_obj_length(array_obj)) {
25662566
wasm_set_exception(
25672567
module, "out of bounds array access");
25682568
goto got_exception;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
diff --git a/test/core/gc/array_fill.wast b/test/core/gc/array_fill.wast
2+
index 0379ad53..73122178 100644
3+
--- a/test/core/gc/array_fill.wast
4+
+++ b/test/core/gc/array_fill.wast
5+
@@ -79,3 +79,22 @@
6+
(assert_return (invoke "array_get_nth" (i32.const 2)) (i32.const 11))
7+
(assert_return (invoke "array_get_nth" (i32.const 3)) (i32.const 11))
8+
(assert_return (invoke "array_get_nth" (i32.const 4)) (i32.const 0))
9+
+
10+
+;; fill the whole array
11+
+(assert_return (invoke "array_fill" (i32.const 0) (i32.const 42) (i32.const 12)))
12+
+(assert_return (invoke "array_get_nth" (i32.const 0)) (i32.const 42))
13+
+(assert_return (invoke "array_get_nth" (i32.const 2)) (i32.const 42))
14+
+(assert_return (invoke "array_get_nth" (i32.const 5)) (i32.const 42))
15+
+(assert_return (invoke "array_get_nth" (i32.const 11)) (i32.const 42))
16+
+
17+
+;; fill the first element
18+
+(assert_return (invoke "array_fill" (i32.const 0) (i32.const 7) (i32.const 1)))
19+
+(assert_return (invoke "array_get_nth" (i32.const 0)) (i32.const 7))
20+
+(assert_return (invoke "array_get_nth" (i32.const 1)) (i32.const 42))
21+
+(assert_return (invoke "array_get_nth" (i32.const 11)) (i32.const 42))
22+
+
23+
+;; fill the last 2 elements
24+
+(assert_return (invoke "array_fill" (i32.const 10) (i32.const 9) (i32.const 2)))
25+
+(assert_return (invoke "array_get_nth" (i32.const 9)) (i32.const 42))
26+
+(assert_return (invoke "array_get_nth" (i32.const 10)) (i32.const 9))
27+
+(assert_return (invoke "array_get_nth" (i32.const 11)) (i32.const 9))

tests/wamr-test-suites/test_wamr.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ function spec_test()
478478
# Dec 9, 2024. Merge branch 'funcref'
479479
git reset --hard 756060f5816c7e2159f4817fbdee76cf52f9c923
480480
git apply --ignore-whitespace ../../spec-test-script/gc_ignore_cases.patch || exit 1
481+
git apply --ignore-whitespace ../../spec-test-script/gc_array_fill_cases.patch || exit 1
481482

482483
if [[ ${ENABLE_QEMU} == 1 ]]; then
483484
# Decrease the recursive count for tail call cases as nuttx qemu's

0 commit comments

Comments
 (0)