Coverage Report

Created: 2025-10-27 07:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/mpv/fuzzers/fuzzer_set_property.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
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
21
30.1k
{
22
30.1k
    if (size > MAX_FUZZ_SIZE)
23
22
        return 0;
24
25
30.1k
    size_t value_len;
26
30.1k
    switch (MPV_FORMAT)
27
30.1k
    {
28
20.7k
    case MPV_FORMAT_STRING:
29
20.7k
        value_len = strnlen(data, size);
30
20.7k
        if (!value_len || value_len == size)
31
7
            return 0;
32
20.7k
        value_len += 1;
33
20.7k
        break;
34
2.40k
    case MPV_FORMAT_FLAG:
35
2.40k
        value_len = sizeof(int);
36
2.40k
        break;
37
3.85k
    case MPV_FORMAT_INT64:
38
3.85k
        value_len = sizeof(int64_t);
39
3.85k
        break;
40
3.14k
    case MPV_FORMAT_DOUBLE:
41
3.14k
        value_len = sizeof(double);
42
3.14k
        break;
43
0
    default:
44
0
        exit(1);
45
0
        break;
46
30.1k
    }
47
48
    // at least two bytes for the name
49
30.1k
    if (size < value_len + 2)
50
42
        return 0;
51
52
30.1k
    const char *name = (const char *)data + value_len;
53
30.1k
    size_t name_len = strnlen(name, size - value_len);
54
30.1k
    if (!name_len || name_len != size - value_len - 1)
55
238
        return 0;
56
57
29.8k
    set_fontconfig_sysroot();
58
59
29.8k
    mpv_handle *ctx = mpv_create();
60
29.8k
    if (!ctx)
61
0
        exit(1);
62
63
29.8k
    check_error(mpv_set_option_string(ctx, "msg-level", "all=trace"));
64
29.8k
    check_error(mpv_set_option_string(ctx, "network-timeout", "1"));
65
66
#if MPV_RUN
67
    check_error(mpv_set_option_string(ctx, "vo", "null"));
68
    check_error(mpv_set_option_string(ctx, "ao", "null"));
69
70
    check_error(mpv_initialize(ctx));
71
#endif
72
73
29.8k
    int ret;
74
29.8k
    if (MPV_FORMAT == MPV_FORMAT_STRING) {
75
20.7k
        ret = mpv_set_property_string(ctx, name, (void *)data);
76
20.7k
    } else {
77
9.15k
        ret = mpv_set_property(ctx, name, MPV_FORMAT, (void *)data);
78
9.15k
    }
79
80
29.8k
    if (ret != MPV_ERROR_SUCCESS)
81
12.9k
        goto done;
82
83
#if MPV_RUN
84
    check_error(mpv_set_option_string(ctx, "ao-null-untimed", "yes"));
85
    check_error(mpv_set_option_string(ctx, "loop-file", "no"));
86
    check_error(mpv_set_option_string(ctx, "loop-playlist", "no"));
87
    check_error(mpv_set_option_string(ctx, "pause", "no"));
88
    check_error(mpv_set_option_string(ctx, "untimed", "yes"));
89
    check_error(mpv_set_option_string(ctx, "sstep", "0"));
90
    check_error(mpv_set_option_string(ctx, "idle", "yes"));
91
92
    mpv_node node = {
93
        .format = MPV_FORMAT_NODE_ARRAY,
94
        .u.list = &(mpv_node_list) {
95
            .num = 1,
96
            .values = &(mpv_node) {
97
                .format = MPV_FORMAT_STRING,
98
                .u.string = "av://lavfi:sine=d=0.1",
99
            },
100
        },
101
    };
102
    check_error(mpv_set_option(ctx, "audio-files", MPV_FORMAT_NODE, &node));
103
104
    node.u.list->num = 0;
105
    check_error(mpv_set_option(ctx, "cover-art-files", MPV_FORMAT_NODE, &node));
106
    check_error(mpv_set_option(ctx, "external-files", MPV_FORMAT_NODE, &node));
107
    check_error(mpv_set_option(ctx, "sub-files", MPV_FORMAT_NODE, &node));
108
109
    const char *cmd[] = {"loadfile", "av://lavfi:yuvtestsrc=d=0.1", NULL};
110
    check_error(mpv_command(ctx, cmd));
111
112
    player_loop(ctx);
113
#endif
114
115
29.8k
done:
116
29.8k
    mpv_terminate_destroy(ctx);
117
118
29.8k
    return 0;
119
29.8k
}