mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-10 01:28:44 +02:00
Merge pull request #183 from arreina/fix/elf-header-size
fix(relinker): require a full ELF64 header before reading it
This commit is contained in:
@@ -167,6 +167,8 @@ if(BUILD_TESTING)
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/relinker/tests/test_windows_gui.py $<TARGET_FILE:relinker>)
|
||||
add_test(NAME guest_intel_trampolines COMMAND ${Python3_EXECUTABLE}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/relinker/tests/test_guest_intel_trampolines.py $<TARGET_FILE:relinker>)
|
||||
add_test(NAME elf_header COMMAND ${Python3_EXECUTABLE}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/relinker/tests/test_elf_header.py $<TARGET_FILE:relinker>)
|
||||
else()
|
||||
message(STATUS "Python3 interpreter not found; skipping Python relinker tests")
|
||||
endif()
|
||||
|
||||
@@ -48,7 +48,7 @@ std::uint64_t ElfReader::_readU64At(FileByteOffset fileByteOffset) const {
|
||||
}
|
||||
|
||||
ElfHeader ElfReader::ReadHeader() const {
|
||||
if (_fileBuffer.size() < 20) {
|
||||
if (_fileBuffer.size() < 0x40) {
|
||||
throw RelinkerException("File too small for ELF header");
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
|
||||
def main():
|
||||
relinker = Path(sys.argv[1]).resolve()
|
||||
cases = [
|
||||
("tiny", bytes(10), "File too small for ELF header"),
|
||||
("truncated", b"\x7fELF\x02\x01\x01" + bytes(25), "File too small for ELF header"),
|
||||
("header-only", b"\x7fELF\x02\x01\x01" + bytes(57), "No PT_DYNAMIC segment found"),
|
||||
("bad-magic", bytes(64), "Invalid ELF magic number"),
|
||||
]
|
||||
with tempfile.TemporaryDirectory(prefix="anyps5-elf-header-") as directory:
|
||||
for name, data, error in cases:
|
||||
source = Path(directory) / (name + ".elf")
|
||||
output = source.with_suffix(".out")
|
||||
source.write_bytes(data)
|
||||
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)
|
||||
print("ELF header tests passed")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user