Skip to content

Commit

Permalink
fileformat/format_detection: make COFF format detection more strict.
Browse files Browse the repository at this point in the history
fix #421
  • Loading branch information
PeterMatula committed Mar 4, 2019
1 parent a95fd46 commit a5fa960
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/fileformat/utils/format_detection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<PELIB_IMAGE_FILE_MACHINE>(coff.getMachine()));
bool validMachineCode = it.isValidMachineCode(
static_cast<PELIB_IMAGE_FILE_MACHINE>(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;
}

/**
Expand Down

0 comments on commit a5fa960

Please sign in to comment.