/src/mpv/fuzzers/common.h
Line | Count | Source (jump to first uncovered line) |
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 | | #pragma once |
19 | | |
20 | | #include <stdbool.h> |
21 | | #include <stdint.h> |
22 | | #include <stdio.h> |
23 | | #include <stdlib.h> |
24 | | #include <string.h> |
25 | | |
26 | | #include <mpv/client.h> |
27 | | |
28 | 122k | #define MAX_FUZZ_SIZE (100 << 10) // 100 KiB |
29 | | |
30 | | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size); |
31 | | |
32 | 125k | #define MPV_STRINGIFY_(X) #X |
33 | 125k | #define MPV_STRINGIFY(X) MPV_STRINGIFY_(X) |
34 | | |
35 | | static inline void check_error(int status) |
36 | 1.34M | { |
37 | 1.34M | if (status < 0) { |
38 | 0 | fprintf(stderr, "mpv API error: %s\n", mpv_error_string(status)); |
39 | 0 | exit(1); |
40 | 0 | } |
41 | 1.34M | } fuzzer_loadfile_direct.c:check_error Line | Count | Source | 36 | 679k | { | 37 | 679k | if (status < 0) { | 38 | 0 | fprintf(stderr, "mpv API error: %s\n", mpv_error_string(status)); | 39 | 0 | exit(1); | 40 | 0 | } | 41 | 679k | } |
Unexecuted instantiation: fuzzer_options_parser.c:check_error fuzzer_load.c:check_error Line | Count | Source | 36 | 431k | { | 37 | 431k | if (status < 0) { | 38 | 0 | fprintf(stderr, "mpv API error: %s\n", mpv_error_string(status)); | 39 | 0 | exit(1); | 40 | 0 | } | 41 | 431k | } |
fuzzer_set_property.c:check_error Line | Count | Source | 36 | 229k | { | 37 | 229k | if (status < 0) { | 38 | 0 | fprintf(stderr, "mpv API error: %s\n", mpv_error_string(status)); | 39 | 0 | exit(1); | 40 | 0 | } | 41 | 229k | } |
Unexecuted instantiation: fuzzer_json.c:check_error |
42 | | |
43 | | static inline bool str_startswith(const char *str, size_t str_len, |
44 | | const char *prefix, size_t prefix_len) |
45 | 62.6k | { |
46 | 62.6k | if (str_len < prefix_len) |
47 | 16 | return false; |
48 | 62.5k | return !memcmp(str, prefix, prefix_len); |
49 | 62.6k | } fuzzer_loadfile_direct.c:str_startswith Line | Count | Source | 45 | 62.6k | { | 46 | 62.6k | if (str_len < prefix_len) | 47 | 16 | return false; | 48 | 62.5k | return !memcmp(str, prefix, prefix_len); | 49 | 62.6k | } |
Unexecuted instantiation: fuzzer_options_parser.c:str_startswith Unexecuted instantiation: fuzzer_load.c:str_startswith Unexecuted instantiation: fuzzer_set_property.c:str_startswith Unexecuted instantiation: fuzzer_json.c:str_startswith |
50 | | |
51 | | static inline void set_fontconfig_sysroot(void) |
52 | 164k | { |
53 | | #ifdef MPV_FONTCONFIG_SYSROOT |
54 | | setenv("FONTCONFIG_SYSROOT", MPV_STRINGIFY(MPV_FONTCONFIG_SYSROOT), 1); |
55 | | #endif |
56 | 164k | } fuzzer_loadfile_direct.c:set_fontconfig_sysroot Line | Count | Source | 52 | 75.4k | { | 53 | | #ifdef MPV_FONTCONFIG_SYSROOT | 54 | | setenv("FONTCONFIG_SYSROOT", MPV_STRINGIFY(MPV_FONTCONFIG_SYSROOT), 1); | 55 | | #endif | 56 | 75.4k | } |
fuzzer_options_parser.c:set_fontconfig_sysroot Line | Count | Source | 52 | 14.5k | { | 53 | | #ifdef MPV_FONTCONFIG_SYSROOT | 54 | | setenv("FONTCONFIG_SYSROOT", MPV_STRINGIFY(MPV_FONTCONFIG_SYSROOT), 1); | 55 | | #endif | 56 | 14.5k | } |
fuzzer_load.c:set_fontconfig_sysroot Line | Count | Source | 52 | 47.4k | { | 53 | | #ifdef MPV_FONTCONFIG_SYSROOT | 54 | | setenv("FONTCONFIG_SYSROOT", MPV_STRINGIFY(MPV_FONTCONFIG_SYSROOT), 1); | 55 | | #endif | 56 | 47.4k | } |
fuzzer_set_property.c:set_fontconfig_sysroot Line | Count | Source | 52 | 27.4k | { | 53 | | #ifdef MPV_FONTCONFIG_SYSROOT | 54 | | setenv("FONTCONFIG_SYSROOT", MPV_STRINGIFY(MPV_FONTCONFIG_SYSROOT), 1); | 55 | | #endif | 56 | 27.4k | } |
Unexecuted instantiation: fuzzer_json.c:set_fontconfig_sysroot |
57 | | |
58 | | #ifndef PLAYBACK_TIME_LIMIT |
59 | 5.87M | #define PLAYBACK_TIME_LIMIT 5 |
60 | | #endif |
61 | | |
62 | | #ifndef EVENTS_LIMIT |
63 | 561k | #define EVENTS_LIMIT 10 |
64 | | #endif |
65 | | |
66 | | static inline void player_loop(mpv_handle *ctx) |
67 | 116k | { |
68 | 116k | bool playing = false; |
69 | 116k | bool loaded = false; |
70 | 116k | int timeout = -1; |
71 | 116k | int events_limit_after_restart = EVENTS_LIMIT; |
72 | 1.45M | while (1) { |
73 | 1.45M | mpv_event *event = mpv_wait_event(ctx, timeout); |
74 | | // If some events are spamming, like audio-reconfig preventing our |
75 | | // timeout to trigger stop after N events. |
76 | 1.45M | if (timeout == PLAYBACK_TIME_LIMIT && events_limit_after_restart-- < 0) |
77 | 440 | break; |
78 | 1.45M | if (timeout == PLAYBACK_TIME_LIMIT && event->event_id == MPV_EVENT_NONE) |
79 | 39 | break; |
80 | 1.45M | if (event->event_id == MPV_EVENT_START_FILE) |
81 | 445k | loaded = playing = true; |
82 | 1.45M | if (event->event_id == MPV_EVENT_END_FILE) { |
83 | 445k | playing = false; |
84 | 445k | events_limit_after_restart = EVENTS_LIMIT; |
85 | 445k | timeout = -1; |
86 | 445k | } |
87 | 1.45M | if (playing && event->event_id == MPV_EVENT_PLAYBACK_RESTART) |
88 | 62.1k | timeout = PLAYBACK_TIME_LIMIT; |
89 | 1.45M | if (loaded && event->event_id == MPV_EVENT_IDLE) |
90 | 115k | break; |
91 | 1.45M | } |
92 | 116k | } fuzzer_loadfile_direct.c:player_loop Line | Count | Source | 67 | 75.4k | { | 68 | 75.4k | bool playing = false; | 69 | 75.4k | bool loaded = false; | 70 | 75.4k | int timeout = -1; | 71 | 75.4k | int events_limit_after_restart = EVENTS_LIMIT; | 72 | 1.10M | while (1) { | 73 | 1.10M | mpv_event *event = mpv_wait_event(ctx, timeout); | 74 | | // If some events are spamming, like audio-reconfig preventing our | 75 | | // timeout to trigger stop after N events. | 76 | 1.10M | if (timeout == PLAYBACK_TIME_LIMIT && events_limit_after_restart-- < 0) | 77 | 317 | break; | 78 | 1.10M | if (timeout == PLAYBACK_TIME_LIMIT && event->event_id == MPV_EVENT_NONE) | 79 | 0 | break; | 80 | 1.10M | if (event->event_id == MPV_EVENT_START_FILE) | 81 | 404k | loaded = playing = true; | 82 | 1.10M | if (event->event_id == MPV_EVENT_END_FILE) { | 83 | 404k | playing = false; | 84 | 404k | events_limit_after_restart = EVENTS_LIMIT; | 85 | 404k | timeout = -1; | 86 | 404k | } | 87 | 1.10M | if (playing && event->event_id == MPV_EVENT_PLAYBACK_RESTART) | 88 | 35.4k | timeout = PLAYBACK_TIME_LIMIT; | 89 | 1.10M | if (loaded && event->event_id == MPV_EVENT_IDLE) | 90 | 75.1k | break; | 91 | 1.10M | } | 92 | 75.4k | } |
Unexecuted instantiation: fuzzer_options_parser.c:player_loop Unexecuted instantiation: fuzzer_load.c:player_loop fuzzer_load.c:player_loop Line | Count | Source | 67 | 30.5k | { | 68 | 30.5k | bool playing = false; | 69 | 30.5k | bool loaded = false; | 70 | 30.5k | int timeout = -1; | 71 | 30.5k | int events_limit_after_restart = EVENTS_LIMIT; | 72 | 205k | while (1) { | 73 | 205k | mpv_event *event = mpv_wait_event(ctx, timeout); | 74 | | // If some events are spamming, like audio-reconfig preventing our | 75 | | // timeout to trigger stop after N events. | 76 | 205k | if (timeout == PLAYBACK_TIME_LIMIT && events_limit_after_restart-- < 0) | 77 | 123 | break; | 78 | 205k | if (timeout == PLAYBACK_TIME_LIMIT && event->event_id == MPV_EVENT_NONE) | 79 | 26 | break; | 80 | 205k | if (event->event_id == MPV_EVENT_START_FILE) | 81 | 30.5k | loaded = playing = true; | 82 | 205k | if (event->event_id == MPV_EVENT_END_FILE) { | 83 | 30.4k | playing = false; | 84 | 30.4k | events_limit_after_restart = EVENTS_LIMIT; | 85 | 30.4k | timeout = -1; | 86 | 30.4k | } | 87 | 205k | if (playing && event->event_id == MPV_EVENT_PLAYBACK_RESTART) | 88 | 16.2k | timeout = PLAYBACK_TIME_LIMIT; | 89 | 205k | if (loaded && event->event_id == MPV_EVENT_IDLE) | 90 | 30.4k | break; | 91 | 205k | } | 92 | 30.5k | } |
Unexecuted instantiation: fuzzer_set_property.c:player_loop Unexecuted instantiation: fuzzer_json.c:player_loop fuzzer_set_property.c:player_loop Line | Count | Source | 67 | 10.4k | { | 68 | 10.4k | bool playing = false; | 69 | 10.4k | bool loaded = false; | 70 | 10.4k | int timeout = -1; | 71 | 10.4k | int events_limit_after_restart = EVENTS_LIMIT; | 72 | 140k | while (1) { | 73 | 140k | mpv_event *event = mpv_wait_event(ctx, timeout); | 74 | | // If some events are spamming, like audio-reconfig preventing our | 75 | | // timeout to trigger stop after N events. | 76 | 140k | if (timeout == PLAYBACK_TIME_LIMIT && events_limit_after_restart-- < 0) | 77 | 0 | break; | 78 | 140k | if (timeout == PLAYBACK_TIME_LIMIT && event->event_id == MPV_EVENT_NONE) | 79 | 13 | break; | 80 | 140k | if (event->event_id == MPV_EVENT_START_FILE) | 81 | 10.4k | loaded = playing = true; | 82 | 140k | if (event->event_id == MPV_EVENT_END_FILE) { | 83 | 10.4k | playing = false; | 84 | 10.4k | events_limit_after_restart = EVENTS_LIMIT; | 85 | 10.4k | timeout = -1; | 86 | 10.4k | } | 87 | 140k | if (playing && event->event_id == MPV_EVENT_PLAYBACK_RESTART) | 88 | 10.4k | timeout = PLAYBACK_TIME_LIMIT; | 89 | 140k | if (loaded && event->event_id == MPV_EVENT_IDLE) | 90 | 10.4k | break; | 91 | 140k | } | 92 | 10.4k | } |
|