fix(libc): fail a stream float scan of an empty hex prefix or a truncated infinity on macOS #21720

Merged
XIIYAZ merged 1 commit from upstream-pr/21720 into main 2026-11-26 01:31:35 +00:00
XIIYAZ commented 2026-11-16 16:48:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XIIYAZ on 2026-11-16T16:48:20Z.


What

On macOS, file_streams aborts in its stream scan checks:

Stream scan changed a matching failure to input failure

The check scans "%64f %1c%n" from a stream holding a few malformed float prefixes. The console reports a matching failure for each: the value, the %1c output and the count stay untouched. Two inputs come back differently on macOS:

input expected macOS
0x 0 (matching failure) 2: value 0, then x read by %1c
infi 0 (matching failure) 2: value inf, then i read by %1c

With a narrow character conversion in the format, ScanGuestStream parses each float field with the host's fscanf. For a string source, CheckHexPrefix already rejects an empty hex prefix before the host scan, but stream sources skip it. glibc ends both fields with a matching failure, so Linux passes. macOS stdio stops after 0 and after inf and leaves the rest.

StreamSource::MalformedFloatAhead now reads ahead before the host scan of a float field and pushes everything back. It reads only as far as needed to decide, within the field width. The conversion fails when the field is one of:

  • an optional sign, then 0x (or 0X) followed by neither a hex digit nor . (including the end of the input or of the field width)
  • infi that does not go on to infinity (any case)

