mirror of
https://github.com/SerenityOS/serenity
synced 2024-07-24 11:35:13 +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
|
@ -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;
|
|
||||||
}
|
|
|
@ -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;
|
|
||||||
}
|
|
|
@ -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;
|
|
||||||
}
|
|
|
@ -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;
|
|
||||||
}
|
|
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;
|
||||||
|
}
|
15
Meta/Lagom/Fuzzers/FuzzTextDecoder.dict
Normal file
15
Meta/Lagom/Fuzzers/FuzzTextDecoder.dict
Normal 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"
|
|
@ -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;
|
|
||||||
}
|
|
|
@ -3,7 +3,6 @@ set(FUZZER_TARGETS
|
||||||
BLAKE2b
|
BLAKE2b
|
||||||
BMPLoader
|
BMPLoader
|
||||||
Brotli
|
Brotli
|
||||||
CyrillicDecoder
|
|
||||||
DDSLoader
|
DDSLoader
|
||||||
DNSPacket
|
DNSPacket
|
||||||
DeflateCompression
|
DeflateCompression
|
||||||
|
@ -14,7 +13,6 @@ set(FUZZER_TARGETS
|
||||||
GIFLoader
|
GIFLoader
|
||||||
GzipCompression
|
GzipCompression
|
||||||
GzipDecompression
|
GzipDecompression
|
||||||
HebrewDecoder
|
|
||||||
HttpRequest
|
HttpRequest
|
||||||
ICCProfile
|
ICCProfile
|
||||||
ICOLoader
|
ICOLoader
|
||||||
|
@ -23,8 +21,6 @@ set(FUZZER_TARGETS
|
||||||
JPEGLoader
|
JPEGLoader
|
||||||
Js
|
Js
|
||||||
JsonParser
|
JsonParser
|
||||||
Latin1Decoder
|
|
||||||
Latin2Decoder
|
|
||||||
LzmaDecompression
|
LzmaDecompression
|
||||||
LzmaRoundtrip
|
LzmaRoundtrip
|
||||||
Markdown
|
Markdown
|
||||||
|
@ -53,12 +49,12 @@ set(FUZZER_TARGETS
|
||||||
ShellPosix
|
ShellPosix
|
||||||
SQLParser
|
SQLParser
|
||||||
Tar
|
Tar
|
||||||
|
TextDecoder
|
||||||
TGALoader
|
TGALoader
|
||||||
TIFFLoader
|
TIFFLoader
|
||||||
TTF
|
TTF
|
||||||
TinyVGLoader
|
TinyVGLoader
|
||||||
URL
|
URL
|
||||||
UTF16BEDecoder
|
|
||||||
VP9Decoder
|
VP9Decoder
|
||||||
WasmParser
|
WasmParser
|
||||||
WAVLoader
|
WAVLoader
|
||||||
|
@ -79,7 +75,6 @@ set(FUZZER_DEPENDENCIES_BLAKE2b LibCrypto)
|
||||||
set(FUZZER_DEPENDENCIES_BMPLoader LibGfx)
|
set(FUZZER_DEPENDENCIES_BMPLoader LibGfx)
|
||||||
set(FUZZER_DEPENDENCIES_Brotli LibCompress)
|
set(FUZZER_DEPENDENCIES_Brotli LibCompress)
|
||||||
set(FUZZER_DEPENDENCIES_CSSParser LibWeb)
|
set(FUZZER_DEPENDENCIES_CSSParser LibWeb)
|
||||||
set(FUZZER_DEPENDENCIES_CyrillicDecoder LibTextCodec)
|
|
||||||
set(FUZZER_DEPENDENCIES_DDSLoader LibGfx)
|
set(FUZZER_DEPENDENCIES_DDSLoader LibGfx)
|
||||||
set(FUZZER_DEPENDENCIES_DNSPacket LibDNS)
|
set(FUZZER_DEPENDENCIES_DNSPacket LibDNS)
|
||||||
set(FUZZER_DEPENDENCIES_DeflateCompression LibCompress)
|
set(FUZZER_DEPENDENCIES_DeflateCompression LibCompress)
|
||||||
|
@ -90,7 +85,6 @@ set(FUZZER_DEPENDENCIES_Gemini LibGemini)
|
||||||
set(FUZZER_DEPENDENCIES_GIFLoader LibGfx)
|
set(FUZZER_DEPENDENCIES_GIFLoader LibGfx)
|
||||||
set(FUZZER_DEPENDENCIES_GzipCompression LibCompress)
|
set(FUZZER_DEPENDENCIES_GzipCompression LibCompress)
|
||||||
set(FUZZER_DEPENDENCIES_GzipDecompression LibCompress)
|
set(FUZZER_DEPENDENCIES_GzipDecompression LibCompress)
|
||||||
set(FUZZER_DEPENDENCIES_HebrewDecoder LibTextCodec)
|
|
||||||
set(FUZZER_DEPENDENCIES_HttpRequest LibHTTP)
|
set(FUZZER_DEPENDENCIES_HttpRequest LibHTTP)
|
||||||
set(FUZZER_DEPENDENCIES_ICCProfile LibGfx)
|
set(FUZZER_DEPENDENCIES_ICCProfile LibGfx)
|
||||||
set(FUZZER_DEPENDENCIES_ICOLoader LibGfx)
|
set(FUZZER_DEPENDENCIES_ICOLoader LibGfx)
|
||||||
|
@ -98,8 +92,6 @@ set(FUZZER_DEPENDENCIES_ILBMLoader LibGfx)
|
||||||
set(FUZZER_DEPENDENCIES_IMAPParser LibIMAP)
|
set(FUZZER_DEPENDENCIES_IMAPParser LibIMAP)
|
||||||
set(FUZZER_DEPENDENCIES_JPEGLoader LibGfx)
|
set(FUZZER_DEPENDENCIES_JPEGLoader LibGfx)
|
||||||
set(FUZZER_DEPENDENCIES_Js LibJS)
|
set(FUZZER_DEPENDENCIES_Js LibJS)
|
||||||
set(FUZZER_DEPENDENCIES_Latin1Decoder LibTextCodec)
|
|
||||||
set(FUZZER_DEPENDENCIES_Latin2Decoder LibTextCodec)
|
|
||||||
set(FUZZER_DEPENDENCIES_LzmaDecompression LibArchive LibCompress)
|
set(FUZZER_DEPENDENCIES_LzmaDecompression LibArchive LibCompress)
|
||||||
set(FUZZER_DEPENDENCIES_LzmaRoundtrip LibCompress)
|
set(FUZZER_DEPENDENCIES_LzmaRoundtrip LibCompress)
|
||||||
set(FUZZER_DEPENDENCIES_Markdown LibMarkdown)
|
set(FUZZER_DEPENDENCIES_Markdown LibMarkdown)
|
||||||
|
@ -128,11 +120,11 @@ set(FUZZER_DEPENDENCIES_Shell LibShell)
|
||||||
set(FUZZER_DEPENDENCIES_ShellPosix LibShell)
|
set(FUZZER_DEPENDENCIES_ShellPosix LibShell)
|
||||||
set(FUZZER_DEPENDENCIES_SQLParser LibSQL)
|
set(FUZZER_DEPENDENCIES_SQLParser LibSQL)
|
||||||
set(FUZZER_DEPENDENCIES_Tar LibArchive)
|
set(FUZZER_DEPENDENCIES_Tar LibArchive)
|
||||||
|
set(FUZZER_DEPENDENCIES_TextDecoder LibTextCodec)
|
||||||
set(FUZZER_DEPENDENCIES_TGALoader LibGfx)
|
set(FUZZER_DEPENDENCIES_TGALoader LibGfx)
|
||||||
set(FUZZER_DEPENDENCIES_TIFFLoader LibGfx)
|
set(FUZZER_DEPENDENCIES_TIFFLoader LibGfx)
|
||||||
set(FUZZER_DEPENDENCIES_TTF LibGfx)
|
set(FUZZER_DEPENDENCIES_TTF LibGfx)
|
||||||
set(FUZZER_DEPENDENCIES_TinyVGLoader LibGfx)
|
set(FUZZER_DEPENDENCIES_TinyVGLoader LibGfx)
|
||||||
set(FUZZER_DEPENDENCIES_UTF16BEDecoder LibTextCodec)
|
|
||||||
set(FUZZER_DEPENDENCIES_VP9Decoder LibVideo)
|
set(FUZZER_DEPENDENCIES_VP9Decoder LibVideo)
|
||||||
set(FUZZER_DEPENDENCIES_WasmParser LibWasm)
|
set(FUZZER_DEPENDENCIES_WasmParser LibWasm)
|
||||||
set(FUZZER_DEPENDENCIES_WAVLoader LibAudio)
|
set(FUZZER_DEPENDENCIES_WAVLoader LibAudio)
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
T(BMPLoader) \
|
T(BMPLoader) \
|
||||||
T(Brotli) \
|
T(Brotli) \
|
||||||
T(CSSParser) \
|
T(CSSParser) \
|
||||||
T(CyrillicDecoder) \
|
|
||||||
T(DDSLoader) \
|
T(DDSLoader) \
|
||||||
T(DNSPacket) \
|
T(DNSPacket) \
|
||||||
T(DeflateCompression) \
|
T(DeflateCompression) \
|
||||||
|
@ -28,7 +27,6 @@
|
||||||
T(GIFLoader) \
|
T(GIFLoader) \
|
||||||
T(GzipCompression) \
|
T(GzipCompression) \
|
||||||
T(GzipDecompression) \
|
T(GzipDecompression) \
|
||||||
T(HebrewDecoder) \
|
|
||||||
T(HttpRequest) \
|
T(HttpRequest) \
|
||||||
T(ICCProfile) \
|
T(ICCProfile) \
|
||||||
T(ICOLoader) \
|
T(ICOLoader) \
|
||||||
|
@ -37,8 +35,6 @@
|
||||||
T(JPEGLoader) \
|
T(JPEGLoader) \
|
||||||
T(Js) \
|
T(Js) \
|
||||||
T(JsonParser) \
|
T(JsonParser) \
|
||||||
T(Latin1Decoder) \
|
|
||||||
T(Latin2Decoder) \
|
|
||||||
T(LzmaDecompression) \
|
T(LzmaDecompression) \
|
||||||
T(LzmaRoundtrip) \
|
T(LzmaRoundtrip) \
|
||||||
T(Markdown) \
|
T(Markdown) \
|
||||||
|
@ -67,12 +63,12 @@
|
||||||
T(ShellPosix) \
|
T(ShellPosix) \
|
||||||
T(SQLParser) \
|
T(SQLParser) \
|
||||||
T(Tar) \
|
T(Tar) \
|
||||||
|
T(TextDecoder) \
|
||||||
T(TGALoader) \
|
T(TGALoader) \
|
||||||
T(TIFFLoader) \
|
T(TIFFLoader) \
|
||||||
T(TTF) \
|
T(TTF) \
|
||||||
T(TinyVGLoader) \
|
T(TinyVGLoader) \
|
||||||
T(URL) \
|
T(URL) \
|
||||||
T(UTF16BEDecoder) \
|
|
||||||
T(VP9Decoder) \
|
T(VP9Decoder) \
|
||||||
T(WasmParser) \
|
T(WasmParser) \
|
||||||
T(WAVLoader) \
|
T(WAVLoader) \
|
||||||
|
|
Loading…
Reference in a new issue