Stream: git-wasmtime

Topic: wasmtime / issue #7401 There is a bug in "invoke_func" fu...


view this post on Zulip Wasmtime GitHub notifications bot (Oct 30 2023 at 02:51):

liutao-liu added the bug label to Issue #7401.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 30 2023 at 02:51):

liutao-liu opened issue #7401:

### Test Case
Na

Steps to Reproduce

When I input "target/debug/wasmtime run my.wasm --invoke my_func_name 1.1" in the command line, i got an error "invalid digit found in string".

Expected Results

The entered parameter "1.1" can be parsed successfully.

Actual Results

Got an error:"invalid digit found in string"。

Versions and Environment

Wasmtime version or commit: wasmtime-cli 13.0.0

Operating system: Ubuntu 20.04

Architecture: Na

Extra Info

【Root Cause】
https://github.com/bytecodealliance/wasmtime/blob/519808fc5c2565f11f9b6a7f5fe3d2385f9f95e8/src/commands/run.rs#L507

The function invoke_func attempted to cast a floating-point string to F32/F64,which is actually a u32/u64 type.

【Solution】
I think this conversion should be written like this:

 let val: f32 = val.parse()?;
 let ptr = &val as *const f32 as *const u32;
 let val = unsafe { *ptr };

~~~

view this post on Zulip Wasmtime GitHub notifications bot (Oct 30 2023 at 07:22):

bjorn3 commented on issue #7401:

You can use .to_bits() on f32 to avoid unsafe code.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 30 2023 at 13:22):

liutao-liu edited issue #7401:

### Test Case
Na

Steps to Reproduce

When I input "target/debug/wasmtime run my.wasm --invoke my_func_name 1.1" in the command line, i got an error "invalid digit found in string".

Expected Results

The entered parameter "1.1" can be parsed successfully.

Actual Results

Got an error:"invalid digit found in string"。

Versions and Environment

Wasmtime version or commit: wasmtime-cli 13.0.0

Operating system: Ubuntu 20.04

Architecture: Na

Extra Info

【Root Cause】
https://github.com/bytecodealliance/wasmtime/blob/519808fc5c2565f11f9b6a7f5fe3d2385f9f95e8/src/commands/run.rs#L507

The function invoke_func attempted to cast a floating-point string to F32/F64,which is actually a u32/u64 type.

【Solution】
I think this conversion should be written like this:

let val: f32 = val.parse()?;
let val = val.to_bits();

~~~

view this post on Zulip Wasmtime GitHub notifications bot (Oct 30 2023 at 13:23):

liutao-liu commented on issue #7401:

You can use .to_bits() on f32 to avoid unsafe code.

You're right, I've revised it as you suggested.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 30 2023 at 13:42):

alexcrichton commented on issue #7401:

Can you share the WebAssembly module that is being run? If the argument is of type i32 in wasm then it doesn't accept a floating point number as an argument (e.g. it won't call to_bits()).

view this post on Zulip Wasmtime GitHub notifications bot (Oct 31 2023 at 07:01):

liutao-liu commented on issue #7401:

Can you share the WebAssembly module that is being run? If the argument is of type i32 in wasm then it doesn't accept a floating point number as an argument (e.g. it won't call to_bits()).

(module (type $f_t (func (param f32) (result f32))) (func $f_f (type $f_t) (param $a f32) (result f32) local.get $a) (export "ret_f32" (func $f_f)))

view this post on Zulip Wasmtime GitHub notifications bot (Oct 31 2023 at 15:21):

alexcrichton commented on issue #7401:

Can you paste the full wasm module? Or upload it? The input you have provided does not have a function export called my_func_name which you're trying to invoke from the command line

view this post on Zulip Wasmtime GitHub notifications bot (Nov 01 2023 at 01:12):

liutao-liu edited a comment on issue #7401:

Can you share the WebAssembly module that is being run? If the argument is of type i32 in wasm then it doesn't accept a floating point number as an argument (e.g. it won't call to_bits()).

(module (type $f_t (func (param f32) (result f32))) (func $f_f (type $f_t) (param $a f32) (result f32) local.get $a) (export "my_func_name" (func $f_f)))

view this post on Zulip Wasmtime GitHub notifications bot (Nov 01 2023 at 01:17):

liutao-liu commented on issue #7401:

