GraphicsMagick: coders/tiff.c: Ability to handle EXIF strings wi...
GraphicsMagick Commits <[email protected]> Mon, 05 Feb 2024 13:55:10 -0600
| Newsgroups | gmane.comp.video.graphicsmagick.cvs |
|---|---|
| Message-ID | <mailman.4469.1707162926.1744.graphicsmagick-commit@lists.sourceforge.net> |
changeset 57e9448a86e2 in /hg/GraphicsMagick details: http://hg.GraphicsMagick.org/hg/GraphicsMagick?cmd=changeset;node=57e9448a86e2 summary: coders/tiff.c: Ability to handle EXIF strings without zero termination. diffstat: ChangeLog | 4 ++++ coders/tiff.c | 30 +++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletions(-) diffs (58 lines): diff -r c88dc1a95388 -r 57e9448a86e2 ChangeLog --- a/ChangeLog Sun Feb 04 12:27:57 2024 +0100 +++ b/ChangeLog Mon Feb 05 20:54:45 2024 +0100 @@ -1,3 +1,7 @@ +2024-02-05 Fojtik Jaroslav <[email protected]> + + * coders/tiff.c: Ability to handle EXIF strings without zero termination. + 2024-02-04 Fojtik Jaroslav <[email protected]> * coders/tiff.c: Performance improvement for lo endian architecture. diff -r c88dc1a95388 -r 57e9448a86e2 coders/tiff.c --- a/coders/tiff.c Sun Feb 04 12:27:57 2024 +0100 +++ b/coders/tiff.c Mon Feb 05 20:54:45 2024 +0100 @@ -4462,6 +4462,34 @@ } +static int CheckAndStoreStr(TIFF *tiff, const magick_uint16_t Tag, const char *String, const magick_uint32_t StrSize) +{ +magick_uint32_t i = StrSize; + + /* Look for zero terminator. */ + while(i>0) + { + i--; + if(String[i]==0) + return TIFFSetField(tiff, Tag, String); + } + + if(StrSize>0) + { /* Try to duplicate unterminated string. */ + char *StringDup = MagickAllocateResourceLimitedMemory(char *, StrSize+1); + if(StringDup!=NULL) + { + memcpy(StringDup,String,StrSize); + StringDup[StrSize] = 0; + i = TIFFSetField(tiff, Tag, String); + MagickFreeResourceLimitedMemory(StringDup); + return i; + } + } + return 0; +} + + static int AddIFDExifFields(TIFF *tiff, const unsigned char *profile_data, const unsigned char *IFD_data, size_t profile_length, MagickBool logging, magick_uint16_t Flags) { magick_uint32_t(*LD_UINT32)(const unsigned char *Mem); @@ -4544,7 +4572,7 @@ else { if(Value+Long2>=profile_length-1) break; /* String outside EXIF boundary. */ - if(TIFFSetField(tiff, Tag, profile_data+Value)) + if(CheckAndStoreStr(tiff, Tag, profile_data+Value, Long2)) FieldCount++; } break;