diff --git a/src/fileformat/utils/format_detection.cpp b/src/fileformat/utils/format_detection.cpp index a7674073b..e1558620c 100644 --- a/src/fileformat/utils/format_detection.cpp +++ b/src/fileformat/utils/format_detection.cpp @@ -127,10 +127,22 @@ bool isCoff(std::istream& stream, const std::string &header) std::error_code errorCode; COFFObjectFile coff(buffer.get()->getMemBufferRef(), errorCode); + if (errorCode) + { + return false; + } + PELIB_IMAGE_FILE_MACHINE_ITERATOR it; - return !errorCode - && it.isValidMachineCode( - static_cast(coff.getMachine())); + bool validMachineCode = it.isValidMachineCode( + static_cast(coff.getMachine())); + bool unknownMachineCode = + coff.getMachine() == PELIB_IMAGE_FILE_MACHINE::PELIB_IMAGE_FILE_MACHINE_UNKNOWN; + if (!validMachineCode + || (unknownMachineCode && coff.getNumberOfSections() == 0)) + { + return false; + } + return true; } /**