Coverage Report

Created: 2026-06-30 06:15

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/crow/tests/fuzz/json_fuzzer.cpp
Line
Count
Source
1
#include <cstdint>
2
#include <string>
3
#include "crow/json.h"
4
5
4.06k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
6
4.06k
    if (size == 0) {
7
0
        return 0;
8
0
    }
9
10
4.06k
    std::string input(reinterpret_cast<const char*>(data), size);
11
4.06k
    try {
12
4.06k
        crow::json::rvalue json_val = crow::json::load(input);
13
4.06k
        if (json_val) {
14
            // If parsing succeeded, try to access some properties to trigger more code
15
2.52k
            auto t = json_val.t();
16
2.52k
            if (t == crow::json::type::Object) {
17
3.12M
                for (const auto& key : json_val.keys()) {
18
3.12M
                    auto& val = json_val[key];
19
3.12M
                    (void)val.t();
20
3.12M
                }
21
2.44k
            } else if (t == crow::json::type::List) {
22
407
                for (const auto& val : json_val) {
23
407
                    (void)val.t();
24
407
                }
25
20
            }
26
            
27
            // Also try to dump it back to string
28
            // (void)crow::json::dump(json_val); // Need to check if dump exists
29
2.52k
        }
30
4.06k
    } catch (...) {
31
        // Ignore exceptions from invalid JSON
32
0
    }
33
34
4.06k
    return 0;
35
4.06k
}