From 9f44f1eb60a7669a0fd07ffb3086ba2075b8dd11 Mon Sep 17 00:00:00 2001 From: Dirk Lemstra Date: Sun, 18 Jul 2021 09:54:06 +0200 Subject: [PATCH] Fixed writing the iptc information when it is not stored as long. --- coders/tiff.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/coders/tiff.c b/coders/tiff.c index 6ff93a9aa10..da44924a2e1 100644 --- a/coders/tiff.c +++ b/coders/tiff.c @@ -3177,6 +3177,9 @@ static void TIFFSetProfiles(TIFF *tiff,Image *image) #endif if (LocaleCompare(name,"iptc") == 0) { + const TIFFField + *field; + size_t length; @@ -3187,11 +3190,20 @@ static void TIFFSetProfiles(TIFF *tiff,Image *image) length=GetStringInfoLength(profile)+4-(GetStringInfoLength(profile) & 0x03); SetStringInfoLength(iptc_profile,length); - if (TIFFIsByteSwapped(tiff)) - TIFFSwabArrayOfLong((uint32 *) GetStringInfoDatum(iptc_profile), - (unsigned long) (length/4)); - (void) TIFFSetField(tiff,TIFFTAG_RICHTIFFIPTC,(uint32) - GetStringInfoLength(iptc_profile)/4,GetStringInfoDatum(iptc_profile)); + field=TIFFFieldWithTag(tiff,TIFFTAG_RICHTIFFIPTC); + if (TIFFFieldDataType(field) == TIFF_LONG) + { + if (TIFFIsByteSwapped(tiff)) + TIFFSwabArrayOfLong((uint32 *) GetStringInfoDatum(iptc_profile), + (unsigned long) (length/4)); + (void) TIFFSetField(tiff,TIFFTAG_RICHTIFFIPTC,(uint32) + GetStringInfoLength(iptc_profile)/4,GetStringInfoDatum( + iptc_profile)); + } + else + (void) TIFFSetField(tiff,TIFFTAG_RICHTIFFIPTC,(uint32) + GetStringInfoLength(iptc_profile),GetStringInfoDatum( + iptc_profile)); iptc_profile=DestroyStringInfo(iptc_profile); } #if defined(TIFFTAG_PHOTOSHOP)