Bug 14469 – file.readText on Win64 doesn't work for files > 4GB.
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Windows
Creation time
2015-04-20T06:40:00Z
Last change time
2017-07-19T17:43:27Z
Assigned to
nobody
Creator
artemalive
Comments
Comment #0 by artemalive — 2015-04-20T06:40:11Z
In DMD 2.067 this function calls read(in char[], size_t) which in turns uses GetFileSize like this:
auto size = trustedGetFileSize(h, null);
One solution is to pass not null second parameter but it seems that it's even better to use GetFileSizeEx (us/library/windows/desktop/aa364957(v=vs.85).aspx).
Comment #1 by artemalive — 2015-04-21T19:49:12Z
Additionally since ReadFile (and ReadFileEx too) can read file in chunks not larger than 4GB the file reading code should be updated to something like this:
ulong totalNumRead = 0;
while (totalNumRead != size)
{
uint chunkSize = (size - totalNumRead) & 0xffffffff;
DWORD numRead = void;
cenforce(ReadFile(hFile, cast(ubyte*)lpBuffer + totalNumRead, chunkSize, &numRead, null) != 0
&& numRead == chunkSize, name);
totalNumRead += chunkSize;
}
Comment #2 by artemalive — 2015-04-21T21:51:37Z
The above algorithm for reading file has a bug. chunkSize should be calculated like this:
uint chunkSize = min(size - totalNumRead, 0xffffffff);
Comment #3 by github-bugzilla — 2015-05-25T07:48:53Z