imgcodecs: add overflow checks

This commit is contained in:
Alexander Alekhin 2018-01-09 17:56:52 +03:00
parent be5247921d
commit 8a76fadaa3
2 changed files with 8 additions and 1 deletions

View File

@ -42,6 +42,7 @@
#include "precomp.hpp"
#include "bitstrm.hpp"
#include "utils.hpp"
namespace cv
{
@ -183,13 +184,18 @@ void RBaseStream::setPos( int pos )
int RBaseStream::getPos()
{
CV_Assert(isOpened());
return m_block_pos + (int)(m_current - m_start);
int pos = validateToInt((m_current - m_start) + m_block_pos);
CV_Assert(pos >= m_block_pos); // overflow check
CV_Assert(pos >= 0); // overflow check
return pos;
}
void RBaseStream::skip( int bytes )
{
CV_Assert(bytes >= 0);
uchar* old = m_current;
m_current += bytes;
CV_Assert(m_current >= old); // overflow check
}
///////////////////////// RLByteStream ////////////////////////////

View File

@ -95,6 +95,7 @@ bool BmpDecoder::readHeader()
m_offset = m_strm.getDWord();
int size = m_strm.getDWord();
CV_Assert(size > 0); // overflow, 2Gb limit
if( size >= 36 )
{