Skip to content

fix(libSceJson2): copy Initializer and MemAllocator guest pointers through checked copies - #21556

Open
Gruzzberry wants to merge 1 commit into
boykopovar:mainfrom
Gruzzberry:fix/libscejson2-guest-ptr-init
Open

Gruzzberry wants to merge 1 commit into
boykopovar:mainfrom
Gruzzberry:fix/libscejson2-guest-ptr-init

Conversation

@Gruzzberry

@Gruzzberry Gruzzberry commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

What

Copy the Initializer and MemAllocator guest pointers (self, init parameter) in libSceJson2 through GuestPtr/GuestBytes checked copies; a failed read returns JsonErrorInvalidArgument.

Tested

Ran tools/check_conventions.py --base upstream/main (passed). Not built or run (no compiler available); pr_overlap.py --branch did not finish.

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

🤖 Generated with Claude Code

…rough checked copies

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the prx label Nov 16, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

I am holding this until there is a build and a test run on the head. The PR says it was not compiled or run, and a reviewer should not be the compiler.
Please build it, run the tests for the library, and add a test that fails without the change. Where several PRs touch one library (NpCppWebApi has four open on the same Export.cpp regions), please fold them into one PR per library. Per-call getters wrapped in checked copies fall under the owner's cost ruling on #20589 and #20691, so leave those out or show the measured cost.

@kiwe147

kiwe147 commented Nov 21, 2026

Copy link
Copy Markdown

Tested head e3c08f719e, applied with git apply on main fd4aeed483 together with the other 25 PRs of one batch (#24107, #24132, #24238, #15143, #22088, #22685, #23739, #24032, #16054, #20001, #20344, #24170, #24396, #16856, #17298, #20497, #23347, #24426, #24554, #24598, #21376, #22047, #22082, #14124, #18476).

This PR makes guest_json_allocator fail. The test passes on main and fails in the batch tree, in the full run and alone (ctest -R, 3 of 3 runs). In the batch tree, with this PR reverted the test passes, and with it applied again it fails again. I did not look for the cause inside the change.

Setup: Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON. NVIDIA GeForce RTX 3080 (driver 621.24). No validation layer.

AI-assisted: yes (Claude Code)

This was referenced Nov 21, 2026

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — changes requested

Changes are required before merge: make both InitParameter overloads use checked guest reads and writes, and keep initialization state consistent if writing back the initializer flag fails.

What I ran

Reviewed head e3c08f719e438ccb3ad1bdce7953972ae8fb14a3. Read description.md, commits.md, manifest.json, diff.patch, and the full changed file core/libs/prx/libSceJson2/Export.cpp in targeted ranges; also read GuestPtr.hpp and Api.hpp. No build or tests were run.

Results

Check Result Note
Diff and source review failed Shared initialization still has unchecked guest accesses
Build and tests not run No command execution available
Changed files passed Read the sole file listed as reviewed

Findings

Blocking

  • core/libs/prx/libSceJson2/Export.cpp:1578: InitializeResources commits global initialization and then writes self directly at line 1595 without checking the guest write. If that write fails, the guest gets no initialized flag while the global state remains initialized, and the call returns success. Propagate a checked CopyOut failure and roll back or avoid committing initialization until the write succeeds.
  • core/libs/prx/libSceJson2/Export.cpp:1571: The change checks reads for the legacy initializer overload, but the InitParameter2 overload at line 3295 still directly dereferences both self and parameter; it passes parameter to the newly checked shared reader as well. Unreadable guest pointers can still fault on this public initialization path. Apply checked copies to that overload too, including validation of specialFloatFormatType.

Non-blocking

None.

Not verified

  • The author reports that tools/check_conventions.py --base upstream/main passed; I did not run it. The build and runtime behavior were not verified.
  • files.json was not available through the reader, so excluded files could not be checked; the manifest lists one changed file and it was read in full through targeted ranges.

To get this to a good state

  • Check guest reads and writes on both initializer overloads, and ensure a failed flag write does not leave shared resources initialized. Re-run the convention check, build, and relevant tests on the updated head.

@ligmaSec ligmaSec left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please handle the failed CopyOut calls before reporting success. In Initializer::terminate, the shared state and resources have already been released before the unchecked write to the instance flag. An unwritable instance leaves the caller's flag set even though termination returns zero. The two constructors also ignore a failed write and return with the guest object uninitialized.

AI-assisted: yes.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants