From a8e550f5bfd809cb2ec4c58621a25b2902f46ce1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Hajo=20Nils=20Krabbenho=CC=88ft?= Date: Wed, 16 Sep 2015 22:04:42 +0200 Subject: [PATCH] Fixed crash when reading b/w tif images (fixes #5579) --- modules/imgcodecs/src/grfmt_tiff.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/imgcodecs/src/grfmt_tiff.cpp b/modules/imgcodecs/src/grfmt_tiff.cpp index fc6f236..a805274 100644 --- a/modules/imgcodecs/src/grfmt_tiff.cpp +++ b/modules/imgcodecs/src/grfmt_tiff.cpp @@ -247,7 +247,12 @@ bool TiffDecoder::readData( Mat& img ) (!is_tiled && tile_height0 == std::numeric_limits::max()) ) tile_height0 = m_height; - const size_t buffer_size = bpp * ncn * tile_height0 * tile_width0; + if(dst_bpp == 8) { + // we will use TIFFReadRGBA* functions, so allocate temporary buffer for 32bit RGBA + bpp = 8; + ncn = 4; + } + const size_t buffer_size = (bpp/bitsPerByte) * ncn * tile_height0 * tile_width0; AutoBuffer _buffer( buffer_size ); uchar* buffer = _buffer; ushort* buffer16 = (ushort*)buffer; -- 2.7.4