imgcodecs: fix regression 9376

This commit is contained in:
Alexander Alekhin 2017-08-29 13:31:26 +03:00
parent 518c6ae8c6
commit 8f05126619
2 changed files with 13 additions and 2 deletions

View File

@ -118,7 +118,7 @@ bool BmpDecoder::readHeader()
if( m_bpp <= 8 )
{
CV_Assert(clrused < 256);
CV_Assert(clrused <= 256);
memset(m_palette, 0, sizeof(m_palette));
m_strm.getBytes(m_palette, (clrused == 0? 1<<m_bpp : clrused)*4 );
iscolor = IsColorPalette( m_palette, m_bpp );
@ -174,6 +174,7 @@ bool BmpDecoder::readHeader()
}
catch(...)
{
throw;
}
// in 32 bit case alpha channel is used - so require CV_8UC4 type
m_type = iscolor ? (m_bpp == 32 ? CV_8UC4 : CV_8UC3 ) : CV_8UC1;
@ -483,11 +484,12 @@ decode_rle8_bad: ;
result = true;
break;
default:
assert(0);
CV_ErrorNoReturn(cv::Error::StsError, "Invalid/unsupported mode");
}
}
catch(...)
{
throw;
}
return result;

View File

@ -120,3 +120,12 @@ const string exts[] = {
};
INSTANTIATE_TEST_CASE_P(imgcodecs, Imgcodecs_Image, testing::ValuesIn(exts));
TEST(Imgcodecs_Image, regression_9376)
{
String path = findDataFile("readwrite/regression_9376.bmp");
Mat m = imread(path);
ASSERT_FALSE(m.empty());
EXPECT_EQ(32, m.cols);
EXPECT_EQ(32, m.rows);
}