https://bugs.winehq.org/show_bug.cgi?id=47832
Bug ID: 47832 Summary: FindFirstFileExW believes every directory entry has been read if NtQueryDirectoryFile underfills buffer Product: Wine Version: unspecified Hardware: x86 OS: Linux Status: UNCONFIRMED Severity: normal Priority: P2 Component: kernel32 Assignee: wine-bugs@winehq.org Reporter: qsniyg@mail.com Distribution: ---
When using USVFS (through ModOrganizer 2), it will hook NtQueryDirectoryFile, and its implementation will occasionally underfill the buffer, even if there are more directory entries to be read.
Due to this check in FindFirstFileExW:
if (!has_wildcard || info->data_len < info->data_size - max_entry_size) { ... info->data_size = 0; /* we read everything */ }
It will stop FindNextFileW from reading more. Windows doesn't seem to exhibit this behavior.
Removing the `info->data_len < info->data_size - max_entry_size` check allows it to work properly.
Unfortunately I wasn't able to find any reference to why that check exists. My best guess after looking through the source code is that it's an optimization, as the code should still run fine if wine's NtQueryDirectoryFile implementation underfills the buffer (therefore indicating that there are no more files needed to be read).
So far I've tested many various applications with the check patched out, with no obvious regressions.