fix(relinker): reject malformed dynamic segments #930
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/930"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by ebarr24 on 2026-10-06T18:28:30Z.
What
The executable relinker's dynamic reader accepted a table without DT_NULL and
silently stopped at the file boundary or a wrapped end offset. Linux conversion
could produce an output executable for a truncated or unterminated PT_DYNAMIC.
Windows detected some of these inputs later during code analysis, after parsing.
Validate the entire declared segment using the existing subtraction-based range
check, require whole 16-byte entries, and require DT_NULL within the segment.
Return at the first DT_NULL so valid trailing padding is still ignored. Errors
identify the segment offset before conversion starts. The termination requirement
follows the ELF dynamic section specification.
The new integration test exercises both Linux and Windows output modes with 11
synthetic fixtures: valid input, ignored entries after DT_NULL, a table ending
exactly at EOF, offsets beyond EOF and at UINT64_MAX, wrapped offset/size ranges,
a truncated declaration after DT_NULL, a partial entry, a missing terminator and
an empty table. The existing invalid-offset test uses the new segment diagnostic.
Tested
Windows 11 x64, WinLibs MinGW-w64 GCC 15.2.0 (ucrt-posix-seh r7), CMake 4.4.4,
Ninja 1.13.2, Python 3.12.14. Base:
5895ea721a.Change:
cd0e534d.object; malformed Linux inputs return success and produce output. It passes
with this change in both output modes.
and strict_nid_filter all pass.
including the libs target.
account (162.58 seconds). Includes GPU execution tests on the RTX 3080.
Defender scanning, with Smart App Control off. Defender real-time protection
remained enabled.
Checklist
Imported from boykopovar/AnyPS5. Originally posted by 011010 on 2026-10-06T22:27:46Z.
Independent verification (relinker-only, builds anywhere).
Built the relinker from
pr930standalone on macOS 26.6.2 (arm64), Apple Clang 21, C++20:test_dynamic_segment.pypasses,test_elf_offsets.pypasses, and the other 19 relinker Python tests in the tree pass (21/21).To confirm the test exercises the fix rather than passing vacuously, I ran it against
main(c1241ad): it fails, and the failures are the behaviour this PR corrects. Onmain, with Linux output the malformed inputs are accepted:truncated-after-null: rc 0, output file producedpartial-entry: rc 0, output file producedmissing-null: rc 0, output file producedThe test expects them rejected. On Windows output,
mainalso acceptedtruncated-after-nullfrom the dynamic reader and stopped later in code analysis, as the description says. With this change both modes reject them at parse time with a segment diagnostic.Limits: no Windows host here, so I only observed the Linux path and the parse-time rejection; the Windows execution side is covered by your run. No console or commercial title involved.
Imported from boykopovar/AnyPS5. Originally posted by ebarr24 on 2026-10-06T23:49:11Z.
@011010 Thanks for the independent macOS relinker verification and for checking that the same regression fails on
c1241adfor the intended malformed-segment behavior. Your 21/21 result adds coverage beyond my Windows runs. I'll keep the reported Linux-output and parse-time checks distinct from Windows guest execution and console/title verification.