Details
Description
If you try to write data QFile and size of data is a multiple of
std::numeric_limits<quint32>::max() + 1
QFile::write will always write 0 bytes.
Reason is here (qfsfileengine_win.cpp):
qint64 QFSFileEnginePrivate::nativeWrite(const char *data, qint64 len) { ... qint64 bytesToWrite = DWORD(len); // <- lossy // Writing on Windows fails with ERROR_NO_SYSTEM_RESOURCES when // the chunks are too large, so we limit the block size to 32MB. static const DWORD maxBlockSize = 32 * 1024 * 1024; ... }
How you can see given data size value will be cut to a 32 bit value. So in case last 32 bit of value are zero, the value will be always cut to a zero value. But it is not necessary to cut this value before, because this function will always split data into 32MB chunks. So it is an unnecessary behavior.
Demo code:
#include <QDebug> #include <QFile> int main(int argc, char *argv[]) { std::vector<char> dummyData(static_cast<size_t>(std::numeric_limits<quint32>::max()) + 1); QFile file("test_data.dat"); if (file.open(QIODevice::WriteOnly)) { //recommended is a loop in case not all bytes are written, but this would cause an endless loop here qDebug() << file.write(dummyData.data(), dummyData.size()); // Output => 0 } return 0; }
Attachments
Issue Links
- relates to
-
QTBUG-56616 REG 5.6.1->5.6.2 [Windows]: QFile::write() does not write all data for data > 32MB
- Closed