fix(relinker): reject x64 instructions longer than 15 bytes #1942

Closed
Zinebyte wants to merge 1 commit from upstream-pr/1942 into main
Zinebyte commented 2026-10-09 01:30:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Zinebyte on 2026-10-09T01:30:19Z.


What

The x64 decoder accepts instructions longer than 15 bytes and can let an overlong MOVNTSS reach Intel conversion. Reject overlong prefix streams and both decoded-length return paths while retaining existing shorter decoding, operand bytes and file-offset diagnostics. The limit follows Intel's SDM, Volume 2A §2.2.1.

Tested

The isolated decoder/converter regression fails against base f145139676 and passes with this patch. The independent reviewer passed 84 integration cases covering 15/16-byte legacy, VEX2/VEX3, EVEX, immediate, displacement, branch and MOVNTSS forms across Linux/Windows output; malformed bytes were not executed. Zorin OS 18.1 x86-64, GCC 13.3.0, Python 3.12 and CMake 3.28.3, relinker-only Release/static, one build job. Author validation of the composed four patches passed all 39 configured CTest registrations in 6.06 s, including progress_report and import_audit; exact-base baseline passed 38/38 in 5.93 s. A separate independent review rebuilt the composed revision and passed 39/39 in 6.03 s. Focused baseline and patched checks use small synthetic inputs. Existing assertions are retained; no real game, firmware, private asset or GPU input was used.

Native Windows/macOS runtime, real titles, sanitizers and cold shared-CI timing remain unverified. Existing approximate opcode semantics remain outside this architectural length bound.

Open #1552 adds separate DecoderLengthTests.cpp/DecoderLengthCases.hpp tests and does not change this test file or implement this guard. #1756 adds narrower RDPRU/MCOMMIT matcher-length guards and shares the converter test file. The cross-segment branch fix also adds tests there; the reviewed patches compose. No cross-PR runtime validation is claimed.

