From 79527e99fb4c2a0e6f2be82f7e20559a3cd087fa Mon Sep 17 00:00:00 2001 From: Oliver Duis Date: Sun, 10 Jun 2012 18:53:20 +0200 Subject: [PATCH] Fixed crash when reading some TIF files see issue 1389 --- rtengine/imageio.cc | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/rtengine/imageio.cc b/rtengine/imageio.cc index 126b19640..47e014b2c 100644 --- a/rtengine/imageio.cc +++ b/rtengine/imageio.cc @@ -439,9 +439,16 @@ int ImageIO::loadTIFF (Glib::ustring fname) { TIFFGetField(in, TIFFTAG_IMAGELENGTH, &height); uint16 bitspersample, samplesperpixel, sampleformat; - TIFFGetField(in, TIFFTAG_BITSPERSAMPLE, &bitspersample); - TIFFGetField(in, TIFFTAG_SAMPLESPERPIXEL, &samplesperpixel); - TIFFGetField(in, TIFFTAG_SAMPLEFORMAT, &sampleformat); + int hasTag = TIFFGetField(in, TIFFTAG_BITSPERSAMPLE, &bitspersample); + hasTag &= TIFFGetField(in, TIFFTAG_SAMPLESPERPIXEL, &samplesperpixel); + if (!hasTag) { + // These are needed + TIFFClose(in); + return IMIO_VARIANTNOTSUPPORTED; + } + + hasTag=TIFFGetField(in, TIFFTAG_SAMPLEFORMAT, &sampleformat); + if (!hasTag) sampleformat=0; uint16 photometric; if (!TIFFGetField(in, TIFFTAG_PHOTOMETRIC, &photometric) ||