From 90d86ea59e25e82d5ac0768c9dbfaef19cc8ff3c Mon Sep 17 00:00:00 2001 From: John Reiser Date: Thu, 27 Feb 2025 17:10:52 -0800 Subject: [PATCH] Prevent leak even if corrupted input https://issues.oss-fuzz.com/u/1/issues/42531955 modified: pefile.cpp --- src/pefile.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pefile.cpp b/src/pefile.cpp index 9cf12e24..8b11e1bf 100644 --- a/src/pefile.cpp +++ b/src/pefile.cpp @@ -1718,6 +1718,8 @@ PeFile::Resource::upx_rnode *PeFile::Resource::convert(const void *rnode, upx_rn branch->nc = ic; branch->children = New(upx_rnode *, ic); branch->data = *node; + if (!root) // first one + root = branch; // prevent leak if xcheck throws (hacked unpack or test) for (const res_dir_entry *rde = node->entries + ic - 1; --ic >= 0; rde--) { upx_rnode *child = convert(start + (rde->child & 0x7fffffff), branch, level + 1);