Reject if MZ and PE headers overlap

Overlap ('leanify', etc.) causes headaches.
https://github.com/upx/upx/issues/231
	modified:   p_w32pe.cpp
	modified:   p_w64pep.cpp
	modified:   pefile.cpp
This commit is contained in:
John Reiser 2021-03-14 15:20:15 -07:00 committed by Markus F.X.J. Oberhumer
parent cbaedffce2
commit ba5c77c9e5
3 changed files with 14 additions and 4 deletions

View File

@ -276,9 +276,10 @@ void PackW32Pe::setOhDataBase(const pe_section_t *osection)
oh.database = osection[2].vaddr;
}
void PackW32Pe::setOhHeaderSize(const pe_section_t *)
void PackW32Pe::setOhHeaderSize(const pe_section_t *osection)
{
oh.headersize = rvamin; // FIXME
(void)osection;
oh.headersize = rvamin; // FIXME
}
void PackW32Pe::pack(OutputFile *fo)

View File

@ -266,9 +266,10 @@ void PackW64Pep::defineSymbols(unsigned ncsection, unsigned upxsection,
linker->defineSymbol("START", upxsection);
}
void PackW64Pep::setOhHeaderSize(const pe_section_t *)
void PackW64Pep::setOhHeaderSize(const pe_section_t *osection)
{
oh.headersize = rvamin; // FIXME
(void)osection;
oh.headersize = rvamin; // FIXME
}
void PackW64Pep::pack(OutputFile *fo)

View File

@ -163,6 +163,13 @@ int PeFile::readFileHeader()
if (h.mz == 'M' + 'Z'*256) // dos exe
{
if (h.nexepos && h.nexepos < sizeof(exe_header_t)) {
// Overlapping MZ and PE headers by 'leanify', etc.
char buf[64]; snprintf(buf, sizeof(buf),
"PE and MZ header overlap: %#x < %#x",
(unsigned)h.nexepos, (unsigned)sizeof(exe_header_t));
throwCantPack(buf);
}
unsigned const delta = (h.relocoffs >= 0x40)
? h.nexepos // new format exe
: (h.p512*512+h.m512 - h.m512 ? 512 : h.nexepos);
@ -3125,6 +3132,7 @@ void PeFile32::pack0(OutputFile *fo, unsigned subsystem_mask,
{
super::pack0<LE32>(fo, ih, oh, subsystem_mask,
default_imagebase, last_section_rsrc_only);
infoWarning("End of PeFile32::pack0");
}
void PeFile32::unpack(OutputFile *fo)