Coverage Report

Created: 2025-12-10 06:44

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/mpv/fuzzers/fuzzer_json.c
Line
Count
Source
1
/*
2
 * This file is part of mpv.
3
 *
4
 * mpv is free software; you can redistribute it and/or
5
 * modify it under the terms of the GNU Lesser General Public
6
 * License as published by the Free Software Foundation; either
7
 * version 2.1 of the License, or (at your option) any later version.
8
 *
9
 * mpv is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU Lesser General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Lesser General Public
15
 * License along with mpv.  If not, see <http://www.gnu.org/licenses/>.
16
 */
17
18
#include "common.h"
19
20
#include "misc/json.h"
21
#include "mpv_talloc.h"
22
23
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
24
1.79k
{
25
1.79k
    if (size > MAX_FUZZ_SIZE)
26
4
        return 0;
27
28
1.79k
    void *tmp = talloc_new(NULL);
29
1.79k
    char *s = talloc_array_ptrtype(tmp, s, size + 1);
30
1.79k
    memcpy(s, data, size);
31
1.79k
    s[size] = '\0';
32
33
1.79k
    json_skip_whitespace(&s);
34
35
1.79k
    struct mpv_node res;
36
1.79k
    if (!json_parse(tmp, &res, &s, MAX_JSON_DEPTH)) {
37
686
        char *d = talloc_strdup(tmp, "");
38
686
        json_write(&d, &res);
39
40
686
        d[0] = '\0';
41
686
        json_write_pretty(&d, &res);
42
686
    }
43
44
1.79k
    talloc_free(tmp);
45
46
1.79k
    return 0;
47
1.79k
}