From 4eaabdad34d14e85cc0bb64769d17b38fa3dbed7 Mon Sep 17 00:00:00 2001 From: Diego <96022404+dzfrias@users.noreply.github.com> Date: Wed, 29 May 2024 10:31:30 -0700 Subject: [PATCH] LibWasm: Properly read blocktypes This works for now, but is technically still not spec compliant. Right now, we're (potentially) missing one bit when reading function indices. See the relevant issue: #24462. --- Userland/Libraries/LibWasm/Parser/Parser.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibWasm/Parser/Parser.cpp b/Userland/Libraries/LibWasm/Parser/Parser.cpp index ebf55b38dc..7ccd03de38 100644 --- a/Userland/Libraries/LibWasm/Parser/Parser.cpp +++ b/Userland/Libraries/LibWasm/Parser/Parser.cpp @@ -254,10 +254,12 @@ ParseResult BlockType::parse(Stream& stream) ReconsumableStream new_stream { stream }; new_stream.unread({ &kind, 1 }); - auto index_value_or_error = stream.read_value>(); + // FIXME: should be an i33. Right now, we're missing a potential last bit at + // the end. See https://webassembly.github.io/spec/core/binary/instructions.html#binary-blocktype + auto index_value_or_error = new_stream.read_value>(); if (index_value_or_error.is_error()) return with_eof_check(stream, ParseError::ExpectedIndex); - ssize_t index_value = index_value_or_error.release_value(); + i32 index_value = index_value_or_error.release_value(); if (index_value < 0) { dbgln("Invalid type index {}", index_value);