diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 005c65d..33e02d6 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -23,6 +23,7 @@ add_executable(tests test_main.cpp simple_test.cpp corkami_test.cpp + pr_153_test.cpp filesystem_compat.h ) diff --git a/tests/assets/pr_153.exe b/tests/assets/pr_153.exe new file mode 100644 index 0000000..fec5dd9 Binary files /dev/null and b/tests/assets/pr_153.exe differ diff --git a/tests/pr_153_test.cpp b/tests/pr_153_test.cpp new file mode 100644 index 0000000..55be4ad --- /dev/null +++ b/tests/pr_153_test.cpp @@ -0,0 +1,17 @@ +#include <pe-parse/parse.h> + +#include <catch2/catch.hpp> + +#include "filesystem_compat.h" + +namespace peparse { +TEST_CASE("malformed PE (GH#153) does not parse", "[pr_153]") { + auto path = fs::path(ASSETS_DIR) / "pr_153.exe"; + auto *p = ParsePEFromFile(path.string().c_str()); + + // pr_153.exe should not parse, and should return an error indicating + // that the magic was invalid (masking the underlying PEERR_ADDRESS error). + REQUIRE(p == nullptr); + REQUIRE(GetPEErr() == PEERR_MAGIC); +} +} // namespace peparse