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:
committed by
Markus F.X.J. Oberhumer
parent
cbaedffce2
commit
ba5c77c9e5
+2
-1
@@ -276,8 +276,9 @@ void PackW32Pe::setOhDataBase(const pe_section_t *osection)
|
|||||||
oh.database = osection[2].vaddr;
|
oh.database = osection[2].vaddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PackW32Pe::setOhHeaderSize(const pe_section_t *)
|
void PackW32Pe::setOhHeaderSize(const pe_section_t *osection)
|
||||||
{
|
{
|
||||||
|
(void)osection;
|
||||||
oh.headersize = rvamin; // FIXME
|
oh.headersize = rvamin; // FIXME
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -266,8 +266,9 @@ void PackW64Pep::defineSymbols(unsigned ncsection, unsigned upxsection,
|
|||||||
linker->defineSymbol("START", upxsection);
|
linker->defineSymbol("START", upxsection);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PackW64Pep::setOhHeaderSize(const pe_section_t *)
|
void PackW64Pep::setOhHeaderSize(const pe_section_t *osection)
|
||||||
{
|
{
|
||||||
|
(void)osection;
|
||||||
oh.headersize = rvamin; // FIXME
|
oh.headersize = rvamin; // FIXME
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -163,6 +163,13 @@ int PeFile::readFileHeader()
|
|||||||
|
|
||||||
if (h.mz == 'M' + 'Z'*256) // dos exe
|
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)
|
unsigned const delta = (h.relocoffs >= 0x40)
|
||||||
? h.nexepos // new format exe
|
? h.nexepos // new format exe
|
||||||
: (h.p512*512+h.m512 - h.m512 ? 512 : h.nexepos);
|
: (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,
|
super::pack0<LE32>(fo, ih, oh, subsystem_mask,
|
||||||
default_imagebase, last_section_rsrc_only);
|
default_imagebase, last_section_rsrc_only);
|
||||||
|
infoWarning("End of PeFile32::pack0");
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeFile32::unpack(OutputFile *fo)
|
void PeFile32::unpack(OutputFile *fo)
|
||||||
|
|||||||
Reference in New Issue
Block a user