| @@ -0,0 +1,65 @@ |
| 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 <stdio.h> |
| 19 | +#include <stdlib.h> |
| 20 | +#include <string.h> |
| 21 | + |
| 22 | +#include <unistd.h> |
| 23 | + |
| 24 | +#include <libmpv/client.h> |
| 25 | + |
| 26 | +#include "common.h" |
| 27 | + |
| 28 | +int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) |
| 29 | +{ |
| 30 | + if (size == 0) |
| 31 | + return -1; |
| 32 | + |
| 33 | + char filename[15 + 10 + 1]; |
| 34 | + sprintf(filename, "/tmp/libfuzzer.%d", getpid()); |
| 35 | + |
| 36 | + FILE *fp = fopen(filename, "wb"); |
| 37 | + if (!fp) |
| 38 | + exit(1); |
| 39 | + |
| 40 | + if (fwrite(data, size, 1, fp) != 1) |
| 41 | + exit(1); |
| 42 | + |
| 43 | + if (fclose(fp)) |
| 44 | + exit(1); |
| 45 | + |
| 46 | + mpv_handle *ctx = mpv_create(); |
| 47 | + if (!ctx) |
| 48 | + exit(1); |
| 49 | + |
| 50 | + check_error(mpv_set_option_string(ctx, "vo", "null")); |
| 51 | + check_error(mpv_set_option_string(ctx, "ao", "null")); |
| 52 | + check_error(mpv_set_option_string(ctx, "ao-null-untimed", "yes")); |
| 53 | + check_error(mpv_set_option_string(ctx, "untimed", "yes")); |
| 54 | + check_error(mpv_set_option_string(ctx, "video-osd", "no")); |
| 55 | + check_error(mpv_set_option_string(ctx, "msg-level", "all=trace")); |
| 56 | + |
| 57 | + check_error(mpv_initialize(ctx)); |
| 58 | + |
| 59 | + const char *cmd[] = {"load-" MPV_LOAD, filename, NULL}; |
| 60 | + check_error(mpv_command(ctx, cmd)); |
| 61 | + |
| 62 | + mpv_terminate_destroy(ctx); |
| 63 | + |
| 64 | + return 0; |
| 65 | +} |