From 58b254a863f5c46653a310b07c411c9295010c49 Mon Sep 17 00:00:00 2001 From: William Woodruff Date: Thu, 29 Apr 2021 12:54:27 -0400 Subject: [PATCH] tests: add the testcase from #153 (#154) * tests: add a testcase for #153 * tests: rename testcase, hook up * tests: fix REQUIRE check --- tests/CMakeLists.txt | 1 + tests/assets/pr_153.exe | Bin 0 -> 252 bytes tests/pr_153_test.cpp | 17 +++++++++++++++++ 3 files changed, 18 insertions(+) create mode 100644 tests/assets/pr_153.exe create mode 100644 tests/pr_153_test.cpp 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 0000000000000000000000000000000000000000..fec5dd96aa094ae497780887365857f725191b9d GIT binary patch literal 252 zcmeZ`VqgexWnl1OWMIf*j5zck2pAX|7#J9s>%W1N{-69g!1aFvi%05z z3kC+Ayzc+%|L-4$1F)H3b^q%{8va~|>Tvnr@YUV<@MEC56Nmc_A7-crvKSfUKL?=7 L0DT9Q0U8bf(*$Qd literal 0 HcmV?d00001 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 + +#include + +#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