Can you paste the full wasm module? Or upload it? The input you have provided does not have a function export called my_func_name which you're trying to invoke from the command line

(module (type $f_t (func (param f32) (result f32))) (func $f_f (type $f_t) (param $a f32) (result f32) local.get $a) (export "my_func_name" (func $f_f)))

view this post on Zulip Wasmtime GitHub notifications bot (Nov 01 2023 at 01:58):

liutao-liu edited a comment on issue #7401:

Can you paste the full wasm module? Or upload it? The input you have provided does not have a function export called my_func_name which you're trying to invoke from the command line

(module (type $f_t (func (param f32) (result f32))) (func $f_f (type $f_t) (param $a f32) (result f32) local.get $a) (export "my_func_name" (func $f_f)))

target/debug/wasmtime run my.wasm --invoke my_func_name 1.1

view this post on Zulip Wasmtime GitHub notifications bot (Nov 01 2023 at 02:00):

liutao-liu edited a comment on issue #7401:

Can you paste the full wasm module? Or upload it? The input you have provided does not have a function export called my_func_name which you're trying to invoke from the command line
wat:
(module (type $f_t (func (param f32) (result f32))) (func $f_f (type $f_t) (param $a f32) (result f32) local.get $a) (export "my_func_name" (func $f_f)))

invoke command:
target/debug/wasmtime run my.wasm --invoke my_func_name 1.1

view this post on Zulip Wasmtime GitHub notifications bot (Nov 01 2023 at 02:00):

liutao-liu edited a comment on issue #7401:

Can you paste the full wasm module? Or upload it? The input you have provided does not have a function export called my_func_name which you're trying to invoke from the command line

wat:
(module (type $f_t (func (param f32) (result f32))) (func $f_f (type $f_t) (param $a f32) (result f32) local.get $a) (export "my_func_name" (func $f_f)))

invoke command:
target/debug/wasmtime run my.wasm --invoke my_func_name 1.1

view this post on Zulip Wasmtime GitHub notifications bot (Nov 01 2023 at 02:01):

liutao-liu edited a comment on issue #7401:

Can you paste the full wasm module? Or upload it? The input you have provided does not have a function export called my_func_name which you're trying to invoke from the command line

my.wat:
(module (type $f_t (func (param f32) (result f32))) (func $f_f (type $f_t) (param $a f32) (result f32) local.get $a) (export "my_func_name" (func $f_f)))

invoke command:
target/debug/wasmtime run my.wat --invoke my_func_name 1.1

view this post on Zulip Wasmtime GitHub notifications bot (Nov 01 2023 at 02:05):

liutao-liu edited a comment on issue #7401:

Can you paste the full wasm module? Or upload it? The input you have provided does not have a function export called my_func_name which you're trying to invoke from the command line

my.wat:

(module
  (type $f_t (func (param f32) (result f32)))
  (func $f_f (type $f_t) (param $a f32) (result f32)
      local.get $a)
(export "my_func_name" (func $f_f)))

invoke command:

target/debug/wasmtime run my.wat --invoke my_func_name 1.1

view this post on Zulip Wasmtime GitHub notifications bot (Nov 01 2023 at 15:05):

alexcrichton commented on issue #7401:

Thanks for the clarification, this should be fixed in https://github.com/bytecodealliance/wasmtime/pull/7440

view this post on Zulip Wasmtime GitHub notifications bot (Nov 01 2023 at 17:32):

pchickey closed issue #7401:

### Test Case
Na

Steps to Reproduce

When I input "target/debug/wasmtime run my.wasm --invoke my_func_name 1.1" in the command line, i got an error "invalid digit found in string".

Expected Results

The entered parameter "1.1" can be parsed successfully.

Actual Results

Got an error:"invalid digit found in string"。

Versions and Environment

Wasmtime version or commit: wasmtime-cli 13.0.0

Operating system: Ubuntu 20.04

Architecture: Na

Extra Info

【Root Cause】
https://github.com/bytecodealliance/wasmtime/blob/519808fc5c2565f11f9b6a7f5fe3d2385f9f95e8/src/commands/run.rs#L507

The function invoke_func attempted to cast a floating-point string to F32/F64,which is actually a u32/u64 type.

【Solution】
I think this conversion should be written like this:

let val: f32 = val.parse()?;
let val = val.to_bits();

~~~


Last updated: Nov 22 2024 at 16:03 UTC