diff options
Diffstat (limited to 'tests/fuzzer')
-rw-r--r-- | tests/fuzzer/fuzzer_temp_file.h | 45 | ||||
-rw-r--r-- | tests/fuzzer/obu_parser_fuzzer.cc | 5 |
2 files changed, 48 insertions, 2 deletions
diff --git a/tests/fuzzer/fuzzer_temp_file.h b/tests/fuzzer/fuzzer_temp_file.h index 5d12bbe..ed8f51c 100644 --- a/tests/fuzzer/fuzzer_temp_file.h +++ b/tests/fuzzer/fuzzer_temp_file.h @@ -25,12 +25,52 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#ifdef _WIN32 +#include <io.h> +#include <windows.h> + +#define strdup _strdup +#define unlink _unlink +#else #include <unistd.h> +#endif // _WIN32 // Pure-C interface for creating and cleaning up temporary files. static char* fuzzer_get_tmpfile_with_suffix(const uint8_t* data, size_t size, const char* suffix) { +#ifdef _WIN32 + // GetTempPathA generates '<path>\<pre><uuuu>.TMP'. + (void)suffix; // NOLINT (this could be a C compilation unit) + char temp_path[MAX_PATH]; + const DWORD ret = GetTempPathA(MAX_PATH, temp_path); + if (ret == 0 || ret > MAX_PATH) { + fprintf(stderr, "Error getting temporary directory name: %lu\n", + GetLastError()); + abort(); + } + char* filename_buffer = + (char*)malloc(MAX_PATH); // NOLINT (this could be a C compilation unit) + if (!filename_buffer) { + perror("Failed to allocate file name buffer."); + abort(); + } + if (GetTempFileNameA(temp_path, "ftf", /*uUnique=*/0, filename_buffer) == 0) { + fprintf(stderr, "Error getting temporary file name: %lu\n", GetLastError()); + abort(); + } +#if defined(_MSC_VER) || defined(MINGW_HAS_SECURE_API) + FILE* file; + const errno_t err = fopen_s(&file, filename_buffer, "wb"); + if (err != 0) file = NULL; // NOLINT (this could be a C compilation unit) +#else + FILE* file = fopen(filename_buffer, "wb"); +#endif + if (!file) { + perror("Failed to open file."); + abort(); + } +#else // !_WIN32 if (suffix == NULL) { // NOLINT (this could be a C compilation unit) suffix = ""; } @@ -55,7 +95,7 @@ static char* fuzzer_get_tmpfile_with_suffix(const uint8_t* data, size_t size, } if (snprintf(filename_buffer, buffer_sz, "%s%s", leading_temp_path, suffix) >= - buffer_sz) { + (int)buffer_sz) { // NOLINT (this could be a C compilation unit) perror("File name buffer too short."); abort(); } @@ -71,9 +111,10 @@ static char* fuzzer_get_tmpfile_with_suffix(const uint8_t* data, size_t size, close(file_descriptor); abort(); } +#endif // _WIN32 const size_t bytes_written = fwrite(data, sizeof(uint8_t), size, file); if (bytes_written < size) { - close(file_descriptor); + fclose(file); fprintf(stderr, "Failed to write all bytes to file (%zu out of %zu)", bytes_written, size); abort(); diff --git a/tests/fuzzer/obu_parser_fuzzer.cc b/tests/fuzzer/obu_parser_fuzzer.cc index 634a802..f71ca17 100644 --- a/tests/fuzzer/obu_parser_fuzzer.cc +++ b/tests/fuzzer/obu_parser_fuzzer.cc @@ -41,6 +41,11 @@ constexpr size_t kMaxDataSize = 200 * 1024; #endif inline void ParseObu(const uint8_t* const data, size_t size) { + size_t av1c_size; + const std::unique_ptr<uint8_t[]> av1c_box = + libgav1::ObuParser::GetAV1CodecConfigurationBox(data, size, &av1c_size); + static_cast<void>(av1c_box); + libgav1::InternalFrameBufferList buffer_list; libgav1::BufferPool buffer_pool(libgav1::OnInternalFrameBufferSizeChanged, libgav1::GetInternalFrameBuffer, |