fix(libc): fail a stream float scan of an empty hex prefix or a truncated infinity on macOS #21720
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/21720"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by XIIYAZ on 2026-11-16T16:48:20Z.
What
On macOS,
file_streamsaborts in its stream scan checks: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%1coutput and the count stay untouched. Two inputs come back differently on macOS:0xxread by%1cinfiiread by%1cWith a narrow character conversion in the format,
ScanGuestStreamparses each float field with the host'sfscanf. For a string source,CheckHexPrefixalready 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 after0and afterinfand leaves the rest.StreamSource::MalformedFloatAheadnow 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:0x(or0X) followed by neither a hex digit nor.(including the end of the input or of the field width)infithat does not go on toinfinity(any case)Any other input goes to the host scan as before, including
0x.andnan(, which the same test compares with the host's ownfscanf.file_streamsalso needs #21721 (a failed unbuffered write resent its byte) to pass on macOS.Tested
-DBUILD_TESTING=ON, x86_64 under Rosettafile_streamspasses. Before, it aborted on0x, and with only the0xcase handled, oninfi.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 4run and pass alone.python3 tools/check_conventions.py --base origin/mainpasses.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)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:
mainata72186d3cf, 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:file_streams, identical in all 3 runs of each build:Stream scan changed a matching failure to input failureFile stream check failedStream scan changed a matching failure to input failureThis confirms the description. This PR fixes the scan check, and
file_streamspasses only once #21721 is also merged.Other tests in the set. There were no regressions.
guest_libc_internal_wide_ctypeaborts andguest_libc_internal_standard_stream_initis Not Run on every build,mainincluded.-j4, and passed in every other run:guest_system_service_date_time_formaton #21721 alone andcode_data_scanningon both PRs together. Neither test is touched by these PRs.I didn't test this on Linux or Windows.
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
a92c9bb5d44edb8f01b2614a1b66311dc6af0d6eusing the prepared review bundle and the pinned repository reader. No build or tests were run.Results
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.cppwas changed and read. No files were excluded according to the manifest;review/files.jsonwas not available as a review document.To get this to a good state
Nothing is required.