diff --git a/exif.c b/exif.c index 1e33580..e502426 100644 --- a/exif.c +++ b/exif.c @@ -1233,6 +1233,19 @@ void create_EXIF(void) } } +//-------------------------------------------------------------------------- +// Check the range of the memory block pointed by ptr contains OrientationPtr or not. +// Return 1 if contains at least one OrientationPtr +//-------------------------------------------------------------------------- + +int CheckOrientationPtrs(unsigned char * ptr, unsigned int range){ + if((OrientationPtr[0] >= (void *)ptr) && (OrientationPtr[0] < (void *)ptr+range)) + return 1; + if((OrientationPtr[1] >= (void *)ptr) && (OrientationPtr[1] < (void *)ptr+range)) + return 1; + return 0; +} + //-------------------------------------------------------------------------- // Clear the rotation tag in the exif header to 1. // Returns NULL if no orientation tag exists. diff --git a/jhead.h b/jhead.h index 67626ec..14a69ed 100644 --- a/jhead.h +++ b/jhead.h @@ -166,6 +166,7 @@ void Clear_EXIF(); int process_EXIF (unsigned char * CharBuf, int length); void ShowImageInfo(int ShowFileInfo); void ShowConciseImageInfo(void); +int CheckOrientationPtrs(unsigned char * ptr, unsigned int range); const char * ClearOrientation(void); void PrintFormatNumber(void * ValuePtr, int Format, int ByteCount); double ConvertAnyFormat(void * ValuePtr, int Format); diff --git a/jpgfile.c b/jpgfile.c index cc40798..ad16433 100644 --- a/jpgfile.c +++ b/jpgfile.c @@ -483,7 +483,9 @@ int ReplaceThumbnail(const char * ThumbFileName) return FALSE; } - ThumbLen = 0; + ThumbLen = 0; + + ThumbnailFile = NULL; } @@ -538,7 +540,7 @@ void DiscardAllButExif(void) CommentKeeper = Sections[a]; }else if (Sections[a].Type == M_IPTC && IptcKeeper.Type == 0){ IptcKeeper = Sections[a]; - }else{ + }else if (CheckOrientationPtrs(Sections[a].Data, Sections[a].Size+20) == 0){ free(Sections[a].Data); } }