src: fix pefile.cpp otls allocation not accounting for alignment. Closes #621.

This commit is contained in:
Markus F.X.J. Oberhumer 2022-11-09 19:29:16 +01:00
parent 824c8a8efb
commit 28f0bb4e11

View File

@ -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);