Repository navigation
fix(libc): report EISDIR when a secure stream scan reads a directory stream - #23974
Merged
oneandonlydean merged 1 commit intoNov 20, 2026
Conversation
…stream fscanf, vfscanf, fgetc, fgets and fread keep EISDIR when a read of a directory stream fails. fscanf_s, vfscanf_s, scanf_s and vscanf_s went through ScanGuestStream, which skipped that step for the secure forms, so they failed with the host's errno instead. Keep the error for them too. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
PrivacyOnion
approved these changes
Nov 20, 2026
PrivacyOnion
left a comment
Contributor
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against cf8a9634da:
- Conventions:
tools/check_conventions.pypassed. - Build:
guest_filesystem_testsbuilt cleanly. - CTest (
guest_filesystem):1/1 Test #5591: guest_filesystem ................. Passed 0.64 sec 100% tests passed, 0 tests failed out of 1 - Negative control: with
core/libs/prx/libc/src/Formatting.cppreverted tomainand the new tests kept, the suite fails:Restoring the change makes it pass again.1/1 Test #5591: guest_filesystem ................. Passed 0.15 sec 100% tests passed, 0 tests failed out of 1 - Code reading:
- Verified ScanGuestStream in Formatting.cpp: removed !secure check so stream->KeepDirectoryReadError(result == -1) runs uniformly for secure and non-secure scan routines.
- Verified FileStream::KeepDirectoryReadError behavior: only triggers when failed is true, stream is marked as directory stream, and error indicator is set, ensuring regular files and ordinary constraint failures are unaffected.
- Verified POSIX error behavior and error code 21 (EISDIR) when attempting to read from directory streams across fscanf, fscanf_s, and other stdio stream readers.
- Verified AGENTS.md compliance: no comments added, clean conventions, no magic constants or single-title workarounds.
- Verified GuestFilesystem.cpp test coverage: properly checks fscanf_s returning -1, errno == 21, and ferror != 0 across directory open modes, matching existing fscanf test semantics.
Looks Good To Me
12 tasks done
12 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
fscanf_s,vfscanf_s,scanf_sandvscanf_sdid not reportEISDIRwhen they read a directory stream.fscanf_s(directoryStream, "%d", &value)returnedEOFand set the error indicator, buterrnokept whatever the host's failed read left instead of 21.The
fopendebt entry states the rule: "reading a directory stream fails withEISDIRand sets the error indicator on every host". Every other reader applies it throughFileStream::KeepDirectoryReadError:fread,fgetc,fgets, and the plainfscanfandvfscanf, withfscanfpinned inGuestFilesystem.cpp. The secure stream forms shareScanGuestStream, whose line wasif (!secure) stream->KeepDirectoryReadError(result == -1);, so they alone skipped it. That condition came with thesecureparameter and only kept what the secure path did before the directory handling existed; nothing in the debt or the tests says the secure forms should differ.This PR removes the condition.
KeepDirectoryReadErroronly acts when the scan failed, the stream is a directory stream and its error indicator is set, so nothing changes for ordinary streams or for a secure scan that fails on a runtime-constraint violation of an ordinary stream.Tested
Windows 11 IoT Enterprise LTSC 2024 (10.0.26100), WinLibs GCC 15.2.0 r7, Release,
BUILD_TESTING=ON.core/libs/tests/GuestFilesystem.cppright after thefscanfone, on the same directory stream and in each of the three open modes the test loops over:fscanf_sreturns -1 witherrno21 and the error indicator set.maindb8edcf4c8andFormatting.cppunchanged,guest_filesystemaborts.guest_filesystempasses, andctest -R "^guest_(filesystem|standard_stream|file|wide|.*scan|.*format|stdio|stream)|file_stream|^file_|^formatting"passes 48 of 48 after a full rebuild.python tools/check_conventions.py --base origin/mainpasses. No debt change: the entry already describes the behaviour this PR makes true.python tools/pr_overlap.py --branch fix/libc-secure-stream-scan-directory-errorfound no overlap among the pull requests it could compare (2027 open); it could not compare fix(libc): follow snprintf_s and sscanf_s constraints as measured on a PS5 #9087, feat(libc): decode non-ASCII scanset members and non-BMP characters in the guest wide scanf #9340 and fix(libc): bound narrow formatting fields #11332 (Formatting.cpp) and feat(libkernel_sys): implement mount, unmount and nmount privilege checks #15037 (GuestFilesystem.cpp), which conflict withmain. Compared by hand, none of them touchesScanGuestStream,KeepDirectoryReadErroror the directory-stream checks.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)