Skip to content

wast's formatting bug on parsing failure leading to rustc panic #2262

@teyahb8

Description

@teyahb8

Stack trace:

Failed to parse WAT code: 
thread 'main' panicked at .cargo/registry/src/index.crates.io-1949cf8c6b5b557f/wast-235.0.0/src/error.rs:150:9:
Formatting argument out of range
stack backtrace:
   0: __rustc::rust_begin_unwind
             at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/panicking.rs:697:5
   1: core::panicking::panic_fmt
             at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/core/src/panicking.rs:75:14
   2: core::fmt::rt::Argument::from_usize
             at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/core/src/fmt/rt.rs:161:13
   3: <wast::error::Error as core::fmt::Display>::fmt
             at .cargo/registry/src/index.crates.io-1949cf8c6b5b557f/wast-235.0.0/src/error.rs:150:9
   4: core::fmt::rt::Argument::fmt
             at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/core/src/fmt/rt.rs:181:76
   5: core::fmt::write
             at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/core/src/fmt/mod.rs:1446:25
   6: std::io::default_write_fmt
             at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/io/mod.rs:639:11
   7: std::io::Write::write_fmt
             at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/io/mod.rs:1914:13
   8: <&std::io::stdio::Stderr as std::io::Write>::write_fmt
             at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/io/stdio.rs:1066:9
   9: <std::io::stdio::Stderr as std::io::Write>::write_fmt
             at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/io/stdio.rs:1040:9
  10: std::io::stdio::print_to
             at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/io/stdio.rs:1164:21
  11: std::io::stdio::_eprint
             at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/io/stdio.rs:1286:5

Debug print shows the following before the panic:

Failed to parse WAT code: Error { inner: ErrorInner { text: Some(Text { line: 5, col: 192586, snippet: "    (local i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 ... ... ... i64 i64" }), file: None, span: Span { offset: 192729 }, kind: Custom("expected `)`") } }

Test case:
wasm file: 5da873c7eff9ddd4769471706dbfb11bc10cb1d1378c728ea57ed6228fb3a292.wasm.txt
wat file: 5da873c7eff9ddd4769471706dbfb11bc10cb1d1378c728ea57ed6228fb3a292.wat.txt

I used wasm-tools print to convert the wasm file to a wat file and later used the wast crate to parse the generated wat file. wasm-tools print generates incomplete wat code while showing the following error:

error: function exceeds the maximum number of locals that can be printed

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions