Hello.
I found out an interesting thing. NtQueryDirectoryFile may return wrong
amount of data returned if it is called from a directory from a FAT volume
and ReturnSingleEntry parameter is FALSE.
//
// Let’s say we open '??\C:' and it is a FAT volume.
// We prepared ‘ObjectAttributes’ beforehand.
//
HANDLE file = NULL;
NtCreateFile(
&file,
SYNCHRONIZE | FILE_READ_DATA,
&ObjectAttributes,
&IoStatusBlock,
NULL,
FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_READ | FILE_SHARE_WRITE,
FILE_OPEN,
FILE_DIRECTORY_FILE,
NULL,
0);
WCHAR templname = L"*";
UNICODE_STRING templateString;
templateString.Buffer = templname;
templateString.MaximumLength = sizeof(templname);
templateString.Length = sizeof(templname) - sizeof(WCHAR);
//
// Suppose that buffer will be enough for all data returned…
//
char buf[0x10000];
memset(buf, 0x5a, sizeof(buf));
NTSTATUS status =
NtQueryDirectoryFile(
file,
0,
0,
0,
&IoStatusBlock,
buf,
sizeof(buf),
FileBothDirectoryInformation,
FALSE,
&templateString,
TRUE);
The function succeeds. The buffer is filled properly but
IoStatusBlock.Information is set to a value two or four bytes less than
amount of data written to the buffer. As result the last file name is
truncated.
I was able to repeat this for FileDirectoryInformation,
FileFullDirectoryInformation, FileBothDirectoryInformation and
FileNamesInformation classes. NTFS, CDFS, UDF work properly.
OS: Win XP Professional, SP1.
Does anyone came across with it before?
Best regards,
Alexey.