From d1c35e7b618ae94241042ca178e2b79c052c4262 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Fri, 13 Dec 2019 18:35:04 +0300 Subject: [PATCH] imgcodecs(bmp): make happy UBSAN with enum value range check --- modules/imgcodecs/src/grfmt_bmp.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/imgcodecs/src/grfmt_bmp.cpp b/modules/imgcodecs/src/grfmt_bmp.cpp index d626de1a54..6a56d3ab2d 100644 --- a/modules/imgcodecs/src/grfmt_bmp.cpp +++ b/modules/imgcodecs/src/grfmt_bmp.cpp @@ -102,7 +102,9 @@ bool BmpDecoder::readHeader() m_width = m_strm.getDWord(); m_height = m_strm.getDWord(); m_bpp = m_strm.getDWord() >> 16; - m_rle_code = (BmpCompression)m_strm.getDWord(); + int m_rle_code_ = m_strm.getDWord(); + CV_Assert(m_rle_code_ >= 0 && m_rle_code_ <= BMP_BITFIELDS); + m_rle_code = (BmpCompression)m_rle_code_; m_strm.skip(12); int clrused = m_strm.getDWord(); m_strm.skip( size - 36 );