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

QImage::scanline results in partial invalid last row for some images

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • P2: Important
    • None
    • 5.15.8
    • GUI: Painting
    • None
    • Linux/Wayland, Linux/X11, Windows

    Description

      I loop over all pixels in a QImage in order to create a histogram of the image loaded in there. This works just fine for most images, however, for the two images attached here I encounter a crash when accessing the last 307 pixels in the last row of the image. As a "hack" I currently stop one row before the last one to avoid the crash.

      int imgWidth = img.width();
      int imgHeight = img.height();
      
      int* levels_grey = new int[256]{};
      int* levels_red = new int[256]{};
      int* levels_green = new int[256]{};
      int* levels_blue = new int[256]{};
      
      // here `imgHeight` needs to be changed to `imgHeight-1`
      for(int i = 0; i < imgHeight; ++i) {
      
          QRgb *rowData = reinterpret_cast<QRgb*>(img.scanLine(i));
      
          for(int j = 0; j < imgWidth; ++j) {
      
              QRgb pixelData = rowData[j];
      
              ++levels_grey[qGray(pixelData)];
              ++levels_red[qRed(pixelData)];
              ++levels_green[qGreen(pixelData)];
              ++levels_blue[qBlue(pixelData)];
      
          }
      
      }
      

      The exact crash is a Segmentation fault (SIGSEV) is happening when accessing the `rowData` of row 799/column 897 of an image of resolution 1203x799. On Linux the crash happens only roughly every other time, on Windows it happens every single time.

      Attachments

        1. test.avif
          54 kB
        2. test.png
          test.png
          1.10 MB

        Activity

          People

            vgt Eirik Aavitsland
            luspi Lukas Spies
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: