fix(libc): reject an invalid _WStoul base like Dinkumware instead of … #10729

Merged
dwk001 merged 3 commits from upstream-pr/10729 into main 2026-11-02 07:54:38 +00:00
dwk001 commented 2026-10-24 19:51:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by dwk001 on 2026-10-24T19:51:40Z.


What

_WStoul threw std::invalid_argument for a base other than 0 or 2 to 36. It now passes every base to wcstoul, which returns 0, stores the start of the string in the end pointer and leaves errno unchanged, as Dinkumware's xstoul.c does. Unverified on the console; noted in docs/dev/debt/libc.md.

Tested

Linux, full build with -DBUILD_TESTING=ON: ctest --test-dir build -R guest_wide_conversion passes with cases for bases 1, 37 and -2. tools/check_conventions.py --base origin/main reports one warning: the existing _WStoul/_Iswctype/swscanf debt entry was already over the 1000-character limit on main.

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4998608093 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10729). Originally posted by [dwk001](https://github.com/dwk001) on 2026-10-24T19:51:40Z. --- ### What `_WStoul` threw `std::invalid_argument` for a base other than 0 or 2 to 36. It now passes every base to `wcstoul`, which returns 0, stores the start of the string in the end pointer and leaves `errno` unchanged, as Dinkumware's `xstoul.c` does. Unverified on the console; noted in `docs/dev/debt/libc.md`. ### Tested Linux, full build with `-DBUILD_TESTING=ON`: `ctest --test-dir build -R guest_wide_conversion` passes with cases for bases 1, 37 and -2. `tools/check_conventions.py --base origin/main` reports one warning: the existing `_WStoul`/`_Iswctype`/`swscanf` debt entry was already over the 1000-character limit on main. ### 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) - [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
MarcZX10 commented 2026-10-24 21:46:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T21:46:56Z.

Review: APPROVED


Reviewed exact head 5d2b23c854. Removing the _WStoul-only exception preserves the shared wcstoul parser behavior and the setError=false invalid-base path: zero result, end pointer at the original input, and unchanged errno. The tests cover bases 1, 37, and -2 with leading whitespace. I syntax-compiled the exact Strings.cpp and GuestWideConversion.cpp; conventions report 0 errors (one existing debt-length warning), and git diff --check passes. I could not run the full runtime test in this environment.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5640152567 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10729#pullrequestreview-5640152567). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T21:46:56Z. **Review:** APPROVED --- Reviewed exact head 5d2b23c854d64a5ffcf2477d0615396cc4efcd46. Removing the `_WStoul`-only exception preserves the shared `wcstoul` parser behavior and the `setError=false` invalid-base path: zero result, end pointer at the original input, and unchanged errno. The tests cover bases 1, 37, and -2 with leading whitespace. I syntax-compiled the exact `Strings.cpp` and `GuestWideConversion.cpp`; conventions report 0 errors (one existing debt-length warning), and `git diff --check` passes. I could not run the full runtime test in this environment.
BunnyFl commented 2026-10-28 15:53:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-10-28T15:53:12Z.

Review: APPROVED


Approving head 31cc00b5d8. I read the diff and ran firmware 13.42's _WStoul (JhVR7D4Ax6Y): the decrypted system libSceLibcInternal.sprx's export, natively on a PC (not a console), with errno cleared and the end pointer pre-set before each call. Three identical runs.

  • " 1" with base 1, 37 and -2, "1" with base 1, "Z" with base 37 and " 1" with base 100 all return 0, leave the end pointer at the start of the string and leave errno at 0. That is what the new CheckStoul rows require.
  • Controls in the same run: " 1" base 10 gives 1 (end after 2 characters), " ff" base 16 gives 255, "0x1f" base 0 gives 31, "zz" base 36 gives 1295, and an overflowing decimal gives ULLONG_MAX with errno 34, so the end pointer and errno are both observed.

So the debt entry's "unverified on the console" can say that firmware 13.42's system module does the same, if you want to cite it.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5685612721 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10729#pullrequestreview-5685612721). Originally posted by [BunnyFl](https://github.com/BunnyFl) on 2026-10-28T15:53:12Z. **Review:** APPROVED --- Approving head `31cc00b5d8`. I read the diff and ran firmware 13.42's `_WStoul` (`JhVR7D4Ax6Y`): the decrypted system `libSceLibcInternal.sprx`'s export, natively on a PC (not a console), with `errno` cleared and the end pointer pre-set before each call. Three identical runs. - `" 1"` with base 1, 37 and -2, `"1"` with base 1, `"Z"` with base 37 and `" 1"` with base 100 all return 0, leave the end pointer at the start of the string and leave `errno` at 0. That is what the new `CheckStoul` rows require. - Controls in the same run: `" 1"` base 10 gives 1 (end after 2 characters), `" ff"` base 16 gives 255, `"0x1f"` base 0 gives 31, `"zz"` base 36 gives 1295, and an overflowing decimal gives `ULLONG_MAX` with `errno` 34, so the end pointer and `errno` are both observed. So the debt entry's "unverified on the console" can say that firmware 13.42's system module does the same, if you want to cite it.
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!10729
No description provided.