/src/serenity/Meta/Lagom/Fuzzers/FuzzTextDecoder.cpp
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2021-2023, the SerenityOS developers. |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #include <LibTextCodec/Decoder.h> |
8 | | #include <stddef.h> |
9 | | #include <stdint.h> |
10 | | |
11 | | extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size) |
12 | 2.69k | { |
13 | 2.69k | AK::set_debug_enabled(false); |
14 | | |
15 | 2.69k | static constexpr StringView MAGIC_SEPARATOR = "|DATA|"sv; |
16 | 2.69k | StringView data_string_view { data, size }; |
17 | 2.69k | auto separator_index = data_string_view.find(MAGIC_SEPARATOR); |
18 | 2.69k | if (!separator_index.has_value()) |
19 | 67 | return 0; |
20 | | |
21 | 2.63k | auto encoding = data_string_view.substring_view(0, separator_index.value()); |
22 | 2.63k | auto encoded_data = data_string_view.substring_view(separator_index.value() + MAGIC_SEPARATOR.length()); |
23 | 2.63k | auto decoder = TextCodec::decoder_for(encoding); |
24 | 2.63k | if (!decoder.has_value()) |
25 | 144 | return 0; |
26 | | |
27 | 2.48k | (void)decoder->to_utf8(encoded_data); |
28 | 2.48k | return 0; |
29 | 2.63k | } |