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

Windows: QTextStream::readLine crashes when QTextCodec::codecForLocale() returns NULL

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • None
    • 5.4.1
    • None
    • Windows XP and wine after cross-compiling with MXE (http://mxe.cc/), but probably all other systems as well.

    Description

      This is similar to QTBUG-38496. Programs crash when trying to use QTextStream::readLine, Qt was built without QT_NO_TEXTCODEC, and no proper codecs are found (as seems to happen when building with (some versions of) icu). A minimal test case (assuming a file named "test.txt" exists):

      #include <QtGui>
      #include <iostream>
      int main(int argc, char *argv[])
      {
              QFile fin("test.txt");
              if (!fin.open(QIODevice::ReadOnly | QIODevice::Text))
                      return 1;
              QTextStream ts(&fin);
              std::cout << qPrintable(ts.readLine());
              return 0;
      }
      

      In QTextStreamPrivate::fillReadBuffer(), if no codec is found, it is set to QTextCodec::codecForLocale() (line 451), which may return NULL. On line 472, this is used in codec->toUnicode(...) without checking if codec is NULL, thus crashing the application. I suspect there are other places where the same might happen, but I haven't investigated.

      For a test program to check which codecs are found, see QTBUG-38496.

      Attachments

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

        Activity

          People

            laknoll Lars Knoll
            st.loeffler Stefan Löffler
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes