docs(libSceJsc): record the 32-bit wrap of the JSString maximum UTF-8 size #15708

Open
MarcZX10 wants to merge 6 commits from upstream-pr/15708 into main
MarcZX10 commented 2026-11-04 08:46:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-04T08:46:26Z.


What

  • docs(libSceJsc): records in the debt list that JSStringGetMaximumUTF8CStringSize still computes 3 * length + 1 in std::uint32_t, so the result wraps for strings longer than about 1.43e9 UTF-16 code units. The code keeps main's 32-bit behaviour, as the reviewers asked; the change to size_t and the 2.9 GB test were removed from this PR.

Tested

  • Documentation only. Convention check and git diff --check pass against upstream/main.
  • Debt tests pass.
  • Not run: guest build or ctest, since no code changed.

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
  • 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

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5151531050 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15708). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-04T08:46:26Z. --- ### What - `docs(libSceJsc)`: records in the debt list that `JSStringGetMaximumUTF8CStringSize` still computes `3 * length + 1` in `std::uint32_t`, so the result wraps for strings longer than about 1.43e9 UTF-16 code units. The code keeps main's 32-bit behaviour, as the reviewers asked; the change to `size_t` and the 2.9 GB test were removed from this PR. ### Tested - Documentation only. Convention check and `git diff --check` pass against `upstream/main`. - Debt tests pass. - Not run: guest build or ctest, since no code changed. ### Checklist - [ ] 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) - [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 AI-assisted: yes
adriadam10 commented 2026-11-07 18:59:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-11-07T18:59:22Z.

Review: CHANGES_REQUESTED


Not merging yet; the open question from @oneandonlydean's review still stands:

  • core/libs/prx/libSceJsc/Export.cpp:121: JavaScriptCore computes string->length() * 3 + 1 with length() returning unsigned, so it wraps above 1431655765 units; the std::uint32_t arithmetic on main matches that. Widening to size_t makes us differ from JSC. Please show that the PS5 module returns the 64-bit value (disassembly of the export or a console run), or drop the code change. If it does differ from upstream, say so in the library's debt file.
  • core/libs/tests/GuestJscString.cpp:231: the test allocates ~2.9 GB in one go, a risk under ctest -j and on small runners. If kept, reach the length without that allocation, or run it alone and return 77 when the memory is not available.

Thanks to @JJenkx for the Windows run and negative control.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5814442852 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15708#pullrequestreview-5814442852). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-11-07T18:59:22Z. **Review:** CHANGES_REQUESTED --- Not merging yet; the open question from @oneandonlydean's review still stands: - `core/libs/prx/libSceJsc/Export.cpp:121`: JavaScriptCore computes `string->length() * 3 + 1` with `length()` returning `unsigned`, so it wraps above 1431655765 units; the `std::uint32_t` arithmetic on `main` matches that. Widening to `size_t` makes us differ from JSC. Please show that the PS5 module returns the 64-bit value (disassembly of the export or a console run), or drop the code change. If it does differ from upstream, say so in the library's debt file. - `core/libs/tests/GuestJscString.cpp:231`: the test allocates ~2.9 GB in one go, a risk under `ctest -j` and on small runners. If kept, reach the length without that allocation, or run it alone and return 77 when the memory is not available. Thanks to @JJenkx for the Windows run and negative control.
gabichuuuuu commented 2026-11-10 11:12:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by gabichuuuuu on 2026-11-10T11:12:32Z.

Review: COMMENTED


Read 5e7615b3e9 against main.

Correctness. The 32-bit arithmetic on main is deliberate, not a bug. It came in with 50c8d4cd8f ("answer the JSString null and length cases as JavaScriptCore does"), and it matches the WebKit sources the debt file pins. In pinned WebKit f274ef4c03 Source/JavaScriptCore/API/JSStringRef.cpp, JSStringGetMaximumUTF8CStringSize is return string->length() * 3 + 1;, and OpaqueJSString::length() returns unsigned. The product is therefore computed in 32 bits and wraps before it widens to size_t. The PS5 11.x WebKit tree linked in docs/dev/debt/libSceJsc.md has the same two lines (JSStringRef.cpp and OpaqueJSString.h, unsigned length()). For lengths of 1431655766 and up, the console library returns the wrapped value; with this change Export.cpp:JSStringGetMaximumUTF8CStringSize_nid_postfix returns the unwrapped one. Lengths up to 2147483635 are accepted (the debt entry's UTF-16 limit), so the range where the result differs is reachable.

Test. MaximumSizeAboveUInt32 pins the non-WebKit result. It also allocates about 2.9 GB in a default ctest run. That is a lot for CI runners, and more under sanitizers.

Suggestion. Keep main's behaviour. If a test for this range is useful, pin the wrapped value against the WebKit line above and cite it in the debt entry. If the PS5 build is believed to differ, that needs a console measurement or a disassembly, not the general size_t reading.

Not run here; this is from reading the code.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5840907378 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15708#pullrequestreview-5840907378). Originally posted by [gabichuuuuu](https://github.com/gabichuuuuu) on 2026-11-10T11:12:32Z. **Review:** COMMENTED --- Read `5e7615b3e9` against `main`. **Correctness.** The 32-bit arithmetic on `main` is deliberate, not a bug. It came in with 50c8d4cd8f ("answer the JSString null and length cases as JavaScriptCore does"), and it matches the WebKit sources the debt file pins. In pinned WebKit `f274ef4c03` `Source/JavaScriptCore/API/JSStringRef.cpp`, `JSStringGetMaximumUTF8CStringSize` is `return string->length() * 3 + 1;`, and `OpaqueJSString::length()` returns `unsigned`. The product is therefore computed in 32 bits and wraps before it widens to `size_t`. The PS5 11.x WebKit tree linked in `docs/dev/debt/libSceJsc.md` has the same two lines (`JSStringRef.cpp` and `OpaqueJSString.h`, `unsigned length()`). For lengths of 1431655766 and up, the console library returns the wrapped value; with this change `Export.cpp:JSStringGetMaximumUTF8CStringSize_nid_postfix` returns the unwrapped one. Lengths up to 2147483635 are accepted (the debt entry's UTF-16 limit), so the range where the result differs is reachable. **Test.** `MaximumSizeAboveUInt32` pins the non-WebKit result. It also allocates about 2.9 GB in a default `ctest` run. That is a lot for CI runners, and more under sanitizers. **Suggestion.** Keep `main`'s behaviour. If a test for this range is useful, pin the wrapped value against the WebKit line above and cite it in the debt entry. If the PS5 build is believed to differ, that needs a console measurement or a disassembly, not the general `size_t` reading. Not run here; this is from reading the code. AI-assisted: yes.
ligmaSec commented 2026-12-03 12:06:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T12:06:56Z.

Review: COMMENTED


Ran the debt fold check on this head. The new entry applies cleanly and matches the implementation’s 32-bit arithmetic. A console result remains unmeasured.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6169449060 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15708#pullrequestreview-6169449060). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T12:06:56Z. **Review:** COMMENTED --- Ran the debt fold check on this head. The new entry applies cleanly and matches the implementation’s 32-bit arithmetic. A console result remains unmeasured. AI-assisted: yes.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/15708:upstream-pr/15708'
git switch 'upstream-pr/15708'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/15708'
git switch 'upstream-pr/15708'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/15708'
git switch 'upstream-pr/15708'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/15708'
git switch 'main'
git merge --squash 'upstream-pr/15708'
git switch 'main'
git merge --ff-only 'upstream-pr/15708'
git switch 'main'
git merge 'upstream-pr/15708'
git push origin 'main'
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!15708
No description provided.