Skip to content

fix(libc): prevent _Stoul 32-bit truncation on Windows - #2486

Closed
mrlempticles wants to merge 1 commit into
boykopovar:mainfrom
mrlempticles:fix/libc-stoul-windows-truncation
Closed

mrlempticles wants to merge 1 commit into
boykopovar:mainfrom
mrlempticles:fix/libc-stoul-windows-truncation

Conversation

@mrlempticles

@mrlempticles mrlempticles commented Oct 9, 2026 •

Copy link
Copy Markdown

What

_Stoul_nid_postfix (core/libs/prx/libc/src/RuntimeSupport.cpp) returned unsigned long and called std::strtoul. On Windows (LLP64), unsigned long is 32-bit, clamping values above UINT32_MAX to 4294967295 and setting ERANGE. On the PS5 (LP64), unsigned long is 64-bit.

  • Return unsigned long long and call std::strtoull, matching _Stoull_nid_postfix and strtoul_nid_postfix in Strings.cpp.
  • Extend CheckIntegerConversions in GuestMath.cpp to verify _Stoul_nid_postfix across 64-bit boundaries without erroneous truncation or range errors.

Fixes #2424

Tested

  • Verified all project conventions pass locally with python tools/check_conventions.py --base origin/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 in TechnicalDebt
  • 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
  • AI-assisted: yes

On Windows (LLP64), unsigned long is 32-bit, causing _Stoul_nid_postfix to clamp values above UINT32_MAX to 4294967295 and set ERANGE. PS5 (LP64) uses a 64-bit unsigned long.

Return unsigned long long and call std::strtoull to preserve 64-bit values across platforms, matching strtoul_nid_postfix and _Stoull. Add unsigned conversion coverage for _Stoul in guest_math_tests.
@github-actions github-actions Bot added the intake paused Closed while PR intake is limited to authors with at least 10 PRs merged into main label Oct 9, 2026
@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown

Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.

@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#1459 core/libs/prx/libc/src/RuntimeSupport.cpp L133-134
core/libs/tests/GuestMath.cpp L16-17, L140, L145
_Stoul_nid_postfix

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

Labels

intake paused Closed while PR intake is limited to authors with at least 10 PRs merged into main

Projects

None yet

Development

Successfully merging this pull request may close these issues.

_Stoul truncates to 32 bits on Windows (unsigned long is 32-bit there)

1 participant