Checklist

  • Based on current main f145139676; open-work audit found no equivalent implementation
  • One topic per PR
  • No new code comments
  • Invalid input throws; existing shorter decoding behavior retained
  • No investigation files or dependencies added to the repository
  • General behavior with synthetic input
  • Depends on: none
  • AI-assisted: yes, OpenAI Codex
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4794814158 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1942). Originally posted by [Zinebyte](https://github.com/Zinebyte) on 2026-10-09T01:30:19Z. --- ### What The x64 decoder accepts instructions longer than 15 bytes and can let an overlong MOVNTSS reach Intel conversion. Reject overlong prefix streams and both decoded-length return paths while retaining existing shorter decoding, operand bytes and file-offset diagnostics. The limit follows Intel's [SDM, Volume 2A §2.2.1](https://cdrdv2-public.intel.com/782168/252046-sdm-change-document.pdf#page=118). ### Tested The isolated decoder/converter regression fails against base f145139676a48306681d3a4d5fabf83938759daf and passes with this patch. The independent reviewer passed 84 integration cases covering 15/16-byte legacy, VEX2/VEX3, EVEX, immediate, displacement, branch and MOVNTSS forms across Linux/Windows output; malformed bytes were not executed. Zorin OS 18.1 x86-64, GCC 13.3.0, Python 3.12 and CMake 3.28.3, relinker-only Release/static, one build job. Author validation of the composed four patches passed all 39 configured CTest registrations in 6.06 s, including progress_report and import_audit; exact-base baseline passed 38/38 in 5.93 s. A separate independent review rebuilt the composed revision and passed 39/39 in 6.03 s. Focused baseline and patched checks use small synthetic inputs. Existing assertions are retained; no real game, firmware, private asset or GPU input was used. Native Windows/macOS runtime, real titles, sanitizers and cold shared-CI timing remain unverified. Existing approximate opcode semantics remain outside this architectural length bound. Open #1552 adds separate DecoderLengthTests.cpp/DecoderLengthCases.hpp tests and does not change this test file or implement this guard. #1756 adds narrower RDPRU/MCOMMIT matcher-length guards and shares the converter test file. The cross-segment branch fix also adds tests there; the reviewed patches compose. No cross-PR runtime validation is claimed. ### Checklist - [x] Based on current main f145139676a48306681d3a4d5fabf83938759daf; open-work audit found no equivalent implementation - [x] One topic per PR - [x] No new code comments - [x] Invalid input throws; existing shorter decoding behavior retained - [x] No investigation files or dependencies added to the repository - [x] General behavior with synthetic input - Depends on: none - AI-assisted: yes, OpenAI Codex
MarcZX10 commented 2026-10-09 02:27:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T02:27:01Z.

Review: APPROVED


Reviewed the complete diff against current main. Prefix scanning stops at the architectural 15-byte limit, and both decoded-length return paths reject instructions that extend past it; the added cases cover exact 15-byte instructions, overlong prefix streams, scanner offsets, and MOVNTSS conversion. This head is based directly on current main. On Linux/GCC 12.2, the full relinker-only build passed, all 38 registered relinker CTests passed, and Conventions plus diff whitespace checks passed. GitHub reports no upstream checks for this head, so this approval records the local evidence only.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5465043211 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1942#pullrequestreview-5465043211). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-09T02:27:01Z. **Review:** APPROVED --- Reviewed the complete diff against current main. Prefix scanning stops at the architectural 15-byte limit, and both decoded-length return paths reject instructions that extend past it; the added cases cover exact 15-byte instructions, overlong prefix streams, scanner offsets, and MOVNTSS conversion. This head is based directly on current main. On Linux/GCC 12.2, the full relinker-only build passed, all 38 registered relinker CTests passed, and Conventions plus diff whitespace checks passed. GitHub reports no upstream checks for this head, so this approval records the local evidence only.
rmz-24 commented 2026-10-09 11:58:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by rmz-24 on 2026-10-09T11:58:43Z.


Windows run, since the description notes it wasn't tested there: Windows 11 Pro 25H2 (10.0.26200.9457), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, full build with BUILD_TESTING=ON. 28d2fe49 cherry-picked onto current main d70b8998 (applies cleanly).

  • amd64_only_converter passes.
  • Full ctest: 510/510, including the Windows PE execution tests.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6080400416 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1942#issuecomment-6080400416). Originally posted by [rmz-24](https://github.com/rmz-24) on 2026-10-09T11:58:43Z. --- Windows run, since the description notes it wasn't tested there: Windows 11 Pro 25H2 (10.0.26200.9457), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, full build with `BUILD_TESTING=ON`. 28d2fe49 cherry-picked onto current `main` d70b8998 (applies cleanly). - `amd64_only_converter` passes. - Full ctest: 510/510, including the Windows PE execution tests. AI-assisted: yes
Zinebyte commented 2026-10-09 17:12:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Zinebyte on 2026-10-09T17:12:41Z.


Could a maintainer rerun the failed Windows job? At head 28d2fe49, Build attempt 2 reports only agc_shader_disk_cache timing out after 120 seconds; amd64_only_converter passed. Linux, the Linux/Windows/macOS relinker jobs, and Conventions passed. This account has no upstream Actions rerun permission.

Thanks rmz-24 for the Windows validation: Windows 11 Pro 25H2 / MinGW-w64 GCC 15.2, Release, full CTest 510/510 including Windows PE execution, with 28d2fe49 cherry-picked onto d70b8998. That is useful separate evidence; the CI timeout's cause remains unproven.

AI-assisted review and reply.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6085665573 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1942#issuecomment-6085665573). Originally posted by [Zinebyte](https://github.com/Zinebyte) on 2026-10-09T17:12:41Z. --- Could a maintainer rerun the [failed Windows job](https://github.com/boykopovar/AnyPS5/actions/runs/37870094605/job/113729811108)? At head `28d2fe49`, Build attempt 2 reports only `agc_shader_disk_cache` timing out after 120 seconds; `amd64_only_converter` passed. Linux, the Linux/Windows/macOS relinker jobs, and Conventions passed. This account has no upstream Actions rerun permission. Thanks rmz-24 for the [Windows validation](https://github.com/boykopovar/AnyPS5/pull/1942#issuecomment-6080400416): Windows 11 Pro 25H2 / MinGW-w64 GCC 15.2, Release, full CTest 510/510 including Windows PE execution, with `28d2fe49` cherry-picked onto `d70b8998`. That is useful separate evidence; the CI timeout's cause remains unproven. AI-assisted review and reply.
oneandonlydean commented 2026-10-09 20:08:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T20:08:22Z.


Closing: an instruction longer than 15 bytes faults on the console, so no title executes one, and nothing here shows a conversion that goes wrong on main because of it. If a title's relink trips over one, please reopen with that title.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6088418183 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1942#issuecomment-6088418183). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-09T20:08:22Z. --- Closing: an instruction longer than 15 bytes faults on the console, so no title executes one, and nothing here shows a conversion that goes wrong on main because of it. If a title's relink trips over one, please reopen with that title.
Zinebyte commented 2026-10-09 20:32:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Zinebyte on 2026-10-09T20:32:11Z.


Understood. The synthetic decoder cases do not demonstrate a title whose conversion fails on main. I have no such title evidence and accept keeping this closed. The earlier CI rerun request is no longer needed for this closed PR.

AI-assisted review and reply.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6088770867 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1942#issuecomment-6088770867). Originally posted by [Zinebyte](https://github.com/Zinebyte) on 2026-10-09T20:32:11Z. --- Understood. The synthetic decoder cases do not demonstrate a title whose conversion fails on main. I have no such title evidence and accept keeping this closed. The earlier CI rerun request is no longer needed for this closed PR. AI-assisted review and reply.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!1942
No description provided.