Description
This is a continuation of #1384. The new problem is in PyArray_Broadcast
. The crash specifically happens on line 1177 here.
https://github.com/numpy/numpy/blob/648fe68f79dfbad21947db4b55873703db0675c4/numpy/core/src/multiarray/iterators.c#L1177
Relevant WAT:
local.get $var0 ;; mit
local.get $var3 ;; j
i32.const 2
i32.shl
i32.add ;; &mit->it[j]
i32.load offset=152 ;; crash here 24 + 32 * 4 = 152
See also the definition of PyArrayMultiIterObject:
https://github.com/numpy/numpy/blob/648fe68f79dfbad21947db4b55873703db0675c4/numpy/core/include/numpy/ndarraytypes.h#L1231
I've been triggering it with
import numpy as np
np.meshgrid(range(10), range(10))
which isn't completely consistent but works frequently.
Luckily the CI catches this: the benchmark evolve has been failing to this bug ever since @rth updated the CI to use chrome 89
#1462.
https://app.circleci.com/pipelines/github/pyodide/pyodide/2673/workflows/a9aec892-261d-4eb9-bd4c-3fee0f8bd7a5/jobs/27749
Here's a typical stack trace:
pyodide.js:433 Pyodide has suffered a fatal error, refresh the page. Please report this to the Pyodide maintainers.
pyodide.js:434 The cause of the fatal error was:
pyodide.js:435 RuntimeError: memory access out of bounds
at PyArray_Broadcast (<anonymous>:wasm-function[1536]:0xcdab3)
at <anonymous>:wasm-function[1538]:0xce06f
at __static_809 (<anonymous>:wasm-function[1542]:0xce5f0)
at byn$fpcast-emu$__static_809 (<anonymous>:wasm-function[6879]:0x219772)
at __static_861 (https://cdn.jsdelivr.net/pyodide/dev/full/pyodide.asm.wasm:wasm-function[1971]:0x22cb00)
at byn$fpcast-emu$__static_861 (https://cdn.jsdelivr.net/pyodide/dev/full/pyodide.asm.wasm:wasm-function[22300]:0x7be366)
at PyObject_Call (https://cdn.jsdelivr.net/pyodide/dev/full/pyodide.asm.wasm:wasm-function[762]:0x1caeef)
at _PyEval_EvalFrameDefault (https://cdn.jsdelivr.net/pyodide/dev/full/pyodide.asm.wasm:wasm-function[2757]:0x2a9d0c)
at byn$fpcast-emu$_PyEval_EvalFrameDefault (https://cdn.jsdelivr.net/pyodide/dev/full/pyodide.asm.wasm:wasm-function[15505]:0x7a5f10)
at _PyEval_EvalCodeWithName (https://cdn.jsdelivr.net/pyodide/dev/full/pyodide.asm.wasm:wasm-function[2753]:0x2a41e4)
Stack (most recent call first):
File "/lib/python3.8/site-packages/numpy/lib/stride_tricks.py", line 191 in _broadcast_shape
File "/lib/python3.8/site-packages/numpy/lib/stride_tricks.py", line 264 in broadcast_arrays
File "<__array_function__ internals>", line 5 in broadcast_arrays
File "/lib/python3.8/site-packages/numpy/lib/function_base.py", line 4213 in meshgrid
File "<__array_function__ internals>", line 5 in meshgrid
File "<exec>", line 1 in <module>
File "/lib/python3.8/site-packages/pyodide/_base.py", line 276 in run_async
File "/lib/python3.8/site-packages/pyodide/_base.py", line 419 in eval_code_async
File "/lib/python3.8/site-packages/pyodide/console.py", line 233 in load_packages_and_run