mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
e1099a1757
This commit replaces the 5 fuzzers that previously tested LibTextCodec with a single fuzzer. We now rely on the fuzzer to generate the encoding and separate it from the encoded data with a magic separator. This increases the overall coverage of LibTextCodec and eliminates the possibility of the same error being generated by multiple fuzzers.
29 lines
875 B
C++
29 lines
875 B
C++
/*
|
|
* Copyright (c) 2021-2023, the SerenityOS developers.
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <LibTextCodec/Decoder.h>
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size)
|
|
{
|
|
AK::set_debug_enabled(false);
|
|
|
|
static constexpr StringView MAGIC_SEPARATOR = "|DATA|"sv;
|
|
StringView data_string_view { data, size };
|
|
auto separator_index = data_string_view.find(MAGIC_SEPARATOR);
|
|
if (!separator_index.has_value())
|
|
return 0;
|
|
|
|
auto encoding = data_string_view.substring_view(0, separator_index.value());
|
|
auto encoded_data = data_string_view.substring_view(separator_index.value() + MAGIC_SEPARATOR.length());
|
|
auto decoder = TextCodec::decoder_for(encoding);
|
|
if (!decoder.has_value())
|
|
return 0;
|
|
|
|
(void)decoder->to_utf8(encoded_data);
|
|
return 0;
|
|
}
|