diff options
author | ace20022 <ace20022@ymail.com> | 2016-04-02 14:03:41 +0200 |
---|---|---|
committer | ace20022 <ace20022@ymail.com> | 2016-04-05 20:32:00 +0200 |
commit | 35310a1fc7ac9cd4e2b2072e13a88e554dcd8144 (patch) | |
tree | e48305544288489e9eab1ffbcef461332af874f3 /lib/libexif/ExifParse.cpp | |
parent | d26ad156084ece8a0f5834fc42ff172fcfe9996a (diff) |
CID 77632, 77633: Untrusted array index read (TAINTED_SCALAR).
Diffstat (limited to 'lib/libexif/ExifParse.cpp')
-rwxr-xr-x | lib/libexif/ExifParse.cpp | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/lib/libexif/ExifParse.cpp b/lib/libexif/ExifParse.cpp index e7be3676a4..0497c4e84d 100755 --- a/lib/libexif/ExifParse.cpp +++ b/lib/libexif/ExifParse.cpp @@ -121,6 +121,8 @@ static void ErrNonfatal(const char* const msg, int a1, int a2); // NOTE: Remember to change NUM_FORMATS if you define a new format #define NUM_FORMATS 12 +const unsigned int BytesPerFormat[NUM_FORMATS] = { 1,1,2,4,8,1,1,2,4,8,4,8 }; + //-------------------------------------------------------------------------- // Internationalisation string IDs. The enum order must match that in the // language file (e.g. 'language/English/strings.xml', and EXIF_PARSE_STRING_ID_BASE @@ -356,9 +358,6 @@ void CExifParse::ProcessDir(const unsigned char* const DirStart, } } - const int BytesPerFormat[] = {0,1,1,2,4,8,1,1,2,4,8,4,8}; - - for (int de=0;de<NumDirEntries;de++) { int Tag, Format, Components; @@ -370,9 +369,8 @@ void CExifParse::ProcessDir(const unsigned char* const DirStart, Format = Get16(DirEntry+2, m_MotorolaOrder); Components = Get32(DirEntry+4, m_MotorolaOrder); - if ((Format-1) >= NUM_FORMATS) + if (Format <= 0 || Format > NUM_FORMATS) { - // (-1) catches illegal zero case as unsigned underflows to positive large. ErrNonfatal("Illegal number format %d for tag %04x", Format, Tag); continue; } @@ -383,7 +381,7 @@ void CExifParse::ProcessDir(const unsigned char* const DirStart, continue; } - ByteCount = Components * BytesPerFormat[Format]; + ByteCount = Components * BytesPerFormat[Format - 1]; if (ByteCount > 4) { @@ -894,15 +892,13 @@ void CExifParse::ProcessGpsInfo( unsigned Tag = Get16(DirEntry, m_MotorolaOrder); unsigned Format = Get16(DirEntry+2, m_MotorolaOrder); unsigned Components = (unsigned)Get32(DirEntry+4, m_MotorolaOrder); - if ((Format-1) >= NUM_FORMATS) + if (Format == 0 || Format > NUM_FORMATS) { - // (-1) catches illegal zero case as unsigned underflows to positive large. ErrNonfatal("Illegal number format %d for tag %04x", Format, Tag); continue; } - const int BytesPerFormat[] = {0,1,1,2,4,8,1,1,2,4,8,4,8}; - int ComponentSize = BytesPerFormat[Format]; + unsigned ComponentSize = BytesPerFormat[Format - 1]; unsigned ByteCount = Components * ComponentSize; const unsigned char* ValuePtr; |