2024-05-08 15:07:48 +00:00
|
|
|
/*
|
|
|
|
* This file is part of mpv.
|
|
|
|
*
|
|
|
|
* mpv is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* mpv is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2024-06-24 20:26:53 +00:00
|
|
|
#include <fcntl.h>
|
2024-05-15 15:52:38 +00:00
|
|
|
#include <sys/mman.h>
|
2024-05-08 15:07:48 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <libmpv/client.h>
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
|
|
|
|
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
|
|
|
{
|
2024-06-23 20:34:38 +00:00
|
|
|
#ifdef MPV_LOAD_CONFIG_FILE
|
|
|
|
// config file size limit, see m_config_parse_config_file()
|
|
|
|
if (size > 1000000000)
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef MPV_LOAD_INPUT_CONF
|
|
|
|
// input config file size limit, see parse_config_file() in input.c
|
|
|
|
if (size > 1000000)
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
|
2024-05-15 15:52:38 +00:00
|
|
|
// fmemopen doesn't have associated file descriptor, so we do copy.
|
2024-06-24 20:26:53 +00:00
|
|
|
int fd = memfd_create("fuzz_mpv_load", MFD_CLOEXEC | MFD_ALLOW_SEALING);
|
2024-05-15 15:52:38 +00:00
|
|
|
if (fd == -1)
|
2024-05-08 15:07:48 +00:00
|
|
|
exit(1);
|
2024-05-15 15:52:38 +00:00
|
|
|
ssize_t written = 0;
|
|
|
|
while (written < size) {
|
|
|
|
ssize_t result = write(fd, data + written, size - written);
|
|
|
|
if (result == -1)
|
|
|
|
exit(1);
|
|
|
|
written += result;
|
|
|
|
}
|
2024-06-24 20:26:53 +00:00
|
|
|
if (fcntl(fd, F_ADD_SEALS, F_SEAL_WRITE | F_SEAL_SHRINK | F_SEAL_GROW | F_SEAL_SEAL) != 0)
|
|
|
|
exit(1);
|
2024-05-15 15:52:38 +00:00
|
|
|
if (lseek(fd, 0, SEEK_SET) != 0)
|
2024-05-08 15:07:48 +00:00
|
|
|
exit(1);
|
2024-05-15 15:52:38 +00:00
|
|
|
char filename[5 + 10 + 1];
|
|
|
|
if (sprintf(filename, "fd://%d", fd) <= 5)
|
2024-05-08 15:07:48 +00:00
|
|
|
exit(1);
|
|
|
|
|
|
|
|
mpv_handle *ctx = mpv_create();
|
|
|
|
if (!ctx)
|
|
|
|
exit(1);
|
|
|
|
|
|
|
|
check_error(mpv_set_option_string(ctx, "vo", "null"));
|
|
|
|
check_error(mpv_set_option_string(ctx, "ao", "null"));
|
|
|
|
check_error(mpv_set_option_string(ctx, "ao-null-untimed", "yes"));
|
|
|
|
check_error(mpv_set_option_string(ctx, "untimed", "yes"));
|
|
|
|
check_error(mpv_set_option_string(ctx, "video-osd", "no"));
|
|
|
|
check_error(mpv_set_option_string(ctx, "msg-level", "all=trace"));
|
2024-05-10 01:41:21 +00:00
|
|
|
check_error(mpv_set_option_string(ctx, "network-timeout", "1"));
|
2024-05-15 16:21:54 +00:00
|
|
|
#ifdef MPV_DEMUXER
|
|
|
|
check_error(mpv_set_option_string(ctx, "demuxer", MPV_DEMUXER));
|
|
|
|
#endif
|
2024-05-08 15:07:48 +00:00
|
|
|
|
|
|
|
check_error(mpv_initialize(ctx));
|
|
|
|
|
2024-05-15 15:44:08 +00:00
|
|
|
const char *cmd[] = {"load" MPV_LOAD, filename, NULL};
|
2024-05-08 15:07:48 +00:00
|
|
|
check_error(mpv_command(ctx, cmd));
|
|
|
|
|
2024-05-15 15:44:08 +00:00
|
|
|
#ifdef MPV_LOADFILE
|
2024-06-26 21:12:42 +00:00
|
|
|
bool loaded = false;
|
2024-05-15 15:44:08 +00:00
|
|
|
while (1) {
|
2024-06-26 21:12:42 +00:00
|
|
|
mpv_event *event = mpv_wait_event(ctx, -1);
|
|
|
|
if (event->event_id == MPV_EVENT_START_FILE)
|
|
|
|
loaded = true;
|
|
|
|
if (loaded && event->event_id == MPV_EVENT_IDLE)
|
2024-05-15 15:44:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2024-05-08 15:07:48 +00:00
|
|
|
mpv_terminate_destroy(ctx);
|
2024-05-15 15:52:38 +00:00
|
|
|
close(fd);
|
2024-05-08 15:07:48 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|