fix(relinker): accept zero alignment for empty tls segments

This commit is contained in:
boykopovar
2026-09-27 12:41:52 +03:00
parent 52b683d208
commit e3dc9a6acc
2 changed files with 2 additions and 2 deletions
@@ -91,7 +91,7 @@ PeDirectory WindowsTlsBuilder::Build(const std::vector<std::uint8_t>& source, co
return {};
}
if (tls->FileSize > tls->MemorySize || tls->Offset > source.size() || tls->FileSize > source.size() - tls->Offset || !std::has_single_bit(tls->Alignment) || tls->Alignment > 8192 || tls->MemorySize > 0x7fff0000u)
if (tls->FileSize > tls->MemorySize || tls->Offset > source.size() || tls->FileSize > source.size() - tls->Offset || (tls->Alignment > 1 && !std::has_single_bit(tls->Alignment)) || tls->Alignment > 8192 || tls->MemorySize > 0x7fff0000u)
throw Domain::RelinkerException("Invalid or unsupported ELF TLS layout", tls->Offset);
// Native homebrew linkers can emit an empty PT_TLS placeholder.
// It needs no Windows TLS directory unless guest code accesses TLS.
@@ -54,7 +54,7 @@ GuestImage GuestImageReader::Read(const std::filesystem::path& path, std::vector
dynlib = &header;
}
if (header.Type == 7) {
if (tls != nullptr || header.FileSize > header.MemorySize || !std::has_single_bit(header.Alignment)) fail("Invalid TLS segment");
if (tls != nullptr || header.FileSize > header.MemorySize || (header.Alignment > 1 && !std::has_single_bit(header.Alignment))) fail("Invalid TLS segment");
tls = &header;
}
}