fix(libSceJxr): copy attachISWrite, putBit16z and fillToByte guest pointers safely #23686

Merged
plentilha merged 1 commit from upstream-pr/23686 into main 2026-11-19 15:16:45 +00:00
plentilha commented 2026-11-19 13:02:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by plentilha on 2026-11-19T13:02:09Z.


What

  • Access io and stream in attachISWrite_nid_postfix, putBit16z_nid_postfix, and fillToByte_nid_postfix (core/libs/prx/libSceJxr/src/BitIo.cpp) through GuestCopyIn_nid_no_patch and GuestCopyOut_nid_no_patch while preserving caller errno and throwing std::invalid_argument on unreadable or unwritable guest pointers.
  • Add negative-control coverage for unmapped and read-only BitIo/Stream pointers with errno preservation in core/libs/tests/GuestJxrBitIo.cpp.
  • Record the host-safety fallback in docs/dev/debt/changes/fix-jxr-bitio-write-guest-copy.md.

Tested

  • Windows (ctest --test-dir build --output-on-failure -R "^guest_jxr_bitio$"):
    • Negative control against unmodified origin/main failed with Exception: SegFault.
    • Patched build: 1/1 (guest_jxr_bitio) passed.
  • tools/guest_pointer_audit.py libSceJxr: 0 findings in attachISWrite_nid_postfix, putBit16z_nid_postfix, and fillToByte_nid_postfix.
  • tools/debt_fold.py --check, core/libs/tests/test_public_headers.py --audit-only, tools/tests/test_public_headers_manifest.py, and tools/check_conventions.py passed.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5395400784 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23686). Originally posted by [plentilha](https://github.com/plentilha) on 2026-11-19T13:02:09Z. --- ### What - Access `io` and `stream` in `attachISWrite_nid_postfix`, `putBit16z_nid_postfix`, and `fillToByte_nid_postfix` (`core/libs/prx/libSceJxr/src/BitIo.cpp`) through `GuestCopyIn_nid_no_patch` and `GuestCopyOut_nid_no_patch` while preserving caller `errno` and throwing `std::invalid_argument` on unreadable or unwritable guest pointers. - Add negative-control coverage for unmapped and read-only `BitIo`/`Stream` pointers with `errno` preservation in `core/libs/tests/GuestJxrBitIo.cpp`. - Record the host-safety fallback in `docs/dev/debt/changes/fix-jxr-bitio-write-guest-copy.md`. ### Tested - Windows (`ctest --test-dir build --output-on-failure -R "^guest_jxr_bitio$"`): - Negative control against unmodified `origin/main` failed with `Exception: SegFault`. - Patched build: `1/1` (`guest_jxr_bitio`) passed. - `tools/guest_pointer_audit.py libSceJxr`: `0` findings in `attachISWrite_nid_postfix`, `putBit16z_nid_postfix`, and `fillToByte_nid_postfix`. - `tools/debt_fold.py --check`, `core/libs/tests/test_public_headers.py --audit-only`, `tools/tests/test_public_headers_manifest.py`, and `tools/check_conventions.py` passed. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) and the licence notice of code adapted from upstream (see AGENTS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
PrivacyOnion commented 2026-11-19 14:57:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-19T14:57:28Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 46abbab7c7:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_jxr_bitio_tests built cleanly.
  • CTest (guest_jxr_bitio):
    1/1 Test #4303: guest_jxr_bitio ..................   Passed    0.08 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceJxr/src/BitIo.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #4303: guest_jxr_bitio ..................Subprocess aborted***Exception:   0.22 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified attachISWrite_nid_postfix correctly reads guest BitIo and Stream via GuestCopyIn_nid_no_patch and writes BitIo fields back with GuestCopyOut_nid_no_patch while preserving errno
    • Verified putBit16z_nid_postfix correctly checks for null, reads guest BitIo via GuestCopyIn_nid_no_patch, tests writability via GuestCopyOut_nid_no_patch, and delegates to JxrPutBit16z_nid_no_patch
    • Verified fillToByte_nid_postfix correctly checks for null, validates readability and writability via guest copy helpers while preserving errno, and calls JxrFillToByte_nid_no_patch
    • Verified debt fragment docs/dev/debt/changes/fix-jxr-bitio-write-guest-copy.md follows format requirements and accurately describes the fallback behavior
    • Verified negative controls and error cases in core/libs/tests/GuestJxrBitIo.cpp for unmapped/read-only memory and errno preservation

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5977390507 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23686#pullrequestreview-5977390507). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-19T14:57:28Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `46abbab7c7`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_jxr_bitio_tests` built cleanly. - **CTest** (`guest_jxr_bitio`): ``` 1/1 Test #4303: guest_jxr_bitio .................. Passed 0.08 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libSceJxr/src/BitIo.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/1 Test #4303: guest_jxr_bitio ..................Subprocess aborted***Exception: 0.22 sec 0% tests passed, 1 tests failed out of 1 ``` Restoring the change makes it pass again. - **Code reading**: - Verified attachISWrite_nid_postfix correctly reads guest BitIo and Stream via GuestCopyIn_nid_no_patch and writes BitIo fields back with GuestCopyOut_nid_no_patch while preserving errno - Verified putBit16z_nid_postfix correctly checks for null, reads guest BitIo via GuestCopyIn_nid_no_patch, tests writability via GuestCopyOut_nid_no_patch, and delegates to JxrPutBit16z_nid_no_patch - Verified fillToByte_nid_postfix correctly checks for null, validates readability and writability via guest copy helpers while preserving errno, and calls JxrFillToByte_nid_no_patch - Verified debt fragment docs/dev/debt/changes/fix-jxr-bitio-write-guest-copy.md follows format requirements and accurately describes the fallback behavior - Verified negative controls and error cases in core/libs/tests/GuestJxrBitIo.cpp for unmapped/read-only memory and errno preservation Looks Good To Me
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!23686
No description provided.