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
Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/95fd043dc6d0c945c171f8874761e1399a11252c Fix Issue 14469 - read > 4GB file on Windows x64. https://github.com/D-Programming-Language/phobos/commit/75f068773ccc0750c2cf865fe2f621a9947723f3 Merge pull request #3218 from artemalive/issue_14469 Fix Issue 14469 - read > 4GB file on Windows x64.
Comment #4 by github-bugzilla — 2017-07-19T17:43:27Z
Commits pushed to dmd-cxx at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/95fd043dc6d0c945c171f8874761e1399a11252c Fix Issue 14469 - read > 4GB file on Windows x64. https://github.com/dlang/phobos/commit/75f068773ccc0750c2cf865fe2f621a9947723f3 Merge pull request #3218 from artemalive/issue_14469