1
0
mirror of https://github.com/upx/upx synced 2025-09-28 19:06:07 +08:00

MS-DOS .exe (not PE): default to file_size when ih.m512 and ih.p512 are zero

https://github.com/upx/upx/issues/169
	modified:   p_exe.cpp
This commit is contained in:
John Reiser 2018-01-18 12:00:38 -08:00
parent ab35b685d4
commit 8ab180edf8

View File

@ -281,9 +281,13 @@ int PackExe::readFileHeader()
if (ih.ident != 'M' + 'Z'*256 && ih.ident != 'Z' + 'M'*256) if (ih.ident != 'M' + 'Z'*256 && ih.ident != 'Z' + 'M'*256)
return 0; return 0;
ih_exesize = ih.m512 + ih.p512*512 - (ih.m512 ? 512 : 0); ih_exesize = ih.m512 + ih.p512*512 - (ih.m512 ? 512 : 0);
if (!ih_exesize) {
ih_exesize = file_size;
}
ih_imagesize = ih_exesize - ih.headsize16*16; ih_imagesize = ih_exesize - ih.headsize16*16;
ih_overlay = file_size - ih_exesize; ih_overlay = file_size - ih_exesize;
if (ih.m512+ih.p512*512u < sizeof (ih)) if (file_size < (int)sizeof(ih)
|| ((ih.m512 | ih.p512) && ih.m512+ih.p512*512u < sizeof (ih)))
throwCantPack("illegal exe header"); throwCantPack("illegal exe header");
if (file_size < (off_t)ih_exesize || ih_imagesize <= 0 || ih_imagesize > ih_exesize) if (file_size < (off_t)ih_exesize || ih_imagesize <= 0 || ih_imagesize > ih_exesize)
throwCantPack("exe header corrupted"); throwCantPack("exe header corrupted");