From bd8a8afeee17e30daed099eb95e1d448d88f9bb3 Mon Sep 17 00:00:00 2001 From: Victor Derks Date: Wed, 27 Dec 2023 16:35:45 +0100 Subject: [PATCH] Add support to fuzz with LibFuzzer Both MSVC and clang have support for fuzzing with LibFuzzer. Add a console app that can be used to fuzz with LibFuzzer. --- CMakeLists.txt | 23 ++++- CharLS.sln | 39 +++++--- benchmark/benchmark.vcxproj | 80 +--------------- .../afl/AflFuzzTest.vcxproj | 7 +- .../afl/AflFuzzTest.vcxproj.filters | 0 fuzzing/afl/CMakeLists.txt | 15 +++ {fuzztest => fuzzing/afl}/main.cpp | 2 +- fuzzing/libfuzzer/CMakeLists.txt | 16 ++++ fuzzing/libfuzzer/LibFuzzerTest.vcxproj | 96 +++++++++++++++++++ .../libfuzzer/LibFuzzerTest.vcxproj.filters | 22 +++++ fuzzing/libfuzzer/README.md | 17 ++++ fuzzing/libfuzzer/main.cpp | 22 +++++ fuzztest/CMakeLists.txt | 15 --- samples/convert.cpp/convert-cpp.vcxproj | 2 +- src/CMakeLists.txt | 5 + src/CharLS.vcxproj | 2 +- src/golomb_lut.h | 2 +- src/scan_decoder_impl.h | 4 +- src/scan_encoder_impl.h | 6 +- test/main.cpp | 7 ++ test/util.cpp | 7 ++ 21 files changed, 269 insertions(+), 120 deletions(-) rename fuzztest/FuzzTest.vcxproj => fuzzing/afl/AflFuzzTest.vcxproj (94%) rename fuzztest/FuzzTest.vcxproj.filters => fuzzing/afl/AflFuzzTest.vcxproj.filters (100%) create mode 100644 fuzzing/afl/CMakeLists.txt rename {fuzztest => fuzzing/afl}/main.cpp (97%) create mode 100644 fuzzing/libfuzzer/CMakeLists.txt create mode 100644 fuzzing/libfuzzer/LibFuzzerTest.vcxproj create mode 100644 fuzzing/libfuzzer/LibFuzzerTest.vcxproj.filters create mode 100644 fuzzing/libfuzzer/README.md create mode 100644 fuzzing/libfuzzer/main.cpp delete mode 100644 fuzztest/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 6805db2c..69229bf3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,13 +24,17 @@ endif () # The basic options to control what is build extra. option(CHARLS_BUILD_TESTS "Build test application" ${MASTER_PROJECT}) -option(CHARLS_BUILD_FUZZ_TEST "Build AFL fuzzer application" ${MASTER_PROJECT}) +option(CHARLS_BUILD_AFL_FUZZ_TEST "Build AFL test fuzzer application" ${MASTER_PROJECT}) +option(CHARLS_BUILD_LIBFUZZER_FUZZ_TEST "Build LibFuzzer test fuzzer application" ${MASTER_PROJECT}) option(CHARLS_BUILD_SAMPLES "Build sample applications" ${MASTER_PROJECT}) option(CHARLS_INSTALL "Generate the install target." ${MASTER_PROJECT}) # Provide BUILD_SHARED_LIBS as an option for GUI tools option(BUILD_SHARED_LIBS "Will control if charls lib is build as shared lib/DLL or static library") +# Provide option to build CharLS with address sanitizer +option(CHARLS_ENABLE_ASAN "Build with address sanitizer enabled." OFF) + # These options are used by the CI pipeline to ensure new warnings are detected quickly. # Not enabled by default to ensure the CharLS package is end-user friendly. option(CHARLS_PEDANTIC_WARNINGS "Enable extra warnings and static analysis." OFF) @@ -143,6 +147,10 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") if (NOT CMAKE_CXX_COMPILER_ID MATCHES "AppleClang") set(WARNINGS_AS_ERRORS_FLAG_LINKER LINKER:--fatal-warnings) endif() + + if(NOT APPLE) + set(LIBFUZZER_SUPPORTED 1) + endif() endif() if(MSVC) @@ -192,6 +200,11 @@ if(MSVC) add_link_options("/CETCOMPAT") endif() + # Enable LibFuzzer support for MSVC + if(${ARM_DETECTED} EQUAL 0 AND MSVC_VERSION GREATER_EQUAL 1930) + set(LIBFUZZER_SUPPORTED 1) + endif() + endif() # When enabled apply the pedantic warnings options and warnings as errors to globally. @@ -223,8 +236,12 @@ if(CHARLS_BUILD_TESTS) ) endif() -if(CHARLS_BUILD_FUZZ_TEST) - add_subdirectory(fuzztest) +if(CHARLS_BUILD_AFL_FUZZ_TEST) + add_subdirectory(fuzzing/afl) +endif() + +if(CHARLS_BUILD_LIBFUZZER_FUZZ_TEST AND LIBFUZZER_SUPPORTED) + add_subdirectory(fuzzing/libfuzzer) endif() if(CHARLS_BUILD_SAMPLES) diff --git a/CharLS.sln b/CharLS.sln index a6be4ba5..859fa5ca 100644 --- a/CharLS.sln +++ b/CharLS.sln @@ -31,10 +31,12 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CharLSUnitTest", "unittest\ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "convert-cpp", "samples\convert.cpp\convert-cpp.vcxproj", "{E09F024E-A125-48AA-8E9D-7D1302BEAC97}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FuzzTest", "fuzztest\FuzzTest.vcxproj", "{5637C116-ABF5-4274-A71F-34433713A538}" -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "benchmark", "benchmark\benchmark.vcxproj", "{F961EC29-4ACE-4D5E-B7ED-55681A678A90}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AflFuzzTest", "fuzzing\afl\AflFuzzTest.vcxproj", "{5637C116-ABF5-4274-A71F-34433713A538}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LibFuzzerTest", "fuzzing\libfuzzer\LibFuzzerTest.vcxproj", "{0F21D958-FE76-469A-8562-5D05F9EFE8D1}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Checked|ARM64 = Checked|ARM64 @@ -138,6 +140,15 @@ Global {E09F024E-A125-48AA-8E9D-7D1302BEAC97}.Release|x64.Build.0 = Release|x64 {E09F024E-A125-48AA-8E9D-7D1302BEAC97}.Release|x86.ActiveCfg = Release|Win32 {E09F024E-A125-48AA-8E9D-7D1302BEAC97}.Release|x86.Build.0 = Release|Win32 + {F961EC29-4ACE-4D5E-B7ED-55681A678A90}.Checked|ARM64.ActiveCfg = Checked|ARM64 + {F961EC29-4ACE-4D5E-B7ED-55681A678A90}.Checked|x64.ActiveCfg = Checked|x64 + {F961EC29-4ACE-4D5E-B7ED-55681A678A90}.Checked|x86.ActiveCfg = Checked|Win32 + {F961EC29-4ACE-4D5E-B7ED-55681A678A90}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {F961EC29-4ACE-4D5E-B7ED-55681A678A90}.Debug|x64.ActiveCfg = Debug|x64 + {F961EC29-4ACE-4D5E-B7ED-55681A678A90}.Debug|x86.ActiveCfg = Debug|Win32 + {F961EC29-4ACE-4D5E-B7ED-55681A678A90}.Release|ARM64.ActiveCfg = Release|ARM64 + {F961EC29-4ACE-4D5E-B7ED-55681A678A90}.Release|x64.ActiveCfg = Release|x64 + {F961EC29-4ACE-4D5E-B7ED-55681A678A90}.Release|x86.ActiveCfg = Release|Win32 {5637C116-ABF5-4274-A71F-34433713A538}.Checked|ARM64.ActiveCfg = Checked|ARM64 {5637C116-ABF5-4274-A71F-34433713A538}.Checked|ARM64.Build.0 = Checked|ARM64 {5637C116-ABF5-4274-A71F-34433713A538}.Checked|x64.ActiveCfg = Checked|x64 @@ -156,15 +167,21 @@ Global {5637C116-ABF5-4274-A71F-34433713A538}.Release|x64.Build.0 = Release|x64 {5637C116-ABF5-4274-A71F-34433713A538}.Release|x86.ActiveCfg = Release|Win32 {5637C116-ABF5-4274-A71F-34433713A538}.Release|x86.Build.0 = Release|Win32 - {F961EC29-4ACE-4D5E-B7ED-55681A678A90}.Checked|ARM64.ActiveCfg = Checked|ARM64 - {F961EC29-4ACE-4D5E-B7ED-55681A678A90}.Checked|x64.ActiveCfg = Checked|x64 - {F961EC29-4ACE-4D5E-B7ED-55681A678A90}.Checked|x86.ActiveCfg = Checked|Win32 - {F961EC29-4ACE-4D5E-B7ED-55681A678A90}.Debug|ARM64.ActiveCfg = Debug|ARM64 - {F961EC29-4ACE-4D5E-B7ED-55681A678A90}.Debug|x64.ActiveCfg = Debug|x64 - {F961EC29-4ACE-4D5E-B7ED-55681A678A90}.Debug|x86.ActiveCfg = Debug|Win32 - {F961EC29-4ACE-4D5E-B7ED-55681A678A90}.Release|ARM64.ActiveCfg = Release|ARM64 - {F961EC29-4ACE-4D5E-B7ED-55681A678A90}.Release|x64.ActiveCfg = Release|x64 - {F961EC29-4ACE-4D5E-B7ED-55681A678A90}.Release|x86.ActiveCfg = Release|Win32 + {0F21D958-FE76-469A-8562-5D05F9EFE8D1}.Checked|ARM64.ActiveCfg = Checked|x64 + {0F21D958-FE76-469A-8562-5D05F9EFE8D1}.Checked|x64.ActiveCfg = Checked|x64 + {0F21D958-FE76-469A-8562-5D05F9EFE8D1}.Checked|x64.Build.0 = Checked|x64 + {0F21D958-FE76-469A-8562-5D05F9EFE8D1}.Checked|x86.ActiveCfg = Checked|Win32 + {0F21D958-FE76-469A-8562-5D05F9EFE8D1}.Checked|x86.Build.0 = Checked|Win32 + {0F21D958-FE76-469A-8562-5D05F9EFE8D1}.Debug|ARM64.ActiveCfg = Debug|x64 + {0F21D958-FE76-469A-8562-5D05F9EFE8D1}.Debug|x64.ActiveCfg = Debug|x64 + {0F21D958-FE76-469A-8562-5D05F9EFE8D1}.Debug|x64.Build.0 = Debug|x64 + {0F21D958-FE76-469A-8562-5D05F9EFE8D1}.Debug|x86.ActiveCfg = Debug|Win32 + {0F21D958-FE76-469A-8562-5D05F9EFE8D1}.Debug|x86.Build.0 = Debug|Win32 + {0F21D958-FE76-469A-8562-5D05F9EFE8D1}.Release|ARM64.ActiveCfg = Release|x64 + {0F21D958-FE76-469A-8562-5D05F9EFE8D1}.Release|x64.ActiveCfg = Release|x64 + {0F21D958-FE76-469A-8562-5D05F9EFE8D1}.Release|x64.Build.0 = Release|x64 + {0F21D958-FE76-469A-8562-5D05F9EFE8D1}.Release|x86.ActiveCfg = Release|Win32 + {0F21D958-FE76-469A-8562-5D05F9EFE8D1}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/benchmark/benchmark.vcxproj b/benchmark/benchmark.vcxproj index 6bf2c4d3..43259225 100644 --- a/benchmark/benchmark.vcxproj +++ b/benchmark/benchmark.vcxproj @@ -39,7 +39,7 @@ - 16.0 + 17.0 Win32Proj {f961ec29-4ace-4d5e-b7ed-55681a678a90} benchmark @@ -54,34 +54,13 @@ $(DefaultPlatformToolset) - - true - - - true - - false true - - true - - - true - - - true - - - true - - false true - false true @@ -146,122 +125,65 @@ - true - _DEBUG;%(PreprocessorDefinitions) true true - - Console - true - - true - _DEBUG;%(PreprocessorDefinitions) true true - - Console - true - true true - true - NDEBUG;%(PreprocessorDefinitions) true true - - Console - true - true - true - - true - _DEBUG;%(PreprocessorDefinitions) true true - - Console - true - - true - _DEBUG;%(PreprocessorDefinitions) true true - - Console - true - - true - _DEBUG;%(PreprocessorDefinitions) true true - - Console - true - - true - _DEBUG;%(PreprocessorDefinitions) true true - - Console - true - true true - true - NDEBUG;%(PreprocessorDefinitions) true true - - Console - true - true - true - true true - true - NDEBUG;%(PreprocessorDefinitions) true true - Console - true true - true diff --git a/fuzztest/FuzzTest.vcxproj b/fuzzing/afl/AflFuzzTest.vcxproj similarity index 94% rename from fuzztest/FuzzTest.vcxproj rename to fuzzing/afl/AflFuzzTest.vcxproj index a0b5d097..65c2e571 100644 --- a/fuzztest/FuzzTest.vcxproj +++ b/fuzzing/afl/AflFuzzTest.vcxproj @@ -39,7 +39,7 @@ - 16.0 + 17.0 {5637C116-ABF5-4274-A71F-34433713A538} Win32Proj Application @@ -53,12 +53,13 @@ true - true + true + true true @@ -78,7 +79,7 @@ - + {1e31f9f1-f175-4082-b3e2-b1f0eca3f44c} diff --git a/fuzztest/FuzzTest.vcxproj.filters b/fuzzing/afl/AflFuzzTest.vcxproj.filters similarity index 100% rename from fuzztest/FuzzTest.vcxproj.filters rename to fuzzing/afl/AflFuzzTest.vcxproj.filters diff --git a/fuzzing/afl/CMakeLists.txt b/fuzzing/afl/CMakeLists.txt new file mode 100644 index 00000000..089c05e8 --- /dev/null +++ b/fuzzing/afl/CMakeLists.txt @@ -0,0 +1,15 @@ +# Copyright (c) Team CharLS. +# SPDX-License-Identifier: BSD-3-Clause + +add_executable(afl-fuzztest "") + +target_sources(afl-fuzztest PRIVATE main.cpp) + +set_target_properties(afl-fuzztest PROPERTIES CXX_VISIBILITY_PRESET hidden) + +target_link_libraries(afl-fuzztest PRIVATE charls) + +if(MSVC) + # AFL uses POSIX functions: disable warning about potential unsafe methods. + target_compile_definitions(afl-fuzztest PRIVATE _CRT_SECURE_NO_WARNINGS) +endif() diff --git a/fuzztest/main.cpp b/fuzzing/afl/main.cpp similarity index 97% rename from fuzztest/main.cpp rename to fuzzing/afl/main.cpp index d6383fff..f70cfab1 100644 --- a/fuzztest/main.cpp +++ b/fuzzing/afl/main.cpp @@ -113,7 +113,7 @@ int main(const int argc, const char* const argv[]) // NOLINT(bugprone-exception- vector destination; jpegls_decoder::decode(source, destination); } - catch (const jpegls_error&) + catch (const jpegls_error&) // NOLINT(bugprone-empty-catch) { } } diff --git a/fuzzing/libfuzzer/CMakeLists.txt b/fuzzing/libfuzzer/CMakeLists.txt new file mode 100644 index 00000000..97cff8d0 --- /dev/null +++ b/fuzzing/libfuzzer/CMakeLists.txt @@ -0,0 +1,16 @@ +# Copyright (c) Team CharLS. +# SPDX-License-Identifier: BSD-3-Clause + +add_executable(libfuzzer-fuzztest "") + +target_sources(libfuzzer-fuzztest PRIVATE main.cpp) + +set_target_properties(libfuzzer-fuzztest PROPERTIES CXX_VISIBILITY_PRESET hidden) + +target_link_libraries(libfuzzer-fuzztest PRIVATE charls) + +target_compile_options(libfuzzer-fuzztest PRIVATE "-fsanitize=fuzzer,address") + +if(NOT MSVC) + target_link_options(libfuzzer-fuzztest PRIVATE "-fsanitize=fuzzer,address") +endif() diff --git a/fuzzing/libfuzzer/LibFuzzerTest.vcxproj b/fuzzing/libfuzzer/LibFuzzerTest.vcxproj new file mode 100644 index 00000000..027ede57 --- /dev/null +++ b/fuzzing/libfuzzer/LibFuzzerTest.vcxproj @@ -0,0 +1,96 @@ + + + + + Checked + Win32 + + + Checked + x64 + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {0f21d958-fe76-469a-8562-5d05f9efe8d1} + LibFuzzerTest + Application + true + true + + + + $(DefaultPlatformToolset) + + + true + + + true + + + + + + + + + + + + + + + + + + + + + + + + Console + + + + + true + true + + + + + true + true + + + + + + + + {1e31f9f1-f175-4082-b3e2-b1f0eca3f44c} + + + + + + \ No newline at end of file diff --git a/fuzzing/libfuzzer/LibFuzzerTest.vcxproj.filters b/fuzzing/libfuzzer/LibFuzzerTest.vcxproj.filters new file mode 100644 index 00000000..ce0c35cc --- /dev/null +++ b/fuzzing/libfuzzer/LibFuzzerTest.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + \ No newline at end of file diff --git a/fuzzing/libfuzzer/README.md b/fuzzing/libfuzzer/README.md new file mode 100644 index 00000000..ad25b515 --- /dev/null +++ b/fuzzing/libfuzzer/README.md @@ -0,0 +1,17 @@ +# Instructions to fuzz CharLS with LibFuzzer + +- It is recommended to fuzz the release build. The release build runs faster and more fuzzing can be done in a time period. + +## Windows (MSbuild projects) + +- Update the release configuration of the CharLS MSbuild project and enable address sanitizer. +- build the solution with Visual Studio 2022 17.8 or newer. +- Run the LibFuzzerTest from the command line (-help=1) will show the options. + +## Linux\Windows (CMake) + +Remark: Using LibFuzzer requires Clang or Visual Studio 2022 + +- Enable the address sanitizer CMake option (CHARLS_ENABLE_ASAN) +- Build the targets (RelWithDebInfo) +- Run the LibFuzzerTest from the command line (-help=1) will show the options. diff --git a/fuzzing/libfuzzer/main.cpp b/fuzzing/libfuzzer/main.cpp new file mode 100644 index 00000000..985ab967 --- /dev/null +++ b/fuzzing/libfuzzer/main.cpp @@ -0,0 +1,22 @@ +// Copyright (c) Team CharLS. +// SPDX-License-Identifier: BSD-3-Clause + +#include +#include "../include/charls/charls_jpegls_decoder.h" + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, const size_t size) +{ + std::vector destination(100000); + charls::jpegls_decoder decoder(data, size, false); + + try + { + decoder.read_header(); + decoder.decode(destination); + } + catch (const charls::jpegls_error&) // NOLINT(bugprone-empty-catch) + { + } + + return 0; +} diff --git a/fuzztest/CMakeLists.txt b/fuzztest/CMakeLists.txt deleted file mode 100644 index 118593ae..00000000 --- a/fuzztest/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -# Copyright (c) Team CharLS. -# SPDX-License-Identifier: BSD-3-Clause - -add_executable(fuzztest "") - -target_sources(fuzztest PRIVATE main.cpp) - -set_target_properties(fuzztest PROPERTIES CXX_VISIBILITY_PRESET hidden) - -target_link_libraries(fuzztest PRIVATE charls) - -if(MSVC) - # POSIX functions are used, required for AFL. - target_compile_definitions(fuzztest PRIVATE _CRT_SECURE_NO_WARNINGS) -endif() diff --git a/samples/convert.cpp/convert-cpp.vcxproj b/samples/convert.cpp/convert-cpp.vcxproj index f3fd2b32..c6ada3c4 100644 --- a/samples/convert.cpp/convert-cpp.vcxproj +++ b/samples/convert.cpp/convert-cpp.vcxproj @@ -39,7 +39,7 @@ - 16.0 + 17.0 {E09F024E-A125-48AA-8E9D-7D1302BEAC97} Win32Proj Application diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index db6a1067..3f6e2b60 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -55,6 +55,11 @@ if(MSVC) target_compile_options(charls PRIVATE /GR-) endif() +if(CHARLS_ENABLE_ASAN) + target_compile_options(charls PRIVATE -fsanitize=address) + target_link_libraries(charls PRIVATE -fsanitize=address) +endif() + set_target_properties(charls PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR}) diff --git a/src/CharLS.vcxproj b/src/CharLS.vcxproj index bc52c2c1..3936ad93 100644 --- a/src/CharLS.vcxproj +++ b/src/CharLS.vcxproj @@ -39,7 +39,7 @@ - 16.0 + 17.0 {1E31F9F1-F175-4082-B3E2-B1F0ECA3F44C} Win32Proj CharLS diff --git a/src/golomb_lut.h b/src/golomb_lut.h index 3798c6c3..8a26fdd6 100644 --- a/src/golomb_lut.h +++ b/src/golomb_lut.h @@ -20,7 +20,7 @@ struct golomb_code final } [[nodiscard]] - int32_t value() const noexcept + constexpr int32_t value() const noexcept { return value_; } diff --git a/src/scan_decoder_impl.h b/src/scan_decoder_impl.h index de83e8c7..bb417b0d 100644 --- a/src/scan_decoder_impl.h +++ b/src/scan_decoder_impl.h @@ -66,11 +66,11 @@ class scan_decoder_impl final : public scan_decoder if (!is_interleaved()) { return std::make_unique(destination, stride, - sizeof(typename Traits::pixel_type)); + sizeof(pixel_type)); } if (parameters().transformation == color_transformation::none) - return std::make_unique>>( + return std::make_unique>>( destination, stride, frame_info(), parameters(), transform_none()); if (frame_info().bits_per_sample == sizeof(sample_type) * 8 && frame_info().component_count == 3) diff --git a/src/scan_encoder_impl.h b/src/scan_encoder_impl.h index e429a0ec..8e37a0c3 100644 --- a/src/scan_encoder_impl.h +++ b/src/scan_encoder_impl.h @@ -61,15 +61,15 @@ class scan_encoder_impl final : public scan_encoder if (frame_info().bits_per_sample == sizeof(sample_type) * 8) { return std::make_unique(source, stride, - sizeof(typename Traits::pixel_type)); + sizeof(pixel_type)); } return std::make_unique( - source, stride, sizeof(typename Traits::pixel_type), frame_info().bits_per_sample); + source, stride, sizeof(pixel_type), frame_info().bits_per_sample); } if (parameters().transformation == color_transformation::none) - return std::make_unique>>( + return std::make_unique>>( source, stride, frame_info(), parameters(), transform_none()); if (frame_info().bits_per_sample == sizeof(sample_type) * 8 && frame_info().component_count == 3) diff --git a/test/main.cpp b/test/main.cpp index d565f3e2..d07b0957 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -13,6 +13,7 @@ #include #include +#include #include #include #include @@ -45,6 +46,7 @@ namespace { constexpr ios::openmode mode_input{ios::in | ios::binary}; ifstream open_input_stream(const char* filename) +try { ifstream stream; stream.exceptions(ios::eofbit | ios::failbit | ios::badbit); @@ -52,6 +54,11 @@ ifstream open_input_stream(const char* filename) return stream; } +catch (const std::ifstream::failure&) +{ + cout << "Failed to open/read file: " << std::filesystem::absolute(filename) << "\n"; + throw; +} uint32_t log2_floor(const uint32_t n) noexcept diff --git a/test/util.cpp b/test/util.cpp index 068866b8..4170c710 100644 --- a/test/util.cpp +++ b/test/util.cpp @@ -6,6 +6,7 @@ #include "portable_anymap_file.h" #include +#include #include #include #include @@ -67,6 +68,7 @@ void fix_endian(vector* buffer, const bool little_endian_data) noexcept vector read_file(const char* filename, long offset, size_t bytes) +try { ifstream input; input.exceptions(ios::eofbit | ios::failbit | ios::badbit); @@ -91,6 +93,11 @@ vector read_file(const char* filename, long offset, size_t bytes) return buffer; } +catch (const std::ifstream::failure&) +{ + cout << "Failed to open/read file: " << std::filesystem::absolute(filename) << "\n"; + throw; +} void write_file(const char* filename, const void* data, const size_t size) {