Merge pull request #5148 from AaravMehta-07/codex/reject-relocatable-input

fix(relinker): reject relocatable ELF conversion inputs
This commit is contained in:
Dean 2026-10-14 14:35:53 +13:00 committed by GitHub
commit 3881dac903
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 0 deletions

View File

@ -16,6 +16,12 @@ namespace Relinker {
using namespace Elfpatcher;
namespace {
constexpr std::uint16_t kEtRel = 1;
}
RelinkerPipeline::RelinkerPipeline(std::shared_ptr<IElfReader> elfReader, std::shared_ptr<ISyscallScanner> syscallScanner, std::shared_ptr<ICallSiteResolver> callSiteResolver, std::shared_ptr<IValidationPolicy> validationPolicy, std::shared_ptr<ISysVDynamicSectionBuilder> dynamicSectionBuilder, std::shared_ptr<IUnusedNidFilter> unusedNidFilter, std::uint32_t unusedFilterLevel, Domain::IProgress& progress)
: elfReader(std::move(elfReader))
, syscallScanner(std::move(syscallScanner))
@ -45,6 +51,9 @@ std::string RelinkerPipeline::relocationTypeName(std::uint32_t type) {
}
RelinkResult RelinkerPipeline::Relink(const std::vector<std::uint8_t>& sourceElf) {
if (elfReader->ReadHeader().Type == kEtRel)
throw RelinkerException("ET_REL relocatable inputs are not supported");
auto programHeaders = elfReader->ReadProgramHeaders();
std::vector<std::uint8_t> textSection;

View File

@ -95,6 +95,16 @@ def main():
result = subprocess.run([str(relinker), "--skip-sce-module", str(source), str(output)],
capture_output=True, text=True, timeout=20)
assert result.returncode == 2 and error in result.stderr and not output.exists(), (name, result)
relocatable = main_fixture()
struct.pack_into("<H", relocatable, 16, 1)
source = Path(directory) / "relocatable.elf"
output = Path(directory) / "relocatable.out"
source.write_bytes(relocatable)
result = subprocess.run([str(relinker), "--skip-sce-module", str(source), str(output)],
capture_output=True, text=True, timeout=20)
assert result.returncode == 2 and "ET_REL relocatable inputs are not supported" in result.stderr and not output.exists(), result
identification_cases(relinker, directory)
structural_cases(relinker, directory)
print("ELF header tests passed")