mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:57:45 +00:00
Fuzzers: Use a single fuzzer to test all LibTextCodec encodings
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.
This commit is contained in:
parent
7d717986de
commit
e1099a1757
9 changed files with 47 additions and 105 deletions
29
Meta/Lagom/Fuzzers/FuzzTextDecoder.cpp
Normal file
29
Meta/Lagom/Fuzzers/FuzzTextDecoder.cpp
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* 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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue