libc: track reported wide scanf incomplete-field and literal-EOF differences #9321

Closed
opened 2026-10-21 18:23:37 +00:00 by UnhealthyKraken · 4 comments
UnhealthyKraken commented 2026-10-21 18:23:37 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by UnhealthyKraken on 2026-10-21T18:23:37Z.


Three differences reported in merged #8479 remain reproducible in the shared wide scanner on current main b00235dda0bdf5101c6af181416e57529e5fa2ba.

These are independently reproduced Windows implementation results, compared with the original author's reported firmware differential evidence. I have not run these cases on a PS5 or loaded a firmware module. This issue tracks the remaining behavior and evidence needed for a focused fix; it does not claim independently verified PS5 regressions.

Input and format Current Windows result Evidence reported in #8479
1e+, %lf, destination initialized to -99 Returns 0, destination remains -99, input is consumed through EOF Scanner converts the mantissa of the incomplete exponent
a, %3lc, destination filled with 0xa55a Returns 0, destination remains untouched, input is consumed through EOF Scanner stores a short %c field
Empty input, literal format x Returns EOF (-1) Scanner returns 0 when a literal meets EOF

The original author's Remaining differences section explicitly says the buffer scanner has the same differences. The exact return count, partial-output extent, and precedence for each surrounding format should be confirmed before changing behavior, particularly after earlier assignments, suppressed fields, width limits and secure-capacity failures. The author describes a module/scanner harness; this should not be conflated with executing a title or these particular cases on hardware.

Reproduced through patched NID exports for all eight stream forms:

Export NID
fwscanf a6CYO8YOzfw
fwscanf_s Bo5wtXSj4kc
vfwscanf WF4fBmip+38
vfwscanf_s Wvm90I-TGl0
wscanf D8JBAR3RiZQ
wscanf_s RV7X3FrWfTI
vwscanf QNwdOK7HfJU
vwscanf_s YgZ6qvFH3QI

Minimal equivalent diagnostics can be inserted into core/libs/tests/GuestWideStreamScan.cpp, using its existing Open and Close fixture and declarations:

FileStream* stream = Open("1e+");
double number = -99;
int result = fwscanf_nid_postfix(stream, u"%lf", &number);
std::printf("exponent: return=%d value=%g next=%d\n", result, number, fgetwc_nid_postfix(stream));
Close(stream);

stream = Open("a");
char16_t output[4] = {0xa55a, 0xa55a, 0xa55a, 0xa55a};
result = fwscanf_s_nid_postfix(stream, u"%3lc", output, 4u);
std::printf("short c: return=%d first=%x next=%d\n", result, static_cast<unsigned>(output[0]), fgetwc_nid_postfix(stream));
Close(stream);

stream = Open("");
result = fwscanf_nid_postfix(stream, u"x");
std::printf("literal EOF: return=%d\n", result);
Close(stream);

Own validation: Windows x86-64, WinLibs GCC 15.2 Release, isolated checkout. A separate native probe loaded the actual patched libc.prx and printed all three diagnostics through each of the eight forms; results were identical across ten runs. It also passed 8,882 current-model checks per run for integer argument registers/stack, guest store widths, %ln, suppression, secure capacities, canaries, stdin routing, null arguments and ASCII lookahead. The count includes repeated identical cases, not 8,882 unique firmware behaviors. The five existing suites guest_wide_stream_scan, guest_wide_conversion, guest_stdio_variadic, guest_wide_strings and guest_scan_count pass. These passing checks do not validate the three reported firmware expectations. No games, console runs or proprietary artifacts.

Scope/overlap: #8306 owns %S/%C matching failures in the same WideScanner; these three cases are separate but touch shared scanner/debt code, so coordinate ordering. #7386 handles 16-bit wide fields in the narrow scanf family on Linux. #8897 concerns wide stream encoding and remains separate. The current non-ASCII pushback limitation, locale behavior and atomic stream locking were not independently validated by this ASCII probe. No competing fix for these three cases was found in the current all-state searches; search results alone are not proof of absence.

