Merge pull request #5645 from jia-kai:master

This commit is contained in:
Vadim Pisarevsky 2015-11-10 15:56:23 +00:00
commit 9ab59fb22e

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;
}
@ -147,6 +158,9 @@ std::map<int, ExifEntry_t > ExifReader::getExif()
case APP1: //actual Exif Marker
exifSize = getFieldSize(f);
if (exifSize <= offsetToTiffHeader) {
throw ExifParsingError();
}
m_data.resize( exifSize - offsetToTiffHeader );
fseek(f, static_cast<long>( offsetToTiffHeader ), SEEK_CUR);
count = fread( &m_data[0], sizeof( unsigned char ), exifSize - offsetToTiffHeader, f );
@ -401,6 +415,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 +433,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] +