Commit 1260060d authored by jiakai's avatar jiakai

check boundary in ExifReader

parent b3ac2746
...@@ -42,6 +42,13 @@ ...@@ -42,6 +42,13 @@
#include "jpeg_exif.hpp" #include "jpeg_exif.hpp"
namespace {
class ExifParsingError {
};
}
namespace cv namespace cv
{ {
...@@ -66,12 +73,16 @@ ExifReader::~ExifReader() ...@@ -66,12 +73,16 @@ ExifReader::~ExifReader()
*/ */
bool ExifReader::parse() bool ExifReader::parse()
{ {
m_exif = getExif(); try {
if( !m_exif.empty() ) m_exif = getExif();
{ if( !m_exif.empty() )
return true; {
return true;
}
return false;
} catch (ExifParsingError&) {
return false;
} }
return false;
} }
...@@ -401,6 +412,9 @@ std::string ExifReader::getString(const size_t offset) const ...@@ -401,6 +412,9 @@ std::string ExifReader::getString(const size_t offset) const
*/ */
uint16_t ExifReader::getU16(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 ) if( m_format == INTEL )
{ {
return m_data[offset] + ( m_data[offset + 1] << 8 ); return m_data[offset] + ( m_data[offset + 1] << 8 );
...@@ -416,6 +430,9 @@ uint16_t ExifReader::getU16(const size_t offset) const ...@@ -416,6 +430,9 @@ uint16_t ExifReader::getU16(const size_t offset) const
*/ */
uint32_t ExifReader::getU32(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 ) if( m_format == INTEL )
{ {
return m_data[offset] + return m_data[offset] +
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment