Skip to content

Commit 837dc0b

Browse files
authored
Validate full offset for shared memories (#2472)
This commit fixes a bug in wasmparser where the full offset in a memarg was not validated when the memarg was used with an atomic instruction. This is an internal bug that wasn't caught during the implementation of the memory64 proposal which is necessary to faithfully validate the input module. The fix here is to delegate to the normal `check_memarg` helper which ensures that all the normal rules apply in addition to the extra rule for atomics.
1 parent 8f21770 commit 837dc0b

3 files changed

Lines changed: 18 additions & 1 deletion

File tree

crates/wasmparser/src/validator/operators.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1162,7 +1162,7 @@ where
11621162
"atomic instructions must always specify maximum alignment"
11631163
);
11641164
}
1165-
self.check_memory_index(memarg.memory)
1165+
self.check_memarg(memarg)
11661166
}
11671167

11681168
/// Validates a block type, primarily with various in-flight proposals.

tests/cli/threads.wast

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,13 @@
99
)
1010
)
1111
"must always specify maximum alignment")
12+
13+
(assert_invalid
14+
(module
15+
(memory 1)
16+
(func (param i32) (result i32)
17+
local.get 0
18+
i32.atomic.load offset=0x1_0000_0000
19+
)
20+
)
21+
"offset out of range")

tests/snapshots/cli/threads.wast.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77
"filename": "threads.0.wasm",
88
"module_type": "binary",
99
"text": "must always specify maximum alignment"
10+
},
11+
{
12+
"type": "assert_invalid",
13+
"line": 14,
14+
"filename": "threads.1.wasm",
15+
"module_type": "binary",
16+
"text": "offset out of range"
1017
}
1118
]
1219
}

0 commit comments

Comments
 (0)