-
Notifications
You must be signed in to change notification settings - Fork 25
fix(compiler): fix false-negative OOB when imm base+offset > INT32_MAX #427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| ;; Test: store with immediate base where (uint64_t)base + offset overflows | ||
| ;; 32-bit arithmetic. The effective address exceeds memory size and MUST trap. | ||
| ;; | ||
| ;; base(unsigned) = 0xFFDFFFFF = 4292870143, offset = 1257956348 | ||
| ;; Effective address = 4292870143 + 1257956348 = 5550826491 | ||
| ;; Memory size = 32769 * 65536 = 2147549184 | ||
| ;; 5550826491 + 2 > 2147549184 => out-of-bounds, MUST trap. | ||
|
|
||
| (module | ||
| (memory (;0;) 32769) | ||
|
|
||
| ;; const base + offset overflows 32-bit => OOB | ||
| (func (export "i64_store16_const_base_overflow_oob") | ||
| i32.const -2097153 | ||
| i64.const 0 | ||
| i64.store16 offset=1257956348 align=1) | ||
|
|
||
| ;; dynamic base (same value via param) + offset overflows 32-bit => OOB | ||
| (func (export "i64_store16_param_base_overflow_oob") (param i32) | ||
| local.get 0 | ||
| i64.const 0 | ||
| i64.store16 offset=1257956348 align=1) | ||
|
|
||
| ;; const base + offset overflows 32-bit for load => OOB | ||
| (func (export "i64_load16_u_const_base_overflow_oob") (result i64) | ||
| i32.const -2097153 | ||
| i64.load16_u offset=1257956348 align=1) | ||
| ) | ||
|
|
||
| (assert_trap (invoke "i64_store16_const_base_overflow_oob") "out of bounds memory access") | ||
| (assert_trap (invoke "i64_store16_param_base_overflow_oob" (i32.const -2097153)) "out of bounds memory access") | ||
| (assert_trap (invoke "i64_load16_u_const_base_overflow_oob") "out of bounds memory access") | ||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,44 @@ | ||||||||||
| ;; Test: f64.store with offset >= INT32_MAX on large memory should NOT trap. | ||||||||||
| ;; | ||||||||||
| ;; When offset >= 0x80000000, x86-64 disp32 sign-extends to a negative 64-bit | ||||||||||
| ;; value, causing the effective address to go before MemBase. The JIT must | ||||||||||
| ;; compute the full 64-bit address explicitly to avoid this. | ||||||||||
| ;; | ||||||||||
| ;; Effective address = memory.size(65131) + offset(4268353288) = 4268418419 | ||||||||||
| ;; Memory size = 65131 * 65536 = 4269236224 | ||||||||||
| ;; 4268418419 + 8 <= 4269236224 => in-bounds, should NOT trap. | ||||||||||
|
Comment on lines
+8
to
+9
|
||||||||||
| ;; Memory size = 65131 * 65536 = 4269236224 | |
| ;; 4268418419 + 8 <= 4269236224 => in-bounds, should NOT trap. | |
| ;; Memory size = 65131 * 65536 = 4268425216 | |
| ;; 4268418419 + 8 <= 4268425216 => in-bounds, should NOT trap. |
Copilot
AI
Mar 23, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test instantiates a very large minimum memory (65131 pages ≈ 4.27GB). Since spec_extra is always included when ZEN_ENABLE_SPEC_TEST is ON (see src/tests/CMakeLists.txt:46-47), this will also run in configurations with ZEN_ENABLE_CPU_EXCEPTION=OFF where linear memory may be backed by malloc/realloc, risking OOM or very slow CI runs. Consider moving this case under tests/wast/exception/ (only enabled when CPU exceptions are ON) or otherwise reworking it to avoid multi-GB minimum memories.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test requires a 32769-page minimum memory (~2GB). Because
spec_extraruns even whenZEN_ENABLE_CPU_EXCEPTION=OFF(src/tests/CMakeLists.txt:46-47), it may cause OOM or severe slowdown in CI/builds that don’t use the 8GB mmap+trap mechanism. Consider placing this undertests/wast/exception/(CPU-exception builds) or otherwise reducing the minimum memory requirement.