From f6230ae0198ed66597c5a7a91279fb20c8a78ca4 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Mon, 10 Jun 2019 19:50:54 +0000 Subject: [PATCH] imgcodecs(tiff): add more checks https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=15154 --- modules/imgcodecs/src/grfmt_tiff.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/modules/imgcodecs/src/grfmt_tiff.cpp b/modules/imgcodecs/src/grfmt_tiff.cpp index e6beb54213..5d54a4ac6d 100644 --- a/modules/imgcodecs/src/grfmt_tiff.cpp +++ b/modules/imgcodecs/src/grfmt_tiff.cpp @@ -537,6 +537,7 @@ bool TiffDecoder::readData( Mat& img ) } else { + CV_CheckEQ(wanted_channels, 3, "TIFF-8bpp: BGR/BGRA images are supported only"); icvCvt_BGRA2BGR_8u_C4C3R(bstart + i*tile_width0*4, 0, img.ptr(img_y + tile_height - i - 1, x), 0, Size(tile_width, 1), 2); @@ -544,6 +545,7 @@ bool TiffDecoder::readData( Mat& img ) } else { + CV_CheckEQ(wanted_channels, 1, ""); icvCvt_BGRA2Gray_8u_C4C1R( bstart + i*tile_width0*4, 0, img.ptr(img_y + tile_height - i - 1, x), 0, Size(tile_width, 1), 2); @@ -569,12 +571,14 @@ bool TiffDecoder::readData( Mat& img ) { if (ncn == 1) { + CV_CheckEQ(wanted_channels, 3, ""); icvCvt_Gray2BGR_16u_C1C3R(buffer16 + i*tile_width0*ncn, 0, img.ptr(img_y + i, x), 0, Size(tile_width, 1)); } else if (ncn == 3) { + CV_CheckEQ(wanted_channels, 3, ""); icvCvt_RGB2BGR_16u_C3R(buffer16 + i*tile_width0*ncn, 0, img.ptr(img_y + i, x), 0, Size(tile_width, 1)); @@ -589,6 +593,7 @@ bool TiffDecoder::readData( Mat& img ) } else { + CV_CheckEQ(wanted_channels, 3, "TIFF-16bpp: BGR/BGRA images are supported only"); icvCvt_BGRA2BGR_16u_C4C3R(buffer16 + i*tile_width0*ncn, 0, img.ptr(img_y + i, x), 0, Size(tile_width, 1), 2); @@ -596,13 +601,12 @@ bool TiffDecoder::readData( Mat& img ) } else { - icvCvt_BGRA2BGR_16u_C4C3R(buffer16 + i*tile_width0*ncn, 0, - img.ptr(img_y + i, x), 0, - Size(tile_width, 1), 2); + CV_Error(Error::StsError, "Not supported"); } } else { + CV_CheckEQ(wanted_channels, 1, ""); if( ncn == 1 ) { memcpy(img.ptr(img_y + i, x),