Coverage Report

Created: 2025-07-12 06:42

/src/tomlplusplus/fuzzing/toml_fuzzer.cpp
Line
Count
Source (jump to first uncovered line)
1
#include <cstdint>
2
#include <fuzzer/FuzzedDataProvider.h>
3
4
#include <toml++/toml.hpp>
5
6
enum class SerializationTest
7
{
8
    NONE = 0,
9
    JSON,
10
    YAML,
11
    TOML,
12
    kMaxValue = TOML
13
};
14
15
extern "C" int LLVMFuzzerTestOneInput(const std::uint8_t* data, const std::size_t size)
16
6.64k
{
17
6.64k
    FuzzedDataProvider fdp{data, size};
18
6.64k
    try
19
6.64k
    {
20
6.64k
        const toml::table tbl = toml::parse(fdp.ConsumeRandomLengthString());
21
22
6.64k
        switch (fdp.ConsumeEnum<SerializationTest>())
23
6.64k
        {
24
13
            case SerializationTest::JSON:
25
13
                static_cast<void>(toml::json_formatter{tbl});
26
13
                break;
27
15
            case SerializationTest::YAML:
28
15
                static_cast<void>(toml::yaml_formatter{tbl});
29
15
                break;
30
8
            case SerializationTest::TOML:
31
8
                static_cast<void>(toml::toml_formatter{tbl});
32
3.29k
            default:
33
3.29k
                break;
34
6.64k
        }
35
6.64k
    }
36
6.64k
    catch (const toml::parse_error&)
37
6.64k
    {
38
3.33k
        return -1;
39
3.33k
    }
40
3.31k
    return 0;
41
6.64k
}