fix(libc): preserve errno on stream scan input exhaustion #13025
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/13025"
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 JJenkx on 2026-10-29T22:11:29Z.
What
On glibc, scanning an empty or whitespace-only file can return
EOFand clear a previously seterrno. Two title-bundled libc modules preserve that errno. Restore the incoming errno inHostVfscanfonly when the host returnsEOFwith errno zero; preserve newly reported nonzero errors. Other host branches are unchanged.The fixture exercises
fscanfandvfscanf, empty/whitespace input, errno seeds 0/22/97, ordinary and suppressed conversions, unchanged destinations, EOF/error indicators, and an overflowing float that must retainERANGE.This is the separately measured file-stream follow-up suggested during review of #13012. It does not include or depend on that string-scanning change.
Tested
Linux x86-64, GCC Release. Exact head
30d5439075e33df009d3cd3cee47a9d8b8f1cedc, base52f212ec053f917455f2f87674ddb708dcc545d8; merge preview clean against subsequently fetched main4c8cff191609bc5f28bf9ee2f93672b531285aa4.file_streams_testsagainst frozen unmodified base libraries fails withStream scan input exhaustion changed errno(CTest exit 8).fdopenon duplicated private temporary-file descriptors. No SDK instructions are patched; the probe rejects loaded Vulkan/AGC/VideoOut modules. This is neither console nor native-game qualification.Authored probe, synthetic rows, exact hashes, test logs and negative control, SHA-256
b1ee388525a747e82742c547fb75700ccac234186f7ac9e857373529b1085b7e. No proprietary modules/assets are included.Windows/macOS execution is not locally qualified; there is no title, graphics, audio or FPS claim.
Current qualification — 2026-10-30
Added a real read-error regression at
ff736bd24ae73dfa54f1f27fca96419cba3b0195for both fscanf and vfscanf. A readable FILE backed by a write-only descriptor forces a read syscall failure; with seeded errno97, the test requires EOF, errno different from97, unchanged destination, and ferror set. The row is guarded by GLIBC, matching the workaround's platform scope. Plain fopen("wb") rejects the mode before a read and leaves ferror clear on this glibc, so it cannot serve as this regression.Production is unchanged from
30d5439075e33df009d3cd3cee47a9d8b8f1cedc. Four focused Linux suites passed three repeats before the mutant and three after restoring the exact implementation (24 passes), plus public_headers and conventions. The unconditional EOF errno-restore mutant fails with "Stream scan lost its read error". Restored libc SHA256 equals the qualified positive binary. No skips.No new Windows/macOS/native SDK/title claim.
Evidence: immutable source and qualification receipts, SHA-256
69989f6c49c749dc948af7261b6751d07c30fe58c6610140798687195932284b(download verified).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 rooklz on 2026-10-29T22:22:36Z.
Review: APPROVED
Checked on head
30d5439075, on macOS host, without the console.4c8cff1916:git merge-treeis clean,git diff --checkis clean andcheck_conventions.py --base upstream/mainpasses. #13012 (8a7cd7d35a) also merges cleanly on top, so the two can land in either order.pr_overlap.py: 1444 PRs probed, 21 share files and all 21 merge. Only #7386/#8150/#10324/#11332/#11726/#11831/#12057 could not be compared because they already conflict with main. That matches the list in the body.HostVfscanfshape ontmpfile()streams. The grid was 5 inputs (""," ","\n\t ",abc,1e99999) × 6 formats (%d %*d %f %s x%d %c) × errno seeds 0/22/97, so 90 rows:vfscanfclears errno in 24/90 rows, all of them EOF rows. With the PR guard it is 0/90.1e99999with%fstill returns 1 with ERANGE for every seed.#elsebranch needs no change.if (result == EOF)restores errno even when there is a real error. All 90 grid rows still pass, but a read on a write-only stream (/dev/nullopened "w") then returns −1 with errno 97 instead of EBADF (9). The PR test has no read-error row, so this mutant survives it. Optional extra row: scan a stream opened for writing only, seed errno with 97, and expect EOF,errno != 97andferrorset. On glibc this row tells the PR guard apart from the unconditional mutant.if (errno == 0)without the EOF check behaves the same as the PR on every row I tried. Keeping the EOF check is still the right, narrower choice.fscanf_nid_postfix(L479),vfscanf_nid_postfix(L808) andHostFscanfall go throughHostVfscanf. After it,KeepDirectoryReadErroronly writes errno=21 on the directory path, so it does not undo the guard. Windows usesScanFileWindows_nid_no_patchand is left unchanged; that CI lane is still pending.Approving. The read-error row is optional.