There is no behavior fix in this report. A follow-up should first pin the expected edge cases with attributable evidence, add failing regressions, and compare identical baseline/candidate tests. AI-assisted investigation and report; I am responsible for the results stated here.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5966168837 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/9321). Originally posted by [UnhealthyKraken](https://github.com/UnhealthyKraken) on 2026-10-21T18:23:37Z. --- Three differences reported in merged #8479 remain reproducible in the shared wide scanner on current main `b00235dda0bdf5101c6af181416e57529e5fa2ba`. These are independently reproduced **Windows implementation results**, compared with **the original author's reported firmware differential evidence**. I have not run these cases on a PS5 or loaded a firmware module. This issue tracks the remaining behavior and evidence needed for a focused fix; it does not claim independently verified PS5 regressions. | Input and format | Current Windows result | Evidence reported in #8479 | |---|---|---| | `1e+`, `%lf`, destination initialized to `-99` | Returns 0, destination remains `-99`, input is consumed through EOF | Scanner converts the mantissa of the incomplete exponent | | `a`, `%3lc`, destination filled with `0xa55a` | Returns 0, destination remains untouched, input is consumed through EOF | Scanner stores a short `%c` field | | Empty input, literal format `x` | Returns `EOF` (-1) | Scanner returns 0 when a literal meets EOF | The original author's **Remaining differences** section explicitly says the buffer scanner has the same differences. The exact return count, partial-output extent, and precedence for each surrounding format should be confirmed before changing behavior, particularly after earlier assignments, suppressed fields, width limits and secure-capacity failures. The author describes a module/scanner harness; this should not be conflated with executing a title or these particular cases on hardware. Reproduced through patched NID exports for all eight stream forms: | Export | NID | |---|---| | `fwscanf` | `a6CYO8YOzfw` | | `fwscanf_s` | `Bo5wtXSj4kc` | | `vfwscanf` | `WF4fBmip+38` | | `vfwscanf_s` | `Wvm90I-TGl0` | | `wscanf` | `D8JBAR3RiZQ` | | `wscanf_s` | `RV7X3FrWfTI` | | `vwscanf` | `QNwdOK7HfJU` | | `vwscanf_s` | `YgZ6qvFH3QI` | Minimal equivalent diagnostics can be inserted into `core/libs/tests/GuestWideStreamScan.cpp`, using its existing `Open` and `Close` fixture and declarations: ```cpp FileStream* stream = Open("1e+"); double number = -99; int result = fwscanf_nid_postfix(stream, u"%lf", &number); std::printf("exponent: return=%d value=%g next=%d\n", result, number, fgetwc_nid_postfix(stream)); Close(stream); stream = Open("a"); char16_t output[4] = {0xa55a, 0xa55a, 0xa55a, 0xa55a}; result = fwscanf_s_nid_postfix(stream, u"%3lc", output, 4u); std::printf("short c: return=%d first=%x next=%d\n", result, static_cast<unsigned>(output[0]), fgetwc_nid_postfix(stream)); Close(stream); stream = Open(""); result = fwscanf_nid_postfix(stream, u"x"); std::printf("literal EOF: return=%d\n", result); Close(stream); ``` Own validation: Windows x86-64, WinLibs GCC 15.2 Release, isolated checkout. A separate native probe loaded the actual patched `libc.prx` and printed all three diagnostics through each of the eight forms; results were identical across ten runs. It also passed 8,882 current-model checks per run for integer argument registers/stack, guest store widths, `%ln`, suppression, secure capacities, canaries, stdin routing, null arguments and ASCII lookahead. The count includes repeated identical cases, not 8,882 unique firmware behaviors. The five existing suites `guest_wide_stream_scan`, `guest_wide_conversion`, `guest_stdio_variadic`, `guest_wide_strings` and `guest_scan_count` pass. These passing checks do not validate the three reported firmware expectations. No games, console runs or proprietary artifacts. Scope/overlap: #8306 owns `%S`/`%C` matching failures in the same `WideScanner`; these three cases are separate but touch shared scanner/debt code, so coordinate ordering. #7386 handles 16-bit wide fields in the narrow scanf family on Linux. #8897 concerns wide stream encoding and remains separate. The current non-ASCII pushback limitation, locale behavior and atomic stream locking were not independently validated by this ASCII probe. No competing fix for these three cases was found in the current all-state searches; search results alone are not proof of absence. There is no behavior fix in this report. A follow-up should first pin the expected edge cases with attributable evidence, add failing regressions, and compare identical baseline/candidate tests. AI-assisted investigation and report; I am responsible for the results stated here.
MarcZX10 commented 2026-10-21 18:36:50 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T18:36:50Z.


For the short %3lc case in #9321, could you share the observed firmware return value, exactly which destination elements are written, and whether any input remains? If the differential harness also covered _s, suppressed fields, or a prior assignment, those results would help pin the general rule. I have left that case out of the current patch until its contract is clear.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6323644704 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/9321#issuecomment-6323644704). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-21T18:36:50Z. --- For the short `%3lc` case in #9321, could you share the observed firmware return value, exactly which destination elements are written, and whether any input remains? If the differential harness also covered `_s`, suppressed fields, or a prior assignment, those results would help pin the general rule. I have left that case out of the current patch until its contract is clear.
UnhealthyKraken commented 2026-10-22 03:16:25 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by UnhealthyKraken on 2026-10-22T03:16:25Z.


I cannot supply a measured firmware return count or partial-write extent for %3lc: I did not run the console scanner. The firmware expectation in this report is attributed to the original author's Remaining differences in #8479, rather than an independent measurement by me.

My Windows observation for input a / %3lc was return 0, destination still filled with 0xa55a, and input consumed to EOF, including the secure stream form shown in the reproducer. That is the current implementation result, not the expected firmware contract. I have no firmware measurements for suppressed fields, prior assignments or secure-capacity precedence.

#9331 correctly leaves this case out and addresses the other two reported differences separately. Before adding a short-field behavior regression, the remaining evidence needed is the exact return count, written code units and guards, input position, and the same observations for _s, suppression and prior assignments. A source-only reproducer with summarized observations would establish that without publishing a firmware module. This issue should remain open for that case.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6331807113 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/9321#issuecomment-6331807113). Originally posted by [UnhealthyKraken](https://github.com/UnhealthyKraken) on 2026-10-22T03:16:25Z. --- I cannot supply a measured firmware return count or partial-write extent for `%3lc`: I did not run the console scanner. The firmware expectation in this report is attributed to the original author's Remaining differences in #8479, rather than an independent measurement by me. My Windows observation for input `a` / `%3lc` was return 0, destination still filled with `0xa55a`, and input consumed to EOF, including the secure stream form shown in the reproducer. That is the current implementation result, not the expected firmware contract. I have no firmware measurements for suppressed fields, prior assignments or secure-capacity precedence. #9331 correctly leaves this case out and addresses the other two reported differences separately. Before adding a short-field behavior regression, the remaining evidence needed is the exact return count, written code units and guards, input position, and the same observations for `_s`, suppression and prior assignments. A source-only reproducer with summarized observations would establish that without publishing a firmware module. This issue should remain open for that case.
hypermoist commented 2026-10-22 13:40:59 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by hypermoist on 2026-10-22T13:40:59Z.


@MarcZX10 here is the firmware contract for #9321. I'm the author of #8479. I measured these just now by loading PPSA03671's libc.prx (build J03848509) into a Linux process and calling its swscanf (0x73dc0) and swscanf_s (0x7bcc0) directly. Destinations were pre-filled with 0xa55a; %n shows how much input was consumed.

Input Format Return Destination / %n
a %3lc 1 0061 a55a a55a a55a: only element 0 written
ab %3lc 1 0061 0062 a55a a55a
abc %3lc 1 0061 0062 0063 a55a
a %3lc, swscanf_s with size 4 1 0061 a55a a55a a55a
a %*3lc 0 —
5 a %d %3lc 2 k=5, 0061 a55a a55a a55a
a %3lc%n 1 0061 …, n=1
1e+ %lf 1 value 1
1e+ %lf%n 1 value 1, n=3
1e+x %lf 1 value 1
0x1p- %lf 1 value 1
empty x 0 —
empty x 0 —
" " x 0 —
empty %% -1 —
5 %dx 1 k=5

So:

  • Short %Nlc: a short field stores what it read, writes nothing past it, and counts as an assignment. The _s form, a suppressed field, a prior assignment and %n behave consistently with that.
  • Incomplete exponent: 1e+ and 0x1p- convert the mantissa and consume the exponent marker and sign.
  • Literal at end of input: a literal that meets EOF returns the assignment count (0), but %% at EOF returns EOF.

The stream scanner gave the same results in my #8479 runs. I didn't repeat those today. This is the title's bundled libc.prx run natively, not a run on a console.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6342217421 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/9321#issuecomment-6342217421). Originally posted by [hypermoist](https://github.com/hypermoist) on 2026-10-22T13:40:59Z. --- @MarcZX10 here is the firmware contract for #9321. I'm the author of #8479. I measured these just now by loading PPSA03671's `libc.prx` (build J03848509) into a Linux process and calling its `swscanf` (0x73dc0) and `swscanf_s` (0x7bcc0) directly. Destinations were pre-filled with `0xa55a`; `%n` shows how much input was consumed. | Input | Format | Return | Destination / `%n` | |---|---|---|---| | `a` | `%3lc` | 1 | `0061 a55a a55a a55a`: only element 0 written | | `ab` | `%3lc` | 1 | `0061 0062 a55a a55a` | | `abc` | `%3lc` | 1 | `0061 0062 0063 a55a` | | `a` | `%3lc`, `swscanf_s` with size 4 | 1 | `0061 a55a a55a a55a` | | `a` | `%*3lc` | 0 | — | | `5 a` | `%d %3lc` | 2 | `k=5`, `0061 a55a a55a a55a` | | `a` | `%3lc%n` | 1 | `0061 …`, `n=1` | | `1e+` | `%lf` | 1 | value `1` | | `1e+` | `%lf%n` | 1 | value `1`, `n=3` | | `1e+x` | `%lf` | 1 | value `1` | | `0x1p-` | `%lf` | 1 | value `1` | | empty | `x` | 0 | — | | empty | ` x` | 0 | — | | `" "` | `x` | 0 | — | | empty | `%%` | -1 | — | | `5` | `%dx` | 1 | `k=5` | So: - **Short `%Nlc`:** a short field stores what it read, writes nothing past it, and counts as an assignment. The `_s` form, a suppressed field, a prior assignment and `%n` behave consistently with that. - **Incomplete exponent:** `1e+` and `0x1p-` convert the mantissa and consume the exponent marker and sign. - **Literal at end of input:** a literal that meets EOF returns the assignment count (0), but `%%` at EOF returns `EOF`. The stream scanner gave the same results in my #8479 runs. I didn't repeat those today. This is the title's bundled `libc.prx` run natively, not a run on a console.
UnhealthyKraken commented 2026-10-22 14:20:25 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by UnhealthyKraken on 2026-10-22T14:20:25Z.


The new results settle the expected outcomes for these cases in the bundled library/build you identified. I have recorded them as contributor-reported native execution of that bundled libc.prx, rather than a console run or proof across firmware versions. Current source still rejects a short %Nlc field and an incomplete floating exponent, so this issue remains actionable. #8479 is already merged and explicitly left these shared-scanner differences for follow-up; I will keep the remaining contract/regression work here instead of opening a duplicate issue. The short-field bounds, consumed %n, suppressed/secure forms, and literal-versus-%% EOF distinction all need to stay separate in that follow-up.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6343064868 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/9321#issuecomment-6343064868). Originally posted by [UnhealthyKraken](https://github.com/UnhealthyKraken) on 2026-10-22T14:20:25Z. --- The new results settle the expected outcomes for these cases in the bundled library/build you identified. I have recorded them as contributor-reported native execution of that bundled `libc.prx`, rather than a console run or proof across firmware versions. Current source still rejects a short `%Nlc` field and an incomplete floating exponent, so this issue remains actionable. #8479 is already merged and explicitly left these shared-scanner differences for follow-up; I will keep the remaining contract/regression work here instead of opening a duplicate issue. The short-field bounds, consumed `%n`, suppressed/secure forms, and literal-versus-`%%` EOF distinction all need to stay separate in that follow-up.
Sign in to join this conversation.
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#9321
No description provided.