Stream: git-wasmtime

Topic: wasmtime / issue #746 [lightbeam] add overflow in debug m...


view this post on Zulip Wasmtime GitHub notifications bot (Sep 27 2021 at 17:29):

alexcrichton commented on issue #746:

Lightbeam was removed in https://github.com/bytecodealliance/wasmtime/pull/3390 as explained in RFC 14, so I'm going to close this.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 27 2021 at 17:29):

alexcrichton closed issue #746:

Issue description

An addition with overflow make lightbeam to panic when compiled in debug mode.

$ ./target/debug/debug_lightbeam add_overflow_mark_used_backend_min.wasm
thread 'main' panicked at 'attempt to add with overflow', XXX/wasmtime/crates/lightbeam/src/backend.rs:325:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.

This issue is related to the function mark_used called by function pick.

Backtrace:

  11: lightbeam::backend::Registers::mark_used
             at XXX/wasmtime/crates/lightbeam/src/backend.rs:325
  12: lightbeam::backend::Context<M>::pick
             at XXX/wasmtime/crates/lightbeam/src/backend.rs:5368
  13: lightbeam::function_body::translate
             at XXX/wasmtime/crates/lightbeam/src/function_body.rs:577
  14: lightbeam::function_body::translate_wasm
             at XXX/wasmtime/crates/lightbeam/src/function_body.rs:82

https://github.com/bytecodealliance/wasmtime/blob/a5823896b70aab5f7675c5ff7651e37324c88262/crates/lightbeam/src/backend.rs#L322-L326

https://github.com/bytecodealliance/wasmtime/blob/a5823896b70aab5f7675c5ff7651e37324c88262/crates/lightbeam/src/backend.rs#L5364-L5371

Reproduction

Download:
add_overflow_mark_used_backend_min.zip

or wasm2wat add_overflow_mark_used_backend_min.wasm :

(module
  (type (;0;) (func))
  (func (;0;) (type 0)
    (local i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64)
    i32.const 0
    i64.load offset=0 align=1
    local.set 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    local.get 32
    unreachable)
  (memory (;0;) 1)
  (export "_start" (func 0)))

Testing program (need to be compiled in debug mode i.e. RUSTFLAGS=-g cargo build):

use std::env;
use std::fs::{File};
use std::io;
use std::io::Read;
use std::path::PathBuf;

use wasmtime_fuzzing::oracles;
use wasmtime_jit::CompilationStrategy;
use lightbeam;

/// Read the contents of a file
fn read_contents(path: &PathBuf) -> Result<Vec<u8>, io::Error> {
    let mut buffer: Vec<u8> = Vec::new();
    let mut file = File::open(path)?;
    file.read_to_end(&mut buffer)?;
    drop(file);
    Ok(buffer)
}

fn main() {
    let args: Vec<String> = env::args().collect();
    let wasm_path = std::path::PathBuf::from(&args[1]);
    let wasm_binary: Vec<u8> = read_contents(&wasm_path).unwrap();

    let _res_compile = oracles::compile(&wasm_binary[..], CompilationStrategy::Lightbeam);
    let _res_instantiate = oracles::instantiate(&wasm_binary[..], CompilationStrategy::Lightbeam);
    let _res_translate = lightbeam::translate(&wasm_binary[..]);
}

wasmtime commit: a5823896b70aab5f7675c5ff7651e37324c88262

Result when executed by wasmtime

$ ../target/release/wasmtime add_overflow_mark_used_backend_min.wasm
Error: failed to process main module `add_overflow_mark_used_backend_min.wasm`

Caused by:
    0: failed to invoke `_start`
    1: trapped: Ref(Trap { message: "wasm trap: unreachable, source location: @0233" })

$ ../target/release/wasmtime --lightbeam add_overflow_mark_used_backend_min.wasm
Error: failed to process main module `add_overflow_mark_used_backend_min.wasm`

Caused by:
    0: failed to invoke `_start`
    1: trapped: Ref(Trap { message: "wasm trap: call stack exhausted, source location: @-" })

Please note that lightbeam error should be the same than using cranelift backend i.e. unreachable trap reached.


Last updated: Nov 22 2024 at 17:03 UTC