--- modules/imgcodecs/src/grfmt_tiff.cpp.orig 2015-09-17 11:15:11.000000000 +0300 +++ modules/imgcodecs/src/grfmt_tiff.cpp 2015-09-17 11:16:06.000000000 +0300 @@ -247,7 +247,12 @@ (!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;