Skip to content

[lightbeam] remainder overflow in debug mode (backend:rem_s:868) #837

@pventuzelo

Description

@pventuzelo

Issue description

lightbeam will try to calculate the remainder even if an overflow occurs in the function rem_s.

$ ./debug_diff_compile panic_remainder_overflow_868_2.wasm 
thread 'main' panicked at 'attempt to calculate the remainder with overflow', XXX/wasmtime/crates/lightbeam/src/backend.rs:868:56
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.

This issue is related to the function rem_s when dealing with the i32.rem_s opcode:

} else {
self.push(ValueLocation::Immediate((dividend % divisor).into()))?;
}

I suspect this issue can also occurs in rem_u:

self.push(ValueLocation::Immediate(
(dividend as $unsigned_ty % divisor as $unsigned_ty).into(),
))?;
}

Reproduction

Download
panic_remainder_overflow_868.zip

(module
  (type (;0;) (func (result i32)))
  (func (;0;) (type 0) (result i32)
    i32.const -2147483648
    i32.const -1
    i32.rem_s
    unreachable))

wasmtime commit: 7890fa6

Metadata

Metadata

Assignees

No one assigned

    Labels

    lightbeamIssues related to the Lightbeam compiler

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions