ladybird/Libraries/LibWasm/AbstractMachine
Pavel Shliak a125bc97c4
Some checks are pending
CI / macOS, arm64, Sanitizer, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / Linux, x86_64 (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
LibWasm: Fix memory.fill ignoring memory index and unsafe bounds check
Previously, the memory.fill instruction always wrote to memory 0,
ignoring the selected memory index. This caused incorrect behavior
in multi-memory modules (e.g. filling mem0 instead of mem1).
Additionally, the bounds check used `destination_offset + count`
without overflow checking, which could wrap and bypass validation.

This patch:
- Passes `args.memory_index` into store_to_memory, so the correct
  memory is filled.
- Uses Checked<u32> for destination_offset + count, consistent
  with memory.copy and memory.init, to prevent overflow.

Minimal repro:

    (module
      (memory $m0 1)
      (memory $m1 1)

      (func (export "go") (result i32)
        ;; Fill mem1[0] with 0xAA
        i32.const 0
        i32.const 170
        i32.const 1
        memory.fill (memory 1)

        ;; Return (mem1[0] << 8) | mem0[0]
        i32.const 0
        i32.load8_u (memory 1)
        i32.const 8
        i32.shl
        i32.const 0
        i32.load8_u (memory 0)
        i32.or
      )
    )

Before fix: returns 170 (0x00AA).
After fix:  returns 43520 (0xAA00).
2025-09-06 08:51:11 +02:00
..
AbstractMachine.cpp LibWasm: Move the interpreter IP out of the configuration object 2025-08-26 15:20:33 +02:00
AbstractMachine.h LibWasm: Move the interpreter IP out of the configuration object 2025-08-26 15:20:33 +02:00
BytecodeInterpreter.cpp LibWasm: Fix memory.fill ignoring memory index and unsafe bounds check 2025-09-06 08:51:11 +02:00
BytecodeInterpreter.h LibWasm: Move the interpreter IP out of the configuration object 2025-08-26 15:20:33 +02:00
Configuration.cpp LibWasm: Move the interpreter IP out of the configuration object 2025-08-26 15:20:33 +02:00
Configuration.h LibWasm: Move the interpreter IP out of the configuration object 2025-08-26 15:20:33 +02:00
Interpreter.h LibWasm: Make traps hold on to externally-managed data 2025-04-22 08:43:46 -06:00
Operators.h LibWasm: Fix Negate::name() to return "neg" 2025-09-06 01:06:58 +02:00
Validator.cpp LibWasm: Move the interpreter IP out of the configuration object 2025-08-26 15:20:33 +02:00
Validator.h LibWasm: Avoid allocations for the label stack as much as possible 2025-08-26 15:20:33 +02:00