From 28f0bb4e113907291148974d7378dd5f70e947d5 Mon Sep 17 00:00:00 2001 From: "Markus F.X.J. Oberhumer" Date: Wed, 9 Nov 2022 19:29:16 +0100 Subject: [PATCH] src: fix pefile.cpp otls allocation not accounting for alignment. Closes #621. --- src/pefile.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pefile.cpp b/src/pefile.cpp index e7bc4c84..fad6907d 100644 --- a/src/pefile.cpp +++ b/src/pefile.cpp @@ -1386,11 +1386,12 @@ void PeFile::processTls1(Interval *iv, // ... and those dwords should be correctly aligned if (use_tls_callbacks) sotls = ALIGN_UP(sotls, cb_size) + 2 * cb_size; + const unsigned aligned_sotls = ALIGN_UP(sotls, (unsigned)sizeof(LEXX)); // the PE loader wants this stuff uncompressed - mb_otls.alloc(sotls); + mb_otls.alloc(aligned_sotls); mb_otls.clear(); - otls = mb_otls; // => SPAN_S + otls = mb_otls; // => otls now is a SPAN_S unsigned const take1 = sizeof(tls); unsigned const skip1 = IDADDR(PEDIR_TLS); memcpy(otls,ibuf.subref("bad tls %#x", skip1, take1), take1);