1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 06:48:13 +00:00
serenity/Meta/Lagom/Fuzzers/FuzzJs.cpp
Andrew Kaster cabc99e953 Fuzzers: Skip trying to parse invalid UTF-8 in LibJS Fuzzers
Invalid UTF-8 crashes JS::Script::Parse.
2023-03-18 15:56:18 +01:00

28 lines
872 B
C++

/*
* Copyright (c) 2020, the SerenityOS developers.
* Copyright (c) 2022, Luke Wilde <lukew@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/StringView.h>
#include <LibJS/Interpreter.h>
#include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Script.h>
#include <stddef.h>
#include <stdint.h>
extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size)
{
auto js = StringView(static_cast<unsigned char const*>(data), size);
// FIXME: https://github.com/SerenityOS/serenity/issues/17899
if (!Utf8View(js).validate())
return 0;
auto vm = MUST(JS::VM::create());
auto interpreter = JS::Interpreter::create<JS::GlobalObject>(*vm);
auto parse_result = JS::Script::parse(js, interpreter->realm());
if (!parse_result.is_error())
(void)interpreter->run(parse_result.value());
return 0;
}