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.
Unified · Split
| @@ -34,18 +34,27 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) · 33 unmodified lines | ||
| 34 | 34 | return -1; |
| 35 | 35 | |
| 36 | 36 | #ifdef MPV_PROTO |
| 37 | − if (!str_startswith(data, size - 1, MPV_STRINGIFY(MPV_PROTO) "://", strlen(MPV_STRINGIFY(MPV_PROTO) "://"))) | |
| 37 | + if (!str_startswith(data, size - 1, MPV_STRINGIFY(MPV_PROTO) "://", sizeof(MPV_STRINGIFY(MPV_PROTO) "://") - 1)) | |
| 38 | 38 | return -1; |
| 39 | −#else | |
| 39 | +#endif | |
| 40 | + | |
| 41 | +#if !defined(MPV_PROTO) || defined(MPV_PROTO_FILE) | |
| 42 | + const uint8_t *data_check = data; | |
| 43 | + size_t size_check = size; | |
| 44 | + size_t prefix_size = sizeof("file://") - 1; | |
| 45 | + if (str_startswith(data, size - 1, "file://", prefix_size)) { | |
| 46 | + data_check += prefix_size; | |
| 47 | + size_check -= prefix_size; | |
| 48 | + } | |
| 40 | 49 | // Exclude some common paths that are not useful for testing. |
| 41 | 50 | // Exclude - |
| 42 | − if (size == 2 && !strncmp(data, "-", 1)) | |
| 51 | + if (size_check == 2 && !strncmp(data_check, "-", 1)) | |
| 43 | 52 | return -1; |
| 44 | 53 | // Exclude relative paths |
| 45 | − if (str_startswith(data, size - 1, ".", 1)) | |
| 54 | + if (str_startswith(data_check, size_check - 1, ".", 1)) | |
| 46 | 55 | return -1; |
| 47 | 56 | // Exclude absolute paths |
| 48 | − if (str_startswith(data, size - 1, "/", 1)) | |
| 57 | + if (str_startswith(data_check, size_check - 1, "/", 1)) | |
| 49 | 58 | return -1; |
| 50 | 59 | #endif |
| 51 | 60 | |
| @@ -9,7 +9,7 @@ foreach p : ['bd', 'cdda', 'dvb', 'dvd', 'edl', 'file', 'hex', 'lavf', 'memory', · 8 unmodified lines | ||
| 9 | 9 | 'mf', 'slice', 'smb'] |
| 10 | 10 | executable('fuzzer_protocol_' + p, |
| 11 | 11 | 'fuzzer_loadfile_direct.c', |
| 12 | − c_args: ['-DMPV_PROTO=' + p], | |
| 12 | + c_args: ['-DMPV_PROTO=' + p, '-DMPV_PROTO_' + p.to_upper()], | |
| 13 | 13 | include_directories: incdir, |
| 14 | 14 | link_with: libmpv) |
| 15 | 15 | endforeach |