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

"Graph" example's use of QResource is dangerous

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • 5.3.0 Beta1
    • 5.2.0
    • None
    • Linux 32bit, Linux 64bit, Open embedded linux (arm 32bit)
    • 74c814ef636dedcee1df4dec474b293bdf2b094c

    Description

      I've based some materials in a larger application on the use of QSGSimpleMaterialShader in the graph example classes NoisyShader and LineShader.

      The example returns the shader source code like this:

          const char *vertexShader() const {
              QResource r(":/scenegraph/graph/shaders/line.vsh");
              Q_ASSERT(r.isValid());
              return (const char *) r.data();
          }
      
          const char *fragmentShader() const {
              QResource r(":/scenegraph/graph/shaders/line.fsh");
              Q_ASSERT(r.isValid());
              return (const char *) r.data();
          }
      

      However, looking into the actual resource qrc_xxx.cpp file, the data is not null-terminated. So in some cases, especially when a shader file is the last one in the cpp file, the code reading the (const char*) will read beyond until it hits some other null termination. Shader compilation fails, and the application will crash somewhere in the scenegraph render thread.

      Seems like this goes well for shader files not being the last in the list, because the header field for the next file is a 4 byte size where the first byte tends to be zero. I'm just guessing.

      Another issue is that the data in the resource file could be compressed, but the example code assumes it is not.

      Attachments

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

        Activity

          People

            sletta Gunnar Sletta
            pyrrhula Ola Røer Thorsen
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes