From 2ad0d512266b0077e86d7e98a29f7957768ad643 Mon Sep 17 00:00:00 2001 From: John Reiser Date: Thu, 11 Jan 2024 09:57:57 -0800 Subject: [PATCH] PeFile::rebuildImports(): Allow strlen() up to the very end of a logical block https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=65650 https://github.com/upx/upx/issues/769 modified: pefile.cpp --- src/pefile.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/pefile.cpp b/src/pefile.cpp index 397420a2..a1f385da 100644 --- a/src/pefile.cpp +++ b/src/pefile.cpp @@ -2948,10 +2948,12 @@ void PeFile::unpack0(OutputFile *fo, const ht &ih, ht &oh, ord_mask_t ord_mask, if (iobjs > 2) { // read the noncompressed section + unsigned const size = isection[2].size; ibuf.dealloc(); - ibuf.alloc(isection[2].size); + ibuf.alloc(size + 1); fi->seek(isection[2].rawdataptr, SEEK_SET); - fi->readx(ibuf, ibufgood = isection[2].size); + fi->readx(ibuf, ibufgood = size); + ibuf[size] = 0; // allow strlen() up to 'size' } // unfilter