From 2e763c3b0e96cbdda4186131976e8d38d10d19d5 Mon Sep 17 00:00:00 2001 From: Thorsten Zachmann Date: Mon, 16 Dec 2024 10:58:16 +0100 Subject: [PATCH] Improve patch Implement things pointed out by jreiser on review of the patch. - Fix type conversion issue - Added constant with comment - Added comment for not validating UPX_RSIZE_MAX_MEM Additional changes - Honor the size of the export_dir_t when calculating the available space --- src/pefile.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pefile.cpp b/src/pefile.cpp index b40a8e72..4dda7f68 100644 --- a/src/pefile.cpp +++ b/src/pefile.cpp @@ -1224,7 +1224,9 @@ void PeFile::Export::convert(unsigned eoffs, unsigned esize) { size += len; iv.add_interval(edir.name, len); - if (upx_uint64_t(edir.functions + edir.names) * 4 >= upx_uint64_t(esize)) { + // this check does not take UPX_RSIZE_MAX_MEM into account + const int ptr_size = 4; // size of function/name pointers + if ((upx_uint64_t(edir.functions) + upx_uint64_t(edir.names)) * ptr_size >= upx_uint64_t(esize - sizeof(export_dir_t))) { throwInternalError("bad export directory, outside size"); }