Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-54870

QFSFileEngine (Win) not able to write data in some cases

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 5.6.2
    • 5.7.0
    • Core: I/O
    • None
    • Windows
    • 0696566b1e19c8178e00c0d14f185935e17d9e8b (qtbase/5.6, 21.7.2016, 5.6.2)

    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

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              kleint Friedemann Kleint
              EliteScience Heiko Thiel
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes