File tiff-samples-reader-crash.diff of Package libqt4-devel-doc.import5129

commit cb6380beb81ab9571c547270c144988781fed465
Author: Luboš Luňák <l.lunak@suse.cz>
Date:   Tue Sep 7 12:07:34 2010 +0200

    fix tiff reader to handle TIFFTAG_SAMPLESPERPIXEL for grayscale images
    
    This commit fixes reading a .tiff file from ImageMagick which reports
    the following:
    TIFFTAG_BITSPERSAMPLE = 8
    TIFFTAG_SAMPLESPERPIXEL = 2
    TIFFTAG_PHOTOMETRIC = PHOTOMETRIC_MINISBLACK
    The reader uses QImage::Format_Indexed8, but since the samples per pixel
    value this should be (non-existent) QImage::Format_Indexed16, causing
    memory corruption. The fix falls back to the "normal" way of reading
    tiff images.
    
    Merge-request: 2467
    Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>

--- src/gui/image/qtiffhandler.cpp
+++ src/gui/image/qtiffhandler.cpp
@@ -196,9 +196,12 @@ bool QTiffHandler::read(QImage *image)
     uint16 bitPerSample;
     if (!TIFFGetField(tiff, TIFFTAG_BITSPERSAMPLE, &bitPerSample))
         bitPerSample = 1;
+    uint16 samplesPerPixel; // they may be e.g. grayscale with 2 samples per pixel
+    if (!TIFFGetField(tiff, TIFFTAG_SAMPLESPERPIXEL, &samplesPerPixel))
+        samplesPerPixel = 1;
 
     bool grayscale = photometric == PHOTOMETRIC_MINISBLACK || photometric == PHOTOMETRIC_MINISWHITE;
-    if (grayscale && bitPerSample == 1) {
+    if (grayscale && bitPerSample == 1 && samplesPerPixel == 1) {
         if (image->size() != QSize(width, height) || image->format() != QImage::Format_Mono)
             *image = QImage(width, height, QImage::Format_Mono);
         QVector<QRgb> colortable(2);
@@ -220,7 +223,7 @@ bool QTiffHandler::read(QImage *image)
             }
         }
     } else {
-        if ((grayscale || photometric == PHOTOMETRIC_PALETTE) && bitPerSample == 8) {
+        if ((grayscale || photometric == PHOTOMETRIC_PALETTE) && bitPerSample == 8 && samplesPerPixel == 1) {
             if (image->size() != QSize(width, height) || image->format() != QImage::Format_Indexed8)
                 *image = QImage(width, height, QImage::Format_Indexed8);
             if (!image->isNull()) {
openSUSE Build Service is sponsored by