summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKacper Michajłow <kasper93@gmail.com>2024-05-09 01:14:01 +0200
committerKacper Michajłow <kasper93@gmail.com>2024-05-09 02:01:24 +0200
commitbf6d49cbd44871fec6795c4eb334e7ed4035f171 (patch)
tree58cc74510c005a9efe2c4a30042adc0047d90471
parentd6803c45183b18637e603eb1997c4ffbcc434616 (diff)
downloadmpv-bf6d49cbd44871fec6795c4eb334e7ed4035f171.tar.bz2
mpv-bf6d49cbd44871fec6795c4eb334e7ed4035f171.tar.xz
fuzzer_loadfile_direct: exclude paths also for file://
Loading external files makes little sense. Might disable this completely later, but let see how it works, The idea is the same as for direct load. Exclude paths starting with `file://.` and `file:///`. But still fuzz any processing that other input might have. It shouldn't be a huge problem if we do `file://mpv` for example. Not great, but also not terrible.
-rw-r--r--fuzzers/fuzzer_loadfile_direct.c19
-rw-r--r--fuzzers/meson.build2
2 files changed, 15 insertions, 6 deletions
diff --git a/fuzzers/fuzzer_loadfile_direct.c b/fuzzers/fuzzer_loadfile_direct.c
index f6578f9f98..a8f9b6b937 100644
--- a/fuzzers/fuzzer_loadfile_direct.c
+++ b/fuzzers/fuzzer_loadfile_direct.c
@@ -34,18 +34,27 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
return -1;
#ifdef MPV_PROTO
- if (!str_startswith(data, size - 1, MPV_STRINGIFY(MPV_PROTO) "://", strlen(MPV_STRINGIFY(MPV_PROTO) "://")))
+ if (!str_startswith(data, size - 1, MPV_STRINGIFY(MPV_PROTO) "://", sizeof(MPV_STRINGIFY(MPV_PROTO) "://") - 1))
return -1;
-#else
+#endif
+
+#if !defined(MPV_PROTO) || defined(MPV_PROTO_FILE)
+ const uint8_t *data_check = data;
+ size_t size_check = size;
+ size_t prefix_size = sizeof("file://") - 1;
+ if (str_startswith(data, size - 1, "file://", prefix_size)) {
+ data_check += prefix_size;
+ size_check -= prefix_size;
+ }
// Exclude some common paths that are not useful for testing.
// Exclude -
- if (size == 2 && !strncmp(data, "-", 1))
+ if (size_check == 2 && !strncmp(data_check, "-", 1))
return -1;
// Exclude relative paths
- if (str_startswith(data, size - 1, ".", 1))
+ if (str_startswith(data_check, size_check - 1, ".", 1))
return -1;
// Exclude absolute paths
- if (str_startswith(data, size - 1, "/", 1))
+ if (str_startswith(data_check, size_check - 1, "/", 1))
return -1;
#endif
diff --git a/fuzzers/meson.build b/fuzzers/meson.build
index 2083416090..0b514b62ae 100644
--- a/fuzzers/meson.build
+++ b/fuzzers/meson.build
@@ -9,7 +9,7 @@ foreach p : ['bd', 'cdda', 'dvb', 'dvd', 'edl', 'file', 'hex', 'lavf', 'memory',
'mf', 'slice', 'smb']
executable('fuzzer_protocol_' + p,
'fuzzer_loadfile_direct.c',
- c_args: ['-DMPV_PROTO=' + p],
+ c_args: ['-DMPV_PROTO=' + p, '-DMPV_PROTO_' + p.to_upper()],
include_directories: incdir,
link_with: libmpv)
endforeach