Merge pull request #26699 from vrabaud:bmp_overflow

Fix integer overflow in in cv::BmpDecoder::readHeader
This commit is contained in:
Alexander Smorkalov 2025-01-03 14:43:23 +03:00 committed by GitHub
commit f65006eee1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -208,7 +208,12 @@ bool BmpDecoder::readHeader()
// in 32 bit case alpha channel is used - so require CV_8UC4 type
m_type = iscolor ? ((m_bpp == 32 && m_rle_code != BMP_RGB) ? CV_8UC4 : CV_8UC3 ) : CV_8UC1;
m_origin = m_height > 0 ? ORIGIN_BL : ORIGIN_TL;
m_height = std::abs(m_height);
if ( m_height == std::numeric_limits<int>::min() ) {
// abs(std::numeric_limits<int>::min()) is undefined behavior.
result = false;
} else {
m_height = std::abs(m_height);
}
if( !result )
{