check boundary in ExifReader

This commit is contained in:
jiakai 2015-11-05 17:58:35 +08:00
parent b3ac274617
commit 1260060d7d

View File

@ -42,6 +42,13 @@
#include "jpeg_exif.hpp"
namespace {
class ExifParsingError {
};
}
namespace cv
{
@ -66,12 +73,16 @@ ExifReader::~ExifReader()
*/
bool ExifReader::parse()
{
m_exif = getExif();
if( !m_exif.empty() )
{
return true;
try {
m_exif = getExif();
if( !m_exif.empty() )
{
return true;
}
return false;
} catch (ExifParsingError&) {
return false;
}
return false;
}
@ -401,6 +412,9 @@ std::string ExifReader::getString(const size_t offset) const
*/
uint16_t ExifReader::getU16(const size_t offset) const
{
if (offset + 1 >= m_data.size())
throw ExifParsingError();
if( m_format == INTEL )
{
return m_data[offset] + ( m_data[offset + 1] << 8 );
@ -416,6 +430,9 @@ uint16_t ExifReader::getU16(const size_t offset) const
*/
uint32_t ExifReader::getU32(const size_t offset) const
{
if (offset + 3 >= m_data.size())
throw ExifParsingError();
if( m_format == INTEL )
{
return m_data[offset] +