1
0
mirror of https://github.com/SerenityOS/serenity synced 2024-07-09 14:27:31 +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:
Tim Ledbetter 2023-11-05 19:24:59 +00:00 committed by Andreas Kling
parent 7d717986de
commit e1099a1757
9 changed files with 47 additions and 105 deletions

View File

@ -1,18 +0,0 @@
/*
* Copyright (c) 2021, 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);
auto decoder = TextCodec::decoder_for("windows-1251"sv);
VERIFY(decoder.has_value());
(void)decoder->to_utf8({ data, size });
return 0;
}

View File

@ -1,18 +0,0 @@
/*
* Copyright (c) 2021, 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);
auto decoder = TextCodec::decoder_for("windows-1255"sv);
VERIFY(decoder.has_value());
(void)decoder->to_utf8({ data, size });
return 0;
}

View File

@ -1,18 +0,0 @@
/*
* Copyright (c) 2021, 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);
auto decoder = TextCodec::decoder_for("windows-1252"sv);
VERIFY(decoder.has_value());
(void)decoder->to_utf8({ data, size });
return 0;
}

View File

@ -1,18 +0,0 @@
/*
* Copyright (c) 2021, 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);
auto decoder = TextCodec::decoder_for("iso-8859-2"sv);
VERIFY(decoder.has_value());
(void)decoder->to_utf8({ data, size });
return 0;
}

View 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;
}

View File

@ -0,0 +1,15 @@
magic_separator="|DATA|"
# encodings
cyrillic_encoding="windows-1251"
hebrew_encoding="windows-1255"
koi8r_encoding="koi8-r"
latin1_encoding="windows-1252"
latin2_encoding="iso-8859-2"
latin9_encoding="iso-8859-15"
mac_roman_encoding="macintosh"
turkish_encoding="windows-1254"
user_defined_encoding="x-user-defined"
utf16be_encoding="utf-16be"
utf16le_encoding="utf-16le"
utf8_encoding="utf-8"

View File

@ -1,18 +0,0 @@
/*
* Copyright (c) 2021, 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);
auto decoder = TextCodec::decoder_for("utf-16be"sv);
VERIFY(decoder.has_value());
(void)decoder->to_utf8({ data, size });
return 0;
}

View File

@ -3,7 +3,6 @@ set(FUZZER_TARGETS
BLAKE2b
BMPLoader
Brotli
CyrillicDecoder
DDSLoader
DNSPacket
DeflateCompression
@ -14,7 +13,6 @@ set(FUZZER_TARGETS
GIFLoader
GzipCompression
GzipDecompression
HebrewDecoder
HttpRequest
ICCProfile
ICOLoader
@ -23,8 +21,6 @@ set(FUZZER_TARGETS
JPEGLoader
Js
JsonParser
Latin1Decoder
Latin2Decoder
LzmaDecompression
LzmaRoundtrip
Markdown
@ -53,12 +49,12 @@ set(FUZZER_TARGETS
ShellPosix
SQLParser
Tar
TextDecoder
TGALoader
TIFFLoader
TTF
TinyVGLoader
URL
UTF16BEDecoder
VP9Decoder
WasmParser
WAVLoader
@ -79,7 +75,6 @@ set(FUZZER_DEPENDENCIES_BLAKE2b LibCrypto)
set(FUZZER_DEPENDENCIES_BMPLoader LibGfx)
set(FUZZER_DEPENDENCIES_Brotli LibCompress)
set(FUZZER_DEPENDENCIES_CSSParser LibWeb)
set(FUZZER_DEPENDENCIES_CyrillicDecoder LibTextCodec)
set(FUZZER_DEPENDENCIES_DDSLoader LibGfx)
set(FUZZER_DEPENDENCIES_DNSPacket LibDNS)
set(FUZZER_DEPENDENCIES_DeflateCompression LibCompress)
@ -90,7 +85,6 @@ set(FUZZER_DEPENDENCIES_Gemini LibGemini)
set(FUZZER_DEPENDENCIES_GIFLoader LibGfx)
set(FUZZER_DEPENDENCIES_GzipCompression LibCompress)
set(FUZZER_DEPENDENCIES_GzipDecompression LibCompress)
set(FUZZER_DEPENDENCIES_HebrewDecoder LibTextCodec)
set(FUZZER_DEPENDENCIES_HttpRequest LibHTTP)
set(FUZZER_DEPENDENCIES_ICCProfile LibGfx)
set(FUZZER_DEPENDENCIES_ICOLoader LibGfx)
@ -98,8 +92,6 @@ set(FUZZER_DEPENDENCIES_ILBMLoader LibGfx)
set(FUZZER_DEPENDENCIES_IMAPParser LibIMAP)
set(FUZZER_DEPENDENCIES_JPEGLoader LibGfx)
set(FUZZER_DEPENDENCIES_Js LibJS)
set(FUZZER_DEPENDENCIES_Latin1Decoder LibTextCodec)
set(FUZZER_DEPENDENCIES_Latin2Decoder LibTextCodec)
set(FUZZER_DEPENDENCIES_LzmaDecompression LibArchive LibCompress)
set(FUZZER_DEPENDENCIES_LzmaRoundtrip LibCompress)
set(FUZZER_DEPENDENCIES_Markdown LibMarkdown)
@ -128,11 +120,11 @@ set(FUZZER_DEPENDENCIES_Shell LibShell)
set(FUZZER_DEPENDENCIES_ShellPosix LibShell)
set(FUZZER_DEPENDENCIES_SQLParser LibSQL)
set(FUZZER_DEPENDENCIES_Tar LibArchive)
set(FUZZER_DEPENDENCIES_TextDecoder LibTextCodec)
set(FUZZER_DEPENDENCIES_TGALoader LibGfx)
set(FUZZER_DEPENDENCIES_TIFFLoader LibGfx)
set(FUZZER_DEPENDENCIES_TTF LibGfx)
set(FUZZER_DEPENDENCIES_TinyVGLoader LibGfx)
set(FUZZER_DEPENDENCIES_UTF16BEDecoder LibTextCodec)
set(FUZZER_DEPENDENCIES_VP9Decoder LibVideo)
set(FUZZER_DEPENDENCIES_WasmParser LibWasm)
set(FUZZER_DEPENDENCIES_WAVLoader LibAudio)

View File

@ -17,7 +17,6 @@
T(BMPLoader) \
T(Brotli) \
T(CSSParser) \
T(CyrillicDecoder) \
T(DDSLoader) \
T(DNSPacket) \
T(DeflateCompression) \
@ -28,7 +27,6 @@
T(GIFLoader) \
T(GzipCompression) \
T(GzipDecompression) \
T(HebrewDecoder) \
T(HttpRequest) \
T(ICCProfile) \
T(ICOLoader) \
@ -37,8 +35,6 @@
T(JPEGLoader) \
T(Js) \
T(JsonParser) \
T(Latin1Decoder) \
T(Latin2Decoder) \
T(LzmaDecompression) \
T(LzmaRoundtrip) \
T(Markdown) \
@ -67,12 +63,12 @@
T(ShellPosix) \
T(SQLParser) \
T(Tar) \
T(TextDecoder) \
T(TGALoader) \
T(TIFFLoader) \
T(TTF) \
T(TinyVGLoader) \
T(URL) \
T(UTF16BEDecoder) \
T(VP9Decoder) \
T(WasmParser) \
T(WAVLoader) \