Any other input goes to the host scan as before, including 0x. and nan(, which the same test compares with the host's own fscanf.

file_streams also needs #21721 (a failed unbuffered write resent its byte) to pass on macOS.

Tested

  • Apple M4, macOS 26.7.3, Apple clang 21.0.0, full Release build with -DBUILD_TESTING=ON, x86_64 under Rosetta
  • With this change and #21721, file_streams passes. Before, it aborted on 0x, and with only the 0x case handled, on infi.
  • ctest -R 'file_streams|scan|format|printf|stdio|wide|fwrite|fputs|stream' (99 tests) passes. Two audio tests that the pattern also matched timed out in that -j 4 run and pass alone.
  • python3 tools/check_conventions.py --base origin/main passes.

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: none (no GPU work)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5341144473 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21720). Originally posted by [XIIYAZ](https://github.com/XIIYAZ) on 2026-11-16T16:48:20Z. --- ### What On macOS, `file_streams` aborts in its stream scan checks: ``` Stream scan changed a matching failure to input failure ``` The check scans `"%64f %1c%n"` from a stream holding a few malformed float prefixes. The console reports a matching failure for each: the value, the `%1c` output and the count stay untouched. Two inputs come back differently on macOS: | input | expected | macOS | |---|---|---| | `0x` | 0 (matching failure) | 2: value 0, then `x` read by `%1c` | | `infi` | 0 (matching failure) | 2: value inf, then `i` read by `%1c` | With a narrow character conversion in the format, `ScanGuestStream` parses each float field with the host's `fscanf`. For a string source, `CheckHexPrefix` already rejects an empty hex prefix before the host scan, but stream sources skip it. glibc ends both fields with a matching failure, so Linux passes. macOS stdio stops after `0` and after `inf` and leaves the rest. `StreamSource::MalformedFloatAhead` now reads ahead before the host scan of a float field and pushes everything back. It reads only as far as needed to decide, within the field width. The conversion fails when the field is one of: - an optional sign, then `0x` (or `0X`) followed by neither a hex digit nor `.` (including the end of the input or of the field width) - `infi` that does not go on to `infinity` (any case) Any other input goes to the host scan as before, including `0x.` and `nan(`, which the same test compares with the host's own `fscanf`. `file_streams` also needs #21721 (a failed unbuffered write resent its byte) to pass on macOS. ### Tested - Apple M4, macOS 26.7.3, Apple clang 21.0.0, full Release build with `-DBUILD_TESTING=ON`, x86_64 under Rosetta - With this change and #21721, `file_streams` passes. Before, it aborted on `0x`, and with only the `0x` case handled, on `infi`. - `ctest -R 'file_streams|scan|format|printf|stdio|wide|fwrite|fputs|stream'` (99 tests) passes. Two audio tests that the pattern also matched timed out in that `-j 4` run and pass alone. - `python3 tools/check_conventions.py --base origin/main` passes. ### 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: none (no GPU work) - [x] AI-assisted: yes
kurexw commented 2026-11-17 06:14:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by kurexw on 2026-11-17T06:14:26Z.

Review: COMMENTED


Tested on macOS 27.2 on an Apple M4. This is an x86-64 build under Rosetta with Apple clang 21.0.0.

Method. I compared four builds: main at a72186d3cf, this PR merged onto it, #21721 merged onto it, and both PRs merged onto it. All the merges were clean. On each build I ran the same 103 stream, scan and format tests three times:

ctest --test-dir build -R '(file_streams|scan|format|printf|stdio|wide|fwrite|fputs|stream)' -j4 --timeout 300 --output-on-failure

file_streams, identical in all 3 runs of each build:

Build Result
main Fails: Stream scan changed a matching failure to input failure
this PR alone Fails later: File stream check failed
#21721 alone Fails: Stream scan changed a matching failure to input failure
this PR + #21721 Passes

This confirms the description. This PR fixes the scan check, and file_streams passes only once #21721 is also merged.

Other tests in the set. There were no regressions.

  • guest_libc_internal_wide_ctype aborts and guest_libc_internal_standard_stream_init is Not Run on every build, main included.
  • Two tests timed out once each, at ctest's 20 s per-test limit under -j4, and passed in every other run: guest_system_service_date_time_format on #21721 alone and code_data_scanning on both PRs together. Neither test is touched by these PRs.

I didn't test this on Linux or Windows.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5933864794 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21720#pullrequestreview-5933864794). Originally posted by [kurexw](https://github.com/kurexw) on 2026-11-17T06:14:26Z. **Review:** COMMENTED --- Tested on macOS 27.2 on an Apple M4. This is an x86-64 build under Rosetta with Apple clang 21.0.0. **Method.** I compared four builds: `main` at a72186d3cf, this PR merged onto it, #21721 merged onto it, and both PRs merged onto it. All the merges were clean. On each build I ran the same 103 stream, scan and format tests three times: ``` ctest --test-dir build -R '(file_streams|scan|format|printf|stdio|wide|fwrite|fputs|stream)' -j4 --timeout 300 --output-on-failure ``` **`file_streams`, identical in all 3 runs of each build:** | Build | Result | | --- | --- | | main | Fails: `Stream scan changed a matching failure to input failure` | | this PR alone | Fails later: `File stream check failed` | | #21721 alone | Fails: `Stream scan changed a matching failure to input failure` | | this PR + #21721 | Passes | This confirms the description. This PR fixes the scan check, and `file_streams` passes only once #21721 is also merged. **Other tests in the set.** There were no regressions. - `guest_libc_internal_wide_ctype` aborts and `guest_libc_internal_standard_stream_init` is Not Run on every build, `main` included. - Two tests timed out once each, at ctest's 20 s per-test limit under `-j4`, and passed in every other run: `guest_system_service_date_time_format` on #21721 alone and `code_data_scanning` on both PRs together. Neither test is touched by these PRs. I didn't test this on Linux or Windows.
MarcZX10 commented 2026-11-23 06:15:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T06:15:01Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the implementation handles the described malformed float prefixes, and no concrete blocking defect was verified.

What I ran

Reviewed head a92c9bb5d44edb8f01b2614a1b66311dc6af0d6e using the prepared review bundle and the pinned repository reader. No build or tests were run.

Results

Check Result Note
Changed code review passed One changed source file read
Build and tests not run Author reports results in the PR description

Findings

Blocking

None.

Non-blocking

None.

Not verified

Tests and build were not run independently. The PR description reports macOS build and test results; those are author-reported. Only core/libs/prx/libc/src/Formatting.cpp was changed and read. No files were excluded according to the manifest; review/files.json was not available as a review document.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6017287652 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21720#pullrequestreview-6017287652). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-23T06:15:01Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the implementation handles the described malformed float prefixes, and no concrete blocking defect was verified. ## What I ran Reviewed head `a92c9bb5d44edb8f01b2614a1b66311dc6af0d6e` using the prepared review bundle and the pinned repository reader. No build or tests were run. ## Results | Check | Result | Note | |---|---|---| | Changed code review | passed | One changed source file read | | Build and tests | not run | Author reports results in the PR description | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified Tests and build were not run independently. The PR description reports macOS build and test results; those are author-reported. Only `core/libs/prx/libc/src/Formatting.cpp` was changed and read. No files were excluded according to the manifest; `review/files.json` was not available as a review document. ## To get this to a good state Nothing is required.
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!21720
No description provided.