From 29c89c8986f9385d72385848b9ca2594ea2dc29d Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Wed, 23 Feb 2022 23:26:06 +0100 Subject: [PATCH] Internal libtiff: resync for OSGeo/libgeotiff#66 fix (which doesn't seem to affect GDAL) --- frmts/gtiff/libgeotiff/geo_new.c | 84 ++++++++++++++++++++++++++++++-- 1 file changed, 81 insertions(+), 3 deletions(-) diff --git a/frmts/gtiff/libgeotiff/geo_new.c b/frmts/gtiff/libgeotiff/geo_new.c index 3183f7e1c74f..17fdd22e554e 100644 --- a/frmts/gtiff/libgeotiff/geo_new.c +++ b/frmts/gtiff/libgeotiff/geo_new.c @@ -33,9 +33,9 @@ static void GTIFErrorFunction(GTIF* gt, int level, const char* msg, ...) va_start(list, msg); if( level == LIBGEOTIFF_WARNING ) - fprintf(stderr, "Warning :"); + fprintf(stderr, "Warning: "); else if( level == LIBGEOTIFF_ERROR ) - fprintf(stderr, "Error :"); + fprintf(stderr, "Error: "); vfprintf(stderr, msg, list); fprintf(stderr, "\n"); va_end(list); @@ -267,21 +267,69 @@ static int ReadKey(GTIF* gt, TempKeyData* tempData, { case GTIFF_LOCAL: /* store value into data value */ + if (count != 1 ) + { + if( gt->gt_error_callback ) + { + gt->gt_error_callback( + gt, + LIBGEOTIFF_ERROR, + "Key %s of TIFFTagLocation=0 has count=%d, " + "whereas only 1 is legal.", + GTIFKeyName(keyptr->gk_key), count); + } + return 0; + } memcpy(&keyptr->gk_data, &(entptr->ent_val_offset), sizeof(pinfo_t)); break; case GTIFF_GEOKEYDIRECTORY: keyptr->gk_data = (char *)(gt->gt_short+offset); if (gt->gt_nshorts < offset+count) + { + if( gt->gt_error_callback ) + { + gt->gt_error_callback( + gt, + LIBGEOTIFF_ERROR, + "Key %s of type SHORT has offset=%d and count=%d, " + "but the GeoKeyDirectory tag has only %d values.", + GTIFKeyName(keyptr->gk_key), + offset, count, gt->gt_nshorts); + } return 0; + } break; case GTIFF_DOUBLEPARAMS: keyptr->gk_data = (char *)(gt->gt_double+offset); if (gt->gt_ndoubles < offset+count) + { + if( gt->gt_error_callback ) + { + gt->gt_error_callback( + gt, + LIBGEOTIFF_ERROR, + "Key %s of type SHORT has offset=%d and count=%d, " + "but the GeoDoubleParams tag has only %d values.", + GTIFKeyName(keyptr->gk_key), + offset, count, gt->gt_ndoubles); + } return 0; + } break; case GTIFF_ASCIIPARAMS: if( tempData->tk_asciiParams == NULL ) + { + if( gt->gt_error_callback ) + { + gt->gt_error_callback( + gt, + LIBGEOTIFF_ERROR, + "Key %s is of type ASCII but GeoAsciiParams is " + "missing or corrupted.", + GTIFKeyName(keyptr->gk_key)); + } return 0; + } if( offset + count == tempData->tk_asciiParamsLength + 1 && count > 0 ) { @@ -294,11 +342,33 @@ static int ReadKey(GTIF* gt, TempKeyData* tempData, else if (offset < tempData->tk_asciiParamsLength && offset + count > tempData->tk_asciiParamsLength ) { + if( gt->gt_error_callback ) + { + gt->gt_error_callback( + gt, + LIBGEOTIFF_WARNING, + "Key %s of type ASCII has offset=%d and count=%d, but " + "the GeoAsciiParams tag has only %d bytes. " + "Truncating the value of the key.", + GTIFKeyName(keyptr->gk_key), offset, count, + tempData->tk_asciiParamsLength); + } count = tempData->tk_asciiParamsLength - offset; - /* issue warning... if we could */ } else if (offset + count > tempData->tk_asciiParamsLength) + { + if( gt->gt_error_callback ) + { + gt->gt_error_callback( + gt, + LIBGEOTIFF_ERROR, + "Key %s of type ASCII has offset=%d and count=%d, " + "but the GeoAsciiParams tag has only %d values.", + GTIFKeyName(keyptr->gk_key), offset, count, + tempData->tk_asciiParamsLength); + } return 0; + } keyptr->gk_count = MAX(1,count+1); keyptr->gk_data = (char *) _GTIFcalloc (keyptr->gk_count); @@ -314,6 +384,14 @@ static int ReadKey(GTIF* gt, TempKeyData* tempData, keyptr->gk_data[MAX(0,count)] = '\0'; break; default: + if( gt->gt_error_callback ) + { + gt->gt_error_callback( + gt, + LIBGEOTIFF_ERROR, + "Key %d of unknown type.", + keyptr->gk_key); + } return 0; /* failure */ } keyptr->gk_size = _gtiff_size[keyptr->gk_type];