From 33b75d2912403fbe28d8f4a8900ea3d2631bb78c Mon Sep 17 00:00:00 2001 From: Yi LIU Date: Sat, 21 Feb 2026 10:42:11 +0800 Subject: [PATCH] Fix array.init_elem to use source offset when reading segment data The interpreter's visitArrayInitElem was ignoring the source offset parameter when reading from the element segment. It used seg->data[i] instead of seg->data[offsetVal + i], meaning it always read from the beginning of the segment regardless of the specified offset. The offset was already correctly computed and used in the bounds check, but not in the actual data access loop. This is now consistent with how visitArrayInitData handles its offset parameter. --- src/wasm-interpreter.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h index 5ae570437ed..a683c7e2587 100644 --- a/src/wasm-interpreter.h +++ b/src/wasm-interpreter.h @@ -4597,7 +4597,8 @@ class ModuleRunnerBase : public ExpressionRunner { // of references in the table! ArrayNew suffers the same problem. // Fixing it will require changing how we represent segments, at least // in the interpreter. - data->values[indexVal + i] = self()->visit(seg->data[i]).getSingleValue(); + data->values[indexVal + i] = + self()->visit(seg->data[offsetVal + i]).getSingleValue(); } return {}; }