Parcourir la source

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.
Diego il y a 1 an
Parent
commit
4eaabdad34
1 fichiers modifiés avec 4 ajouts et 2 suppressions
  1. 4 2
      Userland/Libraries/LibWasm/Parser/Parser.cpp

+ 4 - 2
Userland/Libraries/LibWasm/Parser/Parser.cpp

@@ -254,10 +254,12 @@ ParseResult<BlockType> BlockType::parse(Stream& stream)
     ReconsumableStream new_stream { stream };
     new_stream.unread({ &kind, 1 });
 
-    auto index_value_or_error = stream.read_value<LEB128<ssize_t>>();
+    // 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<LEB128<i32>>();
     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);