forked from SerenityOS/serenity
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
1 parent
7d71798
commit e1099a1
Showing
9 changed files
with
47 additions
and
105 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters