Details
-
Bug
-
Resolution: Invalid
-
P2: Important
-
None
-
5.15.8
-
None
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.