From 295ab5c4460b4a2d083227f2ba8f078c044a5475 Mon Sep 17 00:00:00 2001 From: John Parent Date: Fri, 29 May 2026 11:31:06 -0400 Subject: [PATCH] Winrpath: finddllandrename handle importless dlls Also adds error handling for corrupted PEs where there is no import section file offset Signed-off-by: John Parent --- src/winrpath.cxx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/winrpath.cxx b/src/winrpath.cxx index 5cbb945..7953501 100644 --- a/src/winrpath.cxx +++ b/src/winrpath.cxx @@ -168,9 +168,22 @@ bool LibRename::FindDllAndRename(HANDLE& pe_in) { return false; } + if (rva_import_directory == 0) { + // No import table is valid (e.g. python3.dll which only forwards exports). + FlushViewOfFile((LPCVOID)basepointer, 0); + UnmapViewOfFile((LPCVOID)basepointer); + return SafeHandleCleanup(h_map_object) != 0; + } + DWORD const number_of_sections = coff_header->NumberOfSections; DWORD const import_section_file_offset = RvaToFileOffset( section_header, number_of_sections, rva_import_directory); + if (import_section_file_offset == 0) { + std::cerr << "Import table RVA 0x" << std::hex << rva_import_directory + << " could not be resolved to a file offset.\n"; + UnmapViewOfFile((LPCVOID)basepointer); + return false; + } char* import_table_offset = static_cast(basepointer) + import_section_file_offset; auto* import_image_descriptor =