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

QFSFileEngine "stat cache" bug (resize then map == invalid warning)

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 4.7.1
    • Core: I/O
    • None

    Description

      I was surprised to receive a warning from this code.

      bool ok = storage->resize(offset + size);
      Q_ASSERT(ok);
      uchar *data = storage->map(offset, size);
      

      The warning is this:

      QFSFileEngine::map: Mapping a file beyond its size is not portable
      

      This isn't mapping the file beyond its size. I looked into the code and found a problem with the stat cache.

      QFSFileEngine caches stat results (which is probably a good thing) but it does not invalidate this cache when resizing the file. Hence, in my case, the file was stat'ed before it was resized so the map function was checking an invalid size.

      Closing and re-opening the file can be used as a workaround.

      Ideally the file engine would invalidate the stat cache (set d->tried_stat to false) so that another stat is done after file is resized. It may even be safe to just update the stat structure with the new size.

      Attachments

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

        Activity

          People

            Unassigned Unassigned
            lramsay Lincoln Ramsay (closed Nokia identity) (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes