Repository navigation
Handle STATUS_OBJECT_NAME_NOT_FOUND in Windows directory enumeration (#130134) - #8
jeffhandley wants to merge 1 commit into
Conversation
| // When an OS-level filter (FileName) is passed to NtQueryDirectoryFile and nothing matches, most file | ||
| // system drivers report STATUS_NO_SUCH_FILE (handled above as STATUS_FILE_NOT_FOUND). Some drivers report | ||
| // STATUS_OBJECT_NAME_NOT_FOUND for the same "no matching entries" condition instead- notably the read-only | ||
| // zip mount used by Azure App Service's run-from-package deployments. The directory handle was already | ||
| // opened successfully, so this can only mean the filter matched nothing; treat it the same as no matches. | ||
| case Interop.StatusOptions.STATUS_OBJECT_NAME_NOT_FOUND: |
There was a problem hiding this comment.
The comment should begin with "STATUS_OBJECT_NAME_NOT_FOUND occurs when..." to match the other comments.
There was a problem hiding this comment.
And don't name Azure App Service's run-from-package deployments specifically. Reference the more generalized scenario.
There was a problem hiding this comment.
Done in the amended commit (354b8e0). The comment now begins with STATUS_OBJECT_NAME_NOT_FOUND occurs when... to match the sibling comments, and no longer names Azure run-from-package specifically — it references the generalized "read-only or virtual file systems" scenario instead.
Note
Reply generated by GitHub Copilot.
Then you need to prove it. Show the evidence. |
Add STATUS_OBJECT_NAME_NOT_FOUND (0xC0000034) to the no-matches branch of FileSystemEnumerator<T>.GetData() on Windows, alongside STATUS_FILE_NOT_FOUND. A filtered NtQueryDirectoryFile that matches zero entries can return this status instead of STATUS_NO_SUCH_FILE on some file systems (for example, certain read-only or virtual file systems); it is now treated as an empty result instead of throwing FileNotFoundException. Fixes dotnet#130134 Co-authored-by: Copilot <[email protected]>
d02c35e to
354b8e0
Compare
|
Added the evidence to the PR description under Evidence that the culprit is In short: the reported message is Note Reply generated by GitHub Copilot. |
Summary
Addresses
dotnet/runtime#130134:Directory.GetFiles/EnumerateFileswith a zero-match search pattern throwsFileNotFoundException(naming the directory itself) on a read-only, run-from-package (zip-mounted) content root, instead of returning an empty array. Regression introduced in 10.0.9 bydotnet/runtime#127974.Root cause
dotnet/runtime#127974began passing the search pattern toNtQueryDirectoryFileas an OS-levelFileNamefilter. When zero entries match,FileSystemEnumerator<T>.GetData()'sswitchonly handlesSTATUS_NO_SUCH_FILE(0xC000000F). Some file system drivers report the same "no matching entries" condition asSTATUS_OBJECT_NAME_NOT_FOUND(0xC0000034), which fell through to thedefaultcase →ERROR_FILE_NOT_FOUND→throw.Evidence that the culprit is
STATUS_OBJECT_NAME_NOT_FOUNDThe
defaultarm ofGetData()turns the rawNTSTATUSinto the thrown exception in two hops:Hop 2 —
Win32Marshal.GetExceptionForWin32Error(src/libraries/Common/src/System/IO/Win32Marshal.cs) selects the exception type and message purely from the Win32 error code:ERROR_FILE_NOT_FOUND(2)FileNotFoundExceptionIO_FileNotFound_FileName="Could not find file '{0}'."ERROR_PATH_NOT_FOUND(3)DirectoryNotFoundExceptionIO_PathNotFound_Path="Could not find a part of the path '{0}'."The report is
System.IO.FileNotFoundException: Could not find file '<dir>'— exactly theERROR_FILE_NOT_FOUND(2) branch. So the rawNTSTATUSmust be one that hop 1 (RtlNtStatusToDosError, an ntdll OS function — the mapping is defined by Windows, not .NET) translates to2, and that is not already handled by theswitch.RtlNtStatusToDosErrortranslations for the relevant statuses (values verified by calling it directly):RtlNtStatusToDosErrorSTATUS_SUCCESS0x00000000ERROR_SUCCESS(0)STATUS_NO_MORE_FILES0x80000006ERROR_NO_MORE_FILES(18)STATUS_NO_SUCH_FILE(akaSTATUS_FILE_NOT_FOUND)0xC000000FERROR_FILE_NOT_FOUND(2)STATUS_OBJECT_NAME_INVALID0xC0000033ERROR_INVALID_NAME(123)STATUS_OBJECT_NAME_NOT_FOUND0xC0000034ERROR_FILE_NOT_FOUND(2)STATUS_OBJECT_PATH_NOT_FOUND0xC000003AERROR_PATH_NOT_FOUND(3)Only two
NTSTATUSvalues map toERROR_FILE_NOT_FOUND(2):STATUS_NO_SUCH_FILE(already handled, so it can't produce the throw) andSTATUS_OBJECT_NAME_NOT_FOUND. Therefore0xC0000034is the only possible culprit.STATUS_OBJECT_PATH_NOT_FOUND(0xC000003A) is ruled out: it maps toERROR_PATH_NOT_FOUND(3), which hop 2 turns into aDirectoryNotFoundExceptionwith"Could not find a part of the path '{0}'."— a different exception type and message than the report.Empirically, a direct
NtQueryDirectoryFileP/Invoke with a zero-match filter returns the handledSTATUS_NO_SUCH_FILE(0xC000000F) on NTFS, ReFS, UDF, and CDFS — so the built-in drivers don't hit this, and it takes a driver that returns0xC0000034(as reported for the read-only zip mount) to trigger it.Change (this branch — recommended)
Add
case STATUS_OBJECT_NAME_NOT_FOUNDto the existing no-matches branch inGetData()(Windows), alongsideSTATUS_FILE_NOT_FOUND. The directory handle was already opened successfully inInit(), so this status can only mean the filter matched nothing — consistent with how the sibling0xC000000F/0xC0000033statuses are already handled. The constant already exists inInterop.NtStatus.cs.Validation
ntdll!NtQueryDirectoryFilerewrites the zero-match status0xC000000F→0xC0000034for a single sentinel directory only, exactly mirroring the reported driver behavior (inline hooking defeats the CLR's cached P/Invoke pointer, so it works on shipped and locally built runtimes alike).dotnet-install, x64 + ARM64): 10.0.7 / 10.0.8 return empty; 10.0.9 throws; the .NET 11 branch throws unfixed and returns empty with this fix (the driver still returns0xC0000034, now handled).System.IO.FileSystem.Tests— no regressions. Enumeration namespace 134/134; GetFiles/EnumerateFiles/GetFileSystemEntries 234 pass. The only suite failures are pre-existing admin-required volume-mount tests, which fail identically on baseline.Alternatives
Two alternative approaches were captured as peer PRs for comparison:
jeffhandley/directory-getfiles-error-mapping(closed) — translateNTSTATUS→Win32 error and treatERROR_FILE_NOT_FOUNDas no-matches.jeffhandley/directory-getfiles-unfiltered-fallback— retry unfiltered onSTATUS_OBJECT_NAME_NOT_FOUND, reverting to enumerate-all-then-filter. Note the affected drivers do honor the filter (a matching pattern returns results; only zero-match reports the status), so falling back to unfiltered enumeration would re-introduce the O(all-entries) managed scan for the zero-match case thatdotnet/runtime#127974set out to avoid.Note
This pull request (including its description) was created by GitHub Copilot.