Skip to content

Commit 982ebbc

Browse files
timschumialimpfard
authored andcommitted
LibWasm: Port the parser to Core::Stream
1 parent 409fb0f commit 982ebbc

File tree

6 files changed

+286
-257
lines changed

6 files changed

+286
-257
lines changed

Meta/Lagom/Fuzzers/FuzzWasmParser.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@
44
* SPDX-License-Identifier: BSD-2-Clause
55
*/
66

7-
#include <AK/MemoryStream.h>
8-
#include <AK/Stream.h>
7+
#include <LibCore/MemoryStream.h>
98
#include <LibWasm/Types.h>
109
#include <stddef.h>
1110
#include <stdint.h>
1211

1312
extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size)
1413
{
1514
ReadonlyBytes bytes { data, size };
16-
InputMemoryStream stream { bytes };
17-
[[maybe_unused]] auto result = Wasm::Module::parse(stream);
18-
stream.handle_any_error();
15+
auto stream_or_error = Core::Stream::FixedMemoryStream::construct(bytes);
16+
if (stream_or_error.is_error())
17+
return 0;
18+
auto stream = stream_or_error.release_value();
19+
[[maybe_unused]] auto result = Wasm::Module::parse(*stream);
1920
return 0;
2021
}

Tests/LibWasm/test-wasm.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* SPDX-License-Identifier: BSD-2-Clause
55
*/
66

7+
#include <LibCore/MemoryStream.h>
78
#include <LibCore/Stream.h>
89
#include <LibTest/JavaScriptTestRunner.h>
910
#include <LibWasm/AbstractMachine/BytecodeInterpreter.h>
@@ -105,19 +106,11 @@ TESTJS_GLOBAL_FUNCTION(parse_webassembly_module, parseWebAssemblyModule)
105106
if (!is<JS::Uint8Array>(object))
106107
return vm.throw_completion<JS::TypeError>("Expected a Uint8Array argument to parse_webassembly_module");
107108
auto& array = static_cast<JS::Uint8Array&>(*object);
108-
InputMemoryStream stream { array.data() };
109-
ScopeGuard handle_stream_error {
110-
[&] {
111-
stream.handle_any_error();
112-
}
113-
};
114-
auto result = Wasm::Module::parse(stream);
109+
auto stream = Core::Stream::FixedMemoryStream::construct(array.data()).release_value_but_fixme_should_propagate_errors();
110+
auto result = Wasm::Module::parse(*stream);
115111
if (result.is_error())
116112
return vm.throw_completion<JS::SyntaxError>(Wasm::parse_error_to_deprecated_string(result.error()));
117113

118-
if (stream.handle_any_error())
119-
return vm.throw_completion<JS::SyntaxError>("Binary stream contained errors");
120-
121114
HashMap<Wasm::Linker::Name, Wasm::ExternValue> imports;
122115
auto import_value = vm.argument(1);
123116
if (import_value.is_object()) {

0 commit comments

Comments
 (0)