From 077793fa5ed4fc56f77dd2a7edec1adfdd8f9080 Mon Sep 17 00:00:00 2001 From: S01den <34453174+S01den@users.noreply.github.com> Date: Wed, 27 Jul 2022 01:54:01 +0200 Subject: [PATCH] Update pefile.cpp I found a bug by participating to the Binary Golf Grand Prix 3 (https://tmpout.sh/bggp/3/) : upx text.exe segfaults when NumberOfSections in the IMAGE_FILE_HEADER is NULL, so if (memcmp(isection[0].name,"UPX",3) == 0) triggers a NULL pointer dereference causing a crash. To fix it, just have to check if isection is NULL (which means NumberOfSections = 0) or not. --- src/pefile.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pefile.cpp b/src/pefile.cpp index 571e5831..2023fbed 100644 --- a/src/pefile.cpp +++ b/src/pefile.cpp @@ -2165,7 +2165,10 @@ void PeFile::checkHeaderValues(unsigned subsystem, unsigned mask, //check CLR Runtime Header directory entry if (IDSIZE(PEDIR_COMRT)) throwCantPack(".NET files are not yet supported"); - + + if(isection == NULL) + throwCantPack("No section was found"); + if (memcmp(isection[0].name,"UPX",3) == 0) throwAlreadyPackedByUPX();