From c9d2445bc3bbccd3cc6cfb95f09108cabe981840 Mon Sep 17 00:00:00 2001 From: Kim Motoyoshi Kalland Date: Tue, 19 Jul 2011 17:53:25 +0200 Subject: Fixed crash when loading 16 bits-per-pixel grayscale TIFs. Use the fallback path when encountering 16 bits-per-pixel grayscale TIFs. Also fixed potential memory leak. Task-number: QTBUG-19878 Reviewed-by: Samuel --- src/gui/image/qtiffhandler.cpp | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/gui/image/qtiffhandler.cpp b/src/gui/image/qtiffhandler.cpp index 4a90e49..fd1c488 100644 --- a/src/gui/image/qtiffhandler.cpp +++ b/src/gui/image/qtiffhandler.cpp @@ -192,13 +192,19 @@ bool QTiffHandler::read(QImage *image) return false; } - // BitsPerSample defaults to 1 according to the TIFF spec. - uint16 bitPerSample; - if (!TIFFGetField(tiff, TIFFTAG_BITSPERSAMPLE, &bitPerSample)) - bitPerSample = 1; + uint16 bitsPerSample, samplesPerPixel, bitsPerPixel; + if (!TIFFGetFieldDefaulted(tiff, TIFFTAG_BITSPERSAMPLE, &bitsPerSample)) { + TIFFClose(tiff); + return false; + } + if (!TIFFGetFieldDefaulted(tiff, TIFFTAG_SAMPLESPERPIXEL, &samplesPerPixel)) { + TIFFClose(tiff); + return false; + } + bitsPerPixel = bitsPerSample * samplesPerPixel; bool grayscale = photometric == PHOTOMETRIC_MINISBLACK || photometric == PHOTOMETRIC_MINISWHITE; - if (grayscale && bitPerSample == 1) { + if (grayscale && bitsPerPixel == 1) { if (image->size() != QSize(width, height) || image->format() != QImage::Format_Mono) *image = QImage(width, height, QImage::Format_Mono); QVector colortable(2); @@ -220,7 +226,7 @@ bool QTiffHandler::read(QImage *image) } } } else { - if ((grayscale || photometric == PHOTOMETRIC_PALETTE) && bitPerSample == 8) { + if ((grayscale || photometric == PHOTOMETRIC_PALETTE) && bitsPerPixel == 8) { if (image->size() != QSize(width, height) || image->format() != QImage::Format_Indexed8) *image = QImage(width, height, QImage::Format_Indexed8); if (!image->isNull()) { @@ -233,14 +239,14 @@ bool QTiffHandler::read(QImage *image) } } else { // create the color table - uint16 *redTable = static_cast(qMalloc(tableSize * sizeof(uint16))); - uint16 *greenTable = static_cast(qMalloc(tableSize * sizeof(uint16))); - uint16 *blueTable = static_cast(qMalloc(tableSize * sizeof(uint16))); - if (!redTable || !greenTable || !blueTable) { + uint16 *redTable = 0; + uint16 *greenTable = 0; + uint16 *blueTable = 0; + if (!TIFFGetField(tiff, TIFFTAG_COLORMAP, &redTable, &greenTable, &blueTable)) { TIFFClose(tiff); return false; } - if (!TIFFGetField(tiff, TIFFTAG_COLORMAP, &redTable, &greenTable, &blueTable)) { + if (!redTable || !greenTable || !blueTable) { TIFFClose(tiff); return false; } @@ -497,6 +503,9 @@ bool QTiffHandler::write(const QImage &image) uint16 *greenTable = static_cast(qMalloc(256 * sizeof(uint16))); uint16 *blueTable = static_cast(qMalloc(256 * sizeof(uint16))); if (!redTable || !greenTable || !blueTable) { + qFree(redTable); + qFree(greenTable); + qFree(blueTable); TIFFClose(tiff); return false; } -- cgit v0.12 From 9af3a9d59ace4c1ede928959910d7a8698389088 Mon Sep 17 00:00:00 2001 From: Jani Hautakangas Date: Thu, 21 Jul 2011 10:10:25 +0300 Subject: Fix compilation on Symbian platforms without SgImage support Reviewed-by: Laszlo Agocs --- src/opengl/qpixmapdata_symbiangl.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/opengl/qpixmapdata_symbiangl.cpp b/src/opengl/qpixmapdata_symbiangl.cpp index 372b5ca..73d1c9e 100644 --- a/src/opengl/qpixmapdata_symbiangl.cpp +++ b/src/opengl/qpixmapdata_symbiangl.cpp @@ -136,6 +136,7 @@ QGLPixmapData::QGLPixmapData(PixelType type) QGLPixmapData::~QGLPixmapData() { +#ifdef QT_SYMBIAN_SUPPORTS_SGIMAGE if (m_sgImage) { if (m_texture.id) { QGLSgImageTextureCleanup::cleanupForContext(m_ctx)->remove(m_texture.id); @@ -146,6 +147,7 @@ QGLPixmapData::~QGLPixmapData() delete m_sgImage; m_sgImage = 0; } +#endif delete m_engine; } @@ -662,6 +664,7 @@ static inline bool knownGoodFormat(QImage::Format format) } } +#ifdef QT_SYMBIAN_SUPPORTS_SGIMAGE static inline int symbianPixeFormatBitsPerPixel(TUidPixelFormat pixelFormat) { switch (pixelFormat) { @@ -713,6 +716,7 @@ static inline int symbianPixeFormatBitsPerPixel(TUidPixelFormat pixelFormat) return 32; }; } +#endif void QGLPixmapData::fromNativeType(void* pixmap, NativeType type) { -- cgit v0.12