From a5f5e7fc7378925b78e9d0dadb0e7f5415930dd4 Mon Sep 17 00:00:00 2001 From: John Reiser Date: Fri, 24 Oct 2025 08:35:20 -0700 Subject: [PATCH] WinPE: Require --strip-relocs if relocating compressed data Thanks to @bitraid for investigating and suggestions. https://github.com/upx/upx/issues/880 modified: pefile.cpp --- src/pefile.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/pefile.cpp b/src/pefile.cpp index ffd8ecda..ab974526 100644 --- a/src/pefile.cpp +++ b/src/pefile.cpp @@ -1502,8 +1502,12 @@ void PeFile::processTls2(Reloc *const rel, const Interval *const iv, unsigned ne kc += newaddr + sizeof(tls) - tlsp->datastart; *p = kc + imagebase; rel->add_reloc(kc, iv->ivarr[ic].len); - } else - rel->add_reloc(kc - imagebase, iv->ivarr[ic].len); + } else { + unsigned const a = kc - imagebase; + if (a < newaddr && !opt->win32_pe.strip_relocs) + throwCantPack("relocation too low (%#x < %#x); try --strip-relocs", a, newaddr); + rel->add_reloc(a, iv->ivarr[ic].len); + } } const unsigned tls_data_size = tlsp->dataend - tlsp->datastart;