|
|
376dba |
From 70567edd9fc8753cc176de02b1d96f504a14e82c Mon Sep 17 00:00:00 2001
|
|
|
376dba |
From: =?UTF-8?q?Hubert=20Figui=C3=A8re?= <hub@figuiere.net>
|
|
|
376dba |
Date: Sun, 26 Mar 2017 01:10:11 -0400
|
|
|
376dba |
Subject: [PATCH 2/5] Bug 100397 - Fix crash on malformed JPEG file
|
|
|
376dba |
|
|
|
376dba |
---
|
|
|
376dba |
source/XMPFiles/FormatSupport/TIFF_MemoryReader.cpp | 10 +++++++---
|
|
|
376dba |
source/XMPFiles/FormatSupport/TIFF_Support.hpp | 13 ++++++++++++-
|
|
|
376dba |
source/common/EndianUtils.hpp | 9 +++++++++
|
|
|
376dba |
3 files changed, 28 insertions(+), 4 deletions(-)
|
|
|
376dba |
|
|
|
376dba |
diff --git a/source/XMPFiles/FormatSupport/TIFF_MemoryReader.cpp b/source/XMPFiles/FormatSupport/TIFF_MemoryReader.cpp
|
|
|
376dba |
index 316cea0..1446cb4 100644
|
|
|
376dba |
--- a/source/XMPFiles/FormatSupport/TIFF_MemoryReader.cpp
|
|
|
376dba |
+++ b/source/XMPFiles/FormatSupport/TIFF_MemoryReader.cpp
|
|
|
376dba |
@@ -65,7 +65,7 @@ void TIFF_MemoryReader::SortIFD ( TweakedIFDInfo* thisIFD )
|
|
|
376dba |
} else if ( thisTag == prevTag ) {
|
|
|
376dba |
|
|
|
376dba |
// Duplicate tag, keep the 2nd copy, move the tail of the array up, prevTag is unchanged.
|
|
|
376dba |
- memcpy ( &ifdEntries[i-1], &ifdEntries[i], 12*(tagCount-i) ); // AUDIT: Safe, moving tail forward, i >= 1.
|
|
|
376dba |
+ memmove ( &ifdEntries[i-1], &ifdEntries[i], 12*(tagCount-i) ); // may overlap -- Hub
|
|
|
376dba |
--tagCount;
|
|
|
376dba |
--i; // ! Don't move forward in the array, we've moved the unseen part up.
|
|
|
376dba |
|
|
|
376dba |
@@ -81,7 +81,7 @@ void TIFF_MemoryReader::SortIFD ( TweakedIFDInfo* thisIFD )
|
|
|
376dba |
|
|
|
376dba |
// Out of order duplicate, move it to position j, move the tail of the array up.
|
|
|
376dba |
ifdEntries[j] = ifdEntries[i];
|
|
|
376dba |
- memcpy ( &ifdEntries[i], &ifdEntries[i+1], 12*(tagCount-(i+1)) ); // AUDIT: Safe, moving tail forward, i >= 1.
|
|
|
376dba |
+ memmove ( &ifdEntries[i], &ifdEntries[i+1], 12*(tagCount-(i+1)) ); // may overlap -- Hub
|
|
|
376dba |
--tagCount;
|
|
|
376dba |
--i; // ! Don't move forward in the array, we've moved the unseen part up.
|
|
|
376dba |
|
|
|
376dba |
@@ -212,7 +212,11 @@ bool TIFF_MemoryReader::GetTag ( XMP_Uns8 ifd, XMP_Uns16 id, TagInfo* info ) con
|
|
|
376dba |
info->dataLen = thisTag->bytes;
|
|
|
376dba |
|
|
|
376dba |
info->dataPtr = this->GetDataPtr ( thisTag );
|
|
|
376dba |
-
|
|
|
376dba |
+ // Here we know that if it is NULL, it is wrong. -- Hub
|
|
|
376dba |
+ // GetDataPtr will return NULL in case of overflow.
|
|
|
376dba |
+ if (info->dataPtr == NULL) {
|
|
|
376dba |
+ return false;
|
|
|
376dba |
+ }
|
|
|
376dba |
}
|
|
|
376dba |
|
|
|
376dba |
return true;
|
|
|
376dba |
diff --git a/source/XMPFiles/FormatSupport/TIFF_Support.hpp b/source/XMPFiles/FormatSupport/TIFF_Support.hpp
|
|
|
376dba |
index 9af76c4..95badba 100644
|
|
|
376dba |
--- a/source/XMPFiles/FormatSupport/TIFF_Support.hpp
|
|
|
376dba |
+++ b/source/XMPFiles/FormatSupport/TIFF_Support.hpp
|
|
|
376dba |
@@ -723,7 +723,18 @@ private:
|
|
|
376dba |
const TweakedIFDEntry* FindTagInIFD ( XMP_Uns8 ifd, XMP_Uns16 id ) const;
|
|
|
376dba |
|
|
|
376dba |
const inline void* GetDataPtr ( const TweakedIFDEntry* tifdEntry ) const
|
|
|
376dba |
- { if ( tifdEntry->bytes <= 4 ) return &tifdEntry->dataOrPos; else return (this->tiffStream + tifdEntry->dataOrPos); };
|
|
|
376dba |
+ { if ( GetUns32AsIs(&tifdEntry->bytes) <= 4 ) {
|
|
|
376dba |
+ return &tifdEntry->dataOrPos;
|
|
|
376dba |
+ } else {
|
|
|
376dba |
+ XMP_Uns32 pos = GetUns32AsIs(&tifdEntry->dataOrPos);
|
|
|
376dba |
+ if (pos + GetUns32AsIs(&tifdEntry->bytes) > this->tiffLength) {
|
|
|
376dba |
+ // Invalid file.
|
|
|
376dba |
+ // The data is past the length of the TIFF.
|
|
|
376dba |
+ return NULL;
|
|
|
376dba |
+ }
|
|
|
376dba |
+ return (this->tiffStream + pos);
|
|
|
376dba |
+ }
|
|
|
376dba |
+ }
|
|
|
376dba |
|
|
|
376dba |
static inline void NotAppropriate() { XMP_Throw ( "Not appropriate for TIFF_Reader", kXMPErr_InternalFailure ); };
|
|
|
376dba |
|
|
|
376dba |
diff --git a/source/common/EndianUtils.hpp b/source/common/EndianUtils.hpp
|
|
|
376dba |
index 59e2e32..0e2e2fe 100644
|
|
|
376dba |
--- a/source/common/EndianUtils.hpp
|
|
|
376dba |
+++ b/source/common/EndianUtils.hpp
|
|
|
376dba |
@@ -148,6 +148,15 @@ GetUns32LE ( const void * addr )
|
|
|
376dba |
|
|
|
376dba |
// -------------------------------------------------------------------------------------------------
|
|
|
376dba |
|
|
|
376dba |
+static inline XMP_Uns32
|
|
|
376dba |
+GetUns32AsIs ( const void * addr )
|
|
|
376dba |
+{
|
|
|
376dba |
+ XMP_Uns32 value = *((XMP_Uns32*)addr);
|
|
|
376dba |
+ return value; // Use this to avoid SPARC failure to handle unaligned loads and stores.
|
|
|
376dba |
+}
|
|
|
376dba |
+
|
|
|
376dba |
+// -------------------------------------------------------------------------------------------------
|
|
|
376dba |
+
|
|
|
376dba |
static inline XMP_Uns64
|
|
|
376dba |
GetUns64BE ( const void * addr )
|
|
|
376dba |
{
|
|
|
376dba |
--
|
|
|
376dba |
2.17.2
|
|
|
376dba |
|