diff --git a/src/PE/Parser.cpp b/src/PE/Parser.cpp index 5fd499cedc..82a555594b 100644 --- a/src/PE/Parser.cpp +++ b/src/PE/Parser.cpp @@ -430,6 +430,14 @@ Parser::parse_resource_node(const details::pe_resource_directory_table& director uint32_t offset = base_offset + data_rva; details::pe_resource_data_entry data_entry; + if (!resource_visited_.insert(offset).second) { + if (resource_visited_.size() == 1) { + // Only print once + LIEF_WARN("Infinite loop detected on resources"); + } + break; + } + if (auto res_data_entry = stream_->peek(offset)) { data_entry = *res_data_entry; } else { @@ -462,7 +470,10 @@ Parser::parse_resource_node(const details::pe_resource_directory_table& director const uint32_t directory_rva = data_rva & (~ 0x80000000); const uint32_t offset = base_offset + directory_rva; if (!resource_visited_.insert(offset).second) { - LIEF_WARN("Infinite loop detected on resources"); + if (resource_visited_.size() == 1) { + // Only print once + LIEF_WARN("Infinite loop detected on resources"); + } break; } diff --git a/tests/pe/test_parser.py b/tests/pe/test_parser.py index 291072fdb7..202345fe91 100644 --- a/tests/pe/test_parser.py +++ b/tests/pe/test_parser.py @@ -556,3 +556,11 @@ def test_issue_1049(): def test_xbox_file(): pe = lief.PE.parse(get_sample("PE/backcompat.exe")) assert pe.header.machine == lief.PE.Header.MACHINE_TYPES.POWERPCBE + +def test_issue_1115(): + """ + Infinite loop in PE resource tree + """ + pe = lief.PE.parse(get_sample("PE/issue_1115.pe")) + assert pe is not None +