diff -urNp old/modules/imgcodecs/src/grfmt_bmp.cpp new/modules/imgcodecs/src/grfmt_bmp.cpp --- old/modules/imgcodecs/src/grfmt_bmp.cpp 2018-04-10 12:43:48.636921073 +0200 +++ new/modules/imgcodecs/src/grfmt_bmp.cpp 2018-04-10 12:49:30.394233343 +0200 @@ -368,6 +368,9 @@ decode_rle4_bad: ; gray_palette[code] ); line_end_flag = y - prev_y; + + if( y >= m_height ) + break; } else if( code > 2 ) // absolute mode {