From 8ab180edf8aa824b57a3401941d961cd1302319b Mon Sep 17 00:00:00 2001 From: John Reiser Date: Thu, 18 Jan 2018 12:00:38 -0800 Subject: [PATCH] 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 --- src/p_exe.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/p_exe.cpp b/src/p_exe.cpp index 80bdb0f3..503d30f2 100644 --- a/src/p_exe.cpp +++ b/src/p_exe.cpp @@ -281,9 +281,13 @@ int PackExe::readFileHeader() if (ih.ident != 'M' + 'Z'*256 && ih.ident != 'Z' + 'M'*256) return 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_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"); if (file_size < (off_t)ih_exesize || ih_imagesize <= 0 || ih_imagesize > ih_exesize) throwCantPack("exe header corrupted");