| OLD | NEW |
| 1 /* $Id: tif_dirread.c,v 1.178 2012-08-19 16:56:34 bfriesen Exp $ */ | 1 /* $Id: tif_dirread.c,v 1.191 2015-09-05 20:31:41 bfriesen Exp $ */ |
| 2 | 2 |
| 3 /* | 3 /* |
| 4 * Copyright (c) 1988-1997 Sam Leffler | 4 * Copyright (c) 1988-1997 Sam Leffler |
| 5 * Copyright (c) 1991-1997 Silicon Graphics, Inc. | 5 * Copyright (c) 1991-1997 Silicon Graphics, Inc. |
| 6 * | 6 * |
| 7 * Permission to use, copy, modify, distribute, and sell this software and | 7 * Permission to use, copy, modify, distribute, and sell this software and |
| 8 * its documentation for any purpose is hereby granted without fee, provided | 8 * its documentation for any purpose is hereby granted without fee, provided |
| 9 * that (i) the above copyright notices and this permission notice appear in | 9 * that (i) the above copyright notices and this permission notice appear in |
| 10 * all copies of the software and related documentation, and (ii) the names of | 10 * all copies of the software and related documentation, and (ii) the names of |
| 11 * Sam Leffler and Silicon Graphics may not be used in any advertising or | 11 * Sam Leffler and Silicon Graphics may not be used in any advertising or |
| (...skipping 19 matching lines...) Expand all Loading... |
| 31 */ | 31 */ |
| 32 | 32 |
| 33 /* Suggested pending improvements: | 33 /* Suggested pending improvements: |
| 34 * - add a field 'ignore' to the TIFFDirEntry structure, to flag status, | 34 * - add a field 'ignore' to the TIFFDirEntry structure, to flag status, |
| 35 * eliminating current use of the IGNORE value, and therefore eliminating | 35 * eliminating current use of the IGNORE value, and therefore eliminating |
| 36 * current irrational behaviour on tags with tag id code 0 | 36 * current irrational behaviour on tags with tag id code 0 |
| 37 * - add a field 'field_info' to the TIFFDirEntry structure, and set that with | 37 * - add a field 'field_info' to the TIFFDirEntry structure, and set that with |
| 38 * the pointer to the appropriate TIFFField structure early on in | 38 * the pointer to the appropriate TIFFField structure early on in |
| 39 * TIFFReadDirectory, so as to eliminate current possibly repetitive lookup. | 39 * TIFFReadDirectory, so as to eliminate current possibly repetitive lookup. |
| 40 */ | 40 */ |
| 41 | 41 |
| 42 #include "tiffiop.h" | 42 #include "tiffiop.h" |
| 43 | 43 |
| 44 #define IGNORE 0 /* tag placeholder used below */ | 44 #define IGNORE 0 /* tag placeholder used below */ |
| 45 #define FAILED_FII ((uint32) -1) | 45 #define FAILED_FII ((uint32) -1) |
| 46 | 46 |
| 47 #ifdef HAVE_IEEEFP | 47 #ifdef HAVE_IEEEFP |
| 48 # define TIFFCvtIEEEFloatToNative(tif, n, fp) | 48 # define TIFFCvtIEEEFloatToNative(tif, n, fp) |
| 49 # define TIFFCvtIEEEDoubleToNative(tif, n, dp) | 49 # define TIFFCvtIEEEDoubleToNative(tif, n, dp) |
| 50 #else | 50 #else |
| 51 extern void TIFFCvtIEEEFloatToNative(TIFF*, uint32, float*); | 51 extern void TIFFCvtIEEEFloatToNative(TIFF*, uint32, float*); |
| (...skipping 2113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2165 for (n=0; n<count; n++) | 2165 for (n=0; n<count; n++) |
| 2166 { | 2166 { |
| 2167 if (tif->tif_flags&TIFF_SWAB) | 2167 if (tif->tif_flags&TIFF_SWAB) |
| 2168 TIFFSwabLong((uint32*)ma); | 2168 TIFFSwabLong((uint32*)ma); |
| 2169 *mb++=(int64)(*ma++); | 2169 *mb++=(int64)(*ma++); |
| 2170 } | 2170 } |
| 2171 } | 2171 } |
| 2172 break; | 2172 break; |
| 2173 } | 2173 } |
| 2174 _TIFFfree(origdata); | 2174 _TIFFfree(origdata); |
| 2175 if (err!=TIFFReadDirEntryErrOk) | |
| 2176 { | |
| 2177 _TIFFfree(data); | |
| 2178 return(err); | |
| 2179 } | |
| 2180 *value=data; | 2175 *value=data; |
| 2181 return(TIFFReadDirEntryErrOk); | 2176 return(TIFFReadDirEntryErrOk); |
| 2182 } | 2177 } |
| 2183 | 2178 |
| 2184 static enum TIFFReadDirEntryErr TIFFReadDirEntryFloatArray(TIFF* tif, TIFFDirEnt
ry* direntry, float** value) | 2179 static enum TIFFReadDirEntryErr TIFFReadDirEntryFloatArray(TIFF* tif, TIFFDirEnt
ry* direntry, float** value) |
| 2185 { | 2180 { |
| 2186 enum TIFFReadDirEntryErr err; | 2181 enum TIFFReadDirEntryErr err; |
| 2187 uint32 count; | 2182 uint32 count; |
| 2188 void* origdata; | 2183 void* origdata; |
| 2189 float* data; | 2184 float* data; |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2407 TIFFSwabArrayOfLong8((uint64*)origdata,c
ount); | 2402 TIFFSwabArrayOfLong8((uint64*)origdata,c
ount); |
| 2408 TIFFCvtIEEEDoubleToNative(tif,count,(double*)ori
gdata); | 2403 TIFFCvtIEEEDoubleToNative(tif,count,(double*)ori
gdata); |
| 2409 ma=(double*)origdata; | 2404 ma=(double*)origdata; |
| 2410 mb=data; | 2405 mb=data; |
| 2411 for (n=0; n<count; n++) | 2406 for (n=0; n<count; n++) |
| 2412 *mb++=(float)(*ma++); | 2407 *mb++=(float)(*ma++); |
| 2413 } | 2408 } |
| 2414 break; | 2409 break; |
| 2415 } | 2410 } |
| 2416 _TIFFfree(origdata); | 2411 _TIFFfree(origdata); |
| 2417 if (err!=TIFFReadDirEntryErrOk) | |
| 2418 { | |
| 2419 _TIFFfree(data); | |
| 2420 return(err); | |
| 2421 } | |
| 2422 *value=data; | 2412 *value=data; |
| 2423 return(TIFFReadDirEntryErrOk); | 2413 return(TIFFReadDirEntryErrOk); |
| 2424 } | 2414 } |
| 2425 | 2415 |
| 2426 static enum TIFFReadDirEntryErr | 2416 static enum TIFFReadDirEntryErr |
| 2427 TIFFReadDirEntryDoubleArray(TIFF* tif, TIFFDirEntry* direntry, double** value) | 2417 TIFFReadDirEntryDoubleArray(TIFF* tif, TIFFDirEntry* direntry, double** value) |
| 2428 { | 2418 { |
| 2429 enum TIFFReadDirEntryErr err; | 2419 enum TIFFReadDirEntryErr err; |
| 2430 uint32 count; | 2420 uint32 count; |
| 2431 void* origdata; | 2421 void* origdata; |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2650 TIFFSwabArrayOfLong((uint32*)origdata,co
unt); | 2640 TIFFSwabArrayOfLong((uint32*)origdata,co
unt); |
| 2651 TIFFCvtIEEEFloatToNative(tif,count,(float*)origd
ata); | 2641 TIFFCvtIEEEFloatToNative(tif,count,(float*)origd
ata); |
| 2652 ma=(float*)origdata; | 2642 ma=(float*)origdata; |
| 2653 mb=data; | 2643 mb=data; |
| 2654 for (n=0; n<count; n++) | 2644 for (n=0; n<count; n++) |
| 2655 *mb++=(double)(*ma++); | 2645 *mb++=(double)(*ma++); |
| 2656 } | 2646 } |
| 2657 break; | 2647 break; |
| 2658 } | 2648 } |
| 2659 _TIFFfree(origdata); | 2649 _TIFFfree(origdata); |
| 2660 if (err!=TIFFReadDirEntryErrOk) | |
| 2661 { | |
| 2662 _TIFFfree(data); | |
| 2663 return(err); | |
| 2664 } | |
| 2665 *value=data; | 2650 *value=data; |
| 2666 return(TIFFReadDirEntryErrOk); | 2651 return(TIFFReadDirEntryErrOk); |
| 2667 } | 2652 } |
| 2668 | 2653 |
| 2669 static enum TIFFReadDirEntryErr TIFFReadDirEntryIfd8Array(TIFF* tif, TIFFDirEntr
y* direntry, uint64** value) | 2654 static enum TIFFReadDirEntryErr TIFFReadDirEntryIfd8Array(TIFF* tif, TIFFDirEntr
y* direntry, uint64** value) |
| 2670 { | 2655 { |
| 2671 enum TIFFReadDirEntryErr err; | 2656 enum TIFFReadDirEntryErr err; |
| 2672 uint32 count; | 2657 uint32 count; |
| 2673 void* origdata; | 2658 void* origdata; |
| 2674 uint64* data; | 2659 uint64* data; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2716 for (n=0; n<count; n++) | 2701 for (n=0; n<count; n++) |
| 2717 { | 2702 { |
| 2718 if (tif->tif_flags&TIFF_SWAB) | 2703 if (tif->tif_flags&TIFF_SWAB) |
| 2719 TIFFSwabLong(ma); | 2704 TIFFSwabLong(ma); |
| 2720 *mb++=(uint64)(*ma++); | 2705 *mb++=(uint64)(*ma++); |
| 2721 } | 2706 } |
| 2722 } | 2707 } |
| 2723 break; | 2708 break; |
| 2724 } | 2709 } |
| 2725 _TIFFfree(origdata); | 2710 _TIFFfree(origdata); |
| 2726 if (err!=TIFFReadDirEntryErrOk) | |
| 2727 { | |
| 2728 _TIFFfree(data); | |
| 2729 return(err); | |
| 2730 } | |
| 2731 *value=data; | 2711 *value=data; |
| 2732 return(TIFFReadDirEntryErrOk); | 2712 return(TIFFReadDirEntryErrOk); |
| 2733 } | 2713 } |
| 2734 | 2714 |
| 2735 static enum TIFFReadDirEntryErr TIFFReadDirEntryPersampleShort(TIFF* tif, TIFFDi
rEntry* direntry, uint16* value) | 2715 static enum TIFFReadDirEntryErr TIFFReadDirEntryPersampleShort(TIFF* tif, TIFFDi
rEntry* direntry, uint16* value) |
| 2736 { | 2716 { |
| 2737 enum TIFFReadDirEntryErr err; | 2717 enum TIFFReadDirEntryErr err; |
| 2738 uint16* m; | 2718 uint16* m; |
| 2739 uint16* na; | 2719 uint16* na; |
| 2740 uint16 nb; | 2720 uint16 nb; |
| (...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3187 { | 3167 { |
| 3188 if (value<0) | 3168 if (value<0) |
| 3189 return(TIFFReadDirEntryErrRange); | 3169 return(TIFFReadDirEntryErrRange); |
| 3190 else | 3170 else |
| 3191 return(TIFFReadDirEntryErrOk); | 3171 return(TIFFReadDirEntryErrOk); |
| 3192 } | 3172 } |
| 3193 | 3173 |
| 3194 /* | 3174 /* |
| 3195 * Largest 32-bit unsigned integer value. | 3175 * Largest 32-bit unsigned integer value. |
| 3196 */ | 3176 */ |
| 3197 #if defined(__WIN32__) && defined(_MSC_VER) | 3177 #define TIFF_UINT32_MAX 0xFFFFFFFFU |
| 3198 # define TIFF_UINT32_MAX 0xFFFFFFFFI64 | |
| 3199 #else | |
| 3200 # define TIFF_UINT32_MAX 0xFFFFFFFFLL | |
| 3201 #endif | |
| 3202 | 3178 |
| 3203 static enum TIFFReadDirEntryErr | 3179 static enum TIFFReadDirEntryErr |
| 3204 TIFFReadDirEntryCheckRangeLongLong8(uint64 value) | 3180 TIFFReadDirEntryCheckRangeLongLong8(uint64 value) |
| 3205 { | 3181 { |
| 3206 if (value > TIFF_UINT32_MAX) | 3182 if (value > TIFF_UINT32_MAX) |
| 3207 return(TIFFReadDirEntryErrRange); | 3183 return(TIFFReadDirEntryErrRange); |
| 3208 else | 3184 else |
| 3209 return(TIFFReadDirEntryErrOk); | 3185 return(TIFFReadDirEntryErrOk); |
| 3210 } | 3186 } |
| 3211 | 3187 |
| 3212 static enum TIFFReadDirEntryErr | 3188 static enum TIFFReadDirEntryErr |
| 3213 TIFFReadDirEntryCheckRangeLongSlong8(int64 value) | 3189 TIFFReadDirEntryCheckRangeLongSlong8(int64 value) |
| 3214 { | 3190 { |
| 3215 » if ((value<0) || (value > TIFF_UINT32_MAX)) | 3191 » if ((value < 0) || (value > (int64) TIFF_UINT32_MAX)) |
| 3216 return(TIFFReadDirEntryErrRange); | 3192 return(TIFFReadDirEntryErrRange); |
| 3217 else | 3193 else |
| 3218 return(TIFFReadDirEntryErrOk); | 3194 return(TIFFReadDirEntryErrOk); |
| 3219 } | 3195 } |
| 3220 | 3196 |
| 3221 #undef TIFF_UINT32_MAX | 3197 #undef TIFF_UINT32_MAX |
| 3222 | 3198 |
| 3223 static enum TIFFReadDirEntryErr | 3199 static enum TIFFReadDirEntryErr |
| 3224 TIFFReadDirEntryCheckRangeSlongLong(uint32 value) | 3200 TIFFReadDirEntryCheckRangeSlongLong(uint32 value) |
| 3225 { | 3201 { |
| 3226 if (value > 0x7FFFFFFFUL) | 3202 if (value > 0x7FFFFFFFUL) |
| 3227 return(TIFFReadDirEntryErrRange); | 3203 return(TIFFReadDirEntryErrRange); |
| 3228 else | 3204 else |
| 3229 return(TIFFReadDirEntryErrOk); | 3205 return(TIFFReadDirEntryErrOk); |
| 3230 } | 3206 } |
| 3231 | 3207 |
| 3208 /* Check that the 8-byte unsigned value can fit in a 4-byte unsigned range */ |
| 3232 static enum TIFFReadDirEntryErr | 3209 static enum TIFFReadDirEntryErr |
| 3233 TIFFReadDirEntryCheckRangeSlongLong8(uint64 value) | 3210 TIFFReadDirEntryCheckRangeSlongLong8(uint64 value) |
| 3234 { | 3211 { |
| 3235 » if (value > 0x7FFFFFFFUL) | 3212 » if (value > 0x7FFFFFFF) |
| 3236 return(TIFFReadDirEntryErrRange); | 3213 return(TIFFReadDirEntryErrRange); |
| 3237 else | 3214 else |
| 3238 return(TIFFReadDirEntryErrOk); | 3215 return(TIFFReadDirEntryErrOk); |
| 3239 } | 3216 } |
| 3240 | 3217 |
| 3218 /* Check that the 8-byte signed value can fit in a 4-byte signed range */ |
| 3241 static enum TIFFReadDirEntryErr | 3219 static enum TIFFReadDirEntryErr |
| 3242 TIFFReadDirEntryCheckRangeSlongSlong8(int64 value) | 3220 TIFFReadDirEntryCheckRangeSlongSlong8(int64 value) |
| 3243 { | 3221 { |
| 3244 » if ((value < 0L-0x80000000L) || (value > 0x7FFFFFFFL)) | 3222 if ((value < 0-((int64) 0x7FFFFFFF+1)) || (value > 0x7FFFFFFF)) |
| 3245 return(TIFFReadDirEntryErrRange); | 3223 return(TIFFReadDirEntryErrRange); |
| 3246 else | 3224 else |
| 3247 return(TIFFReadDirEntryErrOk); | 3225 return(TIFFReadDirEntryErrOk); |
| 3248 } | 3226 } |
| 3249 | 3227 |
| 3250 static enum TIFFReadDirEntryErr | 3228 static enum TIFFReadDirEntryErr |
| 3251 TIFFReadDirEntryCheckRangeLong8Sbyte(int8 value) | 3229 TIFFReadDirEntryCheckRangeLong8Sbyte(int8 value) |
| 3252 { | 3230 { |
| 3253 if (value < 0) | 3231 if (value < 0) |
| 3254 return(TIFFReadDirEntryErrRange); | 3232 return(TIFFReadDirEntryErrRange); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 3279 { | 3257 { |
| 3280 if (value < 0) | 3258 if (value < 0) |
| 3281 return(TIFFReadDirEntryErrRange); | 3259 return(TIFFReadDirEntryErrRange); |
| 3282 else | 3260 else |
| 3283 return(TIFFReadDirEntryErrOk); | 3261 return(TIFFReadDirEntryErrOk); |
| 3284 } | 3262 } |
| 3285 | 3263 |
| 3286 /* | 3264 /* |
| 3287 * Largest 64-bit signed integer value. | 3265 * Largest 64-bit signed integer value. |
| 3288 */ | 3266 */ |
| 3289 #if defined(__WIN32__) && defined(_MSC_VER) | 3267 #define TIFF_INT64_MAX ((int64)(((uint64) ~0) >> 1)) |
| 3290 # define TIFF_INT64_MAX 0x7FFFFFFFFFFFFFFFI64 | |
| 3291 #else | |
| 3292 # define TIFF_INT64_MAX 0x7FFFFFFFFFFFFFFFLL | |
| 3293 #endif | |
| 3294 | 3268 |
| 3295 static enum TIFFReadDirEntryErr | 3269 static enum TIFFReadDirEntryErr |
| 3296 TIFFReadDirEntryCheckRangeSlong8Long8(uint64 value) | 3270 TIFFReadDirEntryCheckRangeSlong8Long8(uint64 value) |
| 3297 { | 3271 { |
| 3298 if (value > TIFF_INT64_MAX) | 3272 if (value > TIFF_INT64_MAX) |
| 3299 return(TIFFReadDirEntryErrRange); | 3273 return(TIFFReadDirEntryErrRange); |
| 3300 else | 3274 else |
| 3301 return(TIFFReadDirEntryErrOk); | 3275 return(TIFFReadDirEntryErrOk); |
| 3302 } | 3276 } |
| 3303 | 3277 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3367 "Out of memory reading of \"%s\"", | 3341 "Out of memory reading of \"%s\"", |
| 3368 tagname); | 3342 tagname); |
| 3369 break; | 3343 break; |
| 3370 default: | 3344 default: |
| 3371 assert(0); /* we should never get here */ | 3345 assert(0); /* we should never get here */ |
| 3372 break; | 3346 break; |
| 3373 } | 3347 } |
| 3374 } else { | 3348 } else { |
| 3375 switch (err) { | 3349 switch (err) { |
| 3376 case TIFFReadDirEntryErrCount: | 3350 case TIFFReadDirEntryErrCount: |
| 3377 » » » » TIFFErrorExt(tif->tif_clientdata, module, | 3351 » » » » TIFFWarningExt(tif->tif_clientdata, module, |
| 3378 "Incorrect count for \"%s\"; tag ignored", | 3352 "Incorrect count for \"%s\"; tag ignored", |
| 3379 tagname); | 3353 tagname); |
| 3380 break; | 3354 break; |
| 3381 case TIFFReadDirEntryErrType: | 3355 case TIFFReadDirEntryErrType: |
| 3382 TIFFWarningExt(tif->tif_clientdata, module, | 3356 TIFFWarningExt(tif->tif_clientdata, module, |
| 3383 "Incompatible type for \"%s\"; tag ignored", | 3357 "Incompatible type for \"%s\"; tag ignored", |
| 3384 tagname); | 3358 tagname); |
| 3385 break; | 3359 break; |
| 3386 case TIFFReadDirEntryErrIo: | 3360 case TIFFReadDirEntryErrIo: |
| 3387 TIFFWarningExt(tif->tif_clientdata, module, | 3361 TIFFWarningExt(tif->tif_clientdata, module, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3423 TIFFReadDirectory(TIFF* tif) | 3397 TIFFReadDirectory(TIFF* tif) |
| 3424 { | 3398 { |
| 3425 static const char module[] = "TIFFReadDirectory"; | 3399 static const char module[] = "TIFFReadDirectory"; |
| 3426 TIFFDirEntry* dir; | 3400 TIFFDirEntry* dir; |
| 3427 uint16 dircount; | 3401 uint16 dircount; |
| 3428 TIFFDirEntry* dp; | 3402 TIFFDirEntry* dp; |
| 3429 uint16 di; | 3403 uint16 di; |
| 3430 const TIFFField* fip; | 3404 const TIFFField* fip; |
| 3431 uint32 fii=FAILED_FII; | 3405 uint32 fii=FAILED_FII; |
| 3432 toff_t nextdiroff; | 3406 toff_t nextdiroff; |
| 3407 int bitspersample_read = FALSE; |
| 3408 |
| 3433 tif->tif_diroff=tif->tif_nextdiroff; | 3409 tif->tif_diroff=tif->tif_nextdiroff; |
| 3434 if (!TIFFCheckDirOffset(tif,tif->tif_nextdiroff)) | 3410 if (!TIFFCheckDirOffset(tif,tif->tif_nextdiroff)) |
| 3435 return 0; /* last offset or bad offset (IFD looping) *
/ | 3411 return 0; /* last offset or bad offset (IFD looping) *
/ |
| 3436 (*tif->tif_cleanup)(tif); /* cleanup any previous compression state */ | 3412 (*tif->tif_cleanup)(tif); /* cleanup any previous compression state */ |
| 3437 tif->tif_curdir++; | 3413 tif->tif_curdir++; |
| 3438 nextdiroff = tif->tif_nextdiroff; | 3414 nextdiroff = tif->tif_nextdiroff; |
| 3439 dircount=TIFFFetchDirectory(tif,nextdiroff,&dir,&tif->tif_nextdiroff); | 3415 dircount=TIFFFetchDirectory(tif,nextdiroff,&dir,&tif->tif_nextdiroff); |
| 3440 if (!dircount) | 3416 if (!dircount) |
| 3441 { | 3417 { |
| 3442 TIFFErrorExt(tif->tif_clientdata,module, | 3418 TIFFErrorExt(tif->tif_clientdata,module, |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3699 if (err==TIFFReadDirEntryErrCount) | 3675 if (err==TIFFReadDirEntryErrCount) |
| 3700 err=TIFFReadDirEntryPersampleSho
rt(tif,dp,&value); | 3676 err=TIFFReadDirEntryPersampleSho
rt(tif,dp,&value); |
| 3701 if (err!=TIFFReadDirEntryErrOk) | 3677 if (err!=TIFFReadDirEntryErrOk) |
| 3702 { | 3678 { |
| 3703 fip = TIFFFieldWithTag(tif,dp->t
dir_tag); | 3679 fip = TIFFFieldWithTag(tif,dp->t
dir_tag); |
| 3704 TIFFReadDirEntryOutputErr(tif,er
r,module,fip ? fip->field_name : "unknown tagname",0); | 3680 TIFFReadDirEntryOutputErr(tif,er
r,module,fip ? fip->field_name : "unknown tagname",0); |
| 3705 goto bad; | 3681 goto bad; |
| 3706 } | 3682 } |
| 3707 if (!TIFFSetField(tif,dp->tdir_tag,value
)) | 3683 if (!TIFFSetField(tif,dp->tdir_tag,value
)) |
| 3708 goto bad; | 3684 goto bad; |
| 3685 if( dp->tdir_tag == TIFFTAG_BITSPERSAMPLE ) |
| 3686 bitspersample_read = TRUE; |
| 3709 } | 3687 } |
| 3710 break; | 3688 break; |
| 3711 case TIFFTAG_SMINSAMPLEVALUE: | 3689 case TIFFTAG_SMINSAMPLEVALUE: |
| 3712 case TIFFTAG_SMAXSAMPLEVALUE: | 3690 case TIFFTAG_SMAXSAMPLEVALUE: |
| 3713 { | 3691 { |
| 3714 | 3692 |
| 3715 double *data; | 3693 double *data; |
| 3716 enum TIFFReadDirEntryErr err; | 3694 enum TIFFReadDirEntryErr err; |
| 3717 uint32 saved_flags; | 3695 uint32 saved_flags; |
| 3718 int m; | 3696 int m; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3756 #endif | 3734 #endif |
| 3757 break; | 3735 break; |
| 3758 case TIFFTAG_COLORMAP: | 3736 case TIFFTAG_COLORMAP: |
| 3759 case TIFFTAG_TRANSFERFUNCTION: | 3737 case TIFFTAG_TRANSFERFUNCTION: |
| 3760 { | 3738 { |
| 3761 enum TIFFReadDirEntryErr err; | 3739 enum TIFFReadDirEntryErr err; |
| 3762 uint32 countpersample; | 3740 uint32 countpersample; |
| 3763 uint32 countrequired; | 3741 uint32 countrequired; |
| 3764 uint32 incrementpersample; | 3742 uint32 incrementpersample; |
| 3765 uint16* value=NULL; | 3743 uint16* value=NULL; |
| 3744 /* It would be dangerous to instanciate those tag values */ |
| 3745 /* since if td_bitspersample has not yet been read (due to *
/ |
| 3746 /* unordered tags), it could be read afterwards with a */ |
| 3747 /* values greater than the default one (1), which may cause
*/ |
| 3748 /* crashes in user code */ |
| 3749 if( !bitspersample_read ) |
| 3750 { |
| 3751 fip = TIFFFieldWithTag(tif,dp->tdir_tag); |
| 3752 TIFFWarningExt(tif->tif_clientdata,module, |
| 3753 "Ignoring %s since BitsPerSample tag not
found", |
| 3754 fip ? fip->field_name : "unknown tagname"
); |
| 3755 continue; |
| 3756 } |
| 3766 countpersample=(1L<<tif->tif_dir.td_bits
persample); | 3757 countpersample=(1L<<tif->tif_dir.td_bits
persample); |
| 3767 if ((dp->tdir_tag==TIFFTAG_TRANSFERFUNCT
ION)&&(dp->tdir_count==(uint64)countpersample)) | 3758 if ((dp->tdir_tag==TIFFTAG_TRANSFERFUNCT
ION)&&(dp->tdir_count==(uint64)countpersample)) |
| 3768 { | 3759 { |
| 3769 countrequired=countpersample; | 3760 countrequired=countpersample; |
| 3770 incrementpersample=0; | 3761 incrementpersample=0; |
| 3771 } | 3762 } |
| 3772 else | 3763 else |
| 3773 { | 3764 { |
| 3774 countrequired=3*countpersample; | 3765 countrequired=3*countpersample; |
| 3775 incrementpersample=countpersampl
e; | 3766 incrementpersample=countpersampl
e; |
| (...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4271 | 4262 |
| 4272 static int | 4263 static int |
| 4273 EstimateStripByteCounts(TIFF* tif, TIFFDirEntry* dir, uint16 dircount) | 4264 EstimateStripByteCounts(TIFF* tif, TIFFDirEntry* dir, uint16 dircount) |
| 4274 { | 4265 { |
| 4275 static const char module[] = "EstimateStripByteCounts"; | 4266 static const char module[] = "EstimateStripByteCounts"; |
| 4276 | 4267 |
| 4277 TIFFDirEntry *dp; | 4268 TIFFDirEntry *dp; |
| 4278 TIFFDirectory *td = &tif->tif_dir; | 4269 TIFFDirectory *td = &tif->tif_dir; |
| 4279 uint32 strip; | 4270 uint32 strip; |
| 4280 | 4271 |
| 4281 _TIFFFillStriles( tif ); | 4272 if( !_TIFFFillStriles( tif ) ) |
| 4273 return -1; |
| 4282 | 4274 |
| 4283 if (td->td_stripbytecount) | 4275 if (td->td_stripbytecount) |
| 4284 _TIFFfree(td->td_stripbytecount); | 4276 _TIFFfree(td->td_stripbytecount); |
| 4285 td->td_stripbytecount = (uint64*) | 4277 td->td_stripbytecount = (uint64*) |
| 4286 _TIFFCheckMalloc(tif, td->td_nstrips, sizeof (uint64), | 4278 _TIFFCheckMalloc(tif, td->td_nstrips, sizeof (uint64), |
| 4287 "for \"StripByteCounts\" array"); | 4279 "for \"StripByteCounts\" array"); |
| 4288 if( td->td_stripbytecount == NULL ) | 4280 if( td->td_stripbytecount == NULL ) |
| 4289 return -1; | 4281 return -1; |
| 4290 | 4282 |
| 4291 if (td->td_compression != COMPRESSION_NONE) { | 4283 if (td->td_compression != COMPRESSION_NONE) { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4370 * file with looped directory pointers. We will maintain a list of already | 4362 * file with looped directory pointers. We will maintain a list of already |
| 4371 * seen directories and check every IFD offset against that list. | 4363 * seen directories and check every IFD offset against that list. |
| 4372 */ | 4364 */ |
| 4373 static int | 4365 static int |
| 4374 TIFFCheckDirOffset(TIFF* tif, uint64 diroff) | 4366 TIFFCheckDirOffset(TIFF* tif, uint64 diroff) |
| 4375 { | 4367 { |
| 4376 uint16 n; | 4368 uint16 n; |
| 4377 | 4369 |
| 4378 if (diroff == 0) /* no more directories */ | 4370 if (diroff == 0) /* no more directories */ |
| 4379 return 0; | 4371 return 0; |
| 4372 if (tif->tif_dirnumber == 65535) { |
| 4373 TIFFErrorExt(tif->tif_clientdata, "TIFFCheckDirOffset", |
| 4374 "Cannot handle more than 65535 TIFF directories"); |
| 4375 return 0; |
| 4376 } |
| 4380 | 4377 |
| 4381 for (n = 0; n < tif->tif_dirnumber && tif->tif_dirlist; n++) { | 4378 for (n = 0; n < tif->tif_dirnumber && tif->tif_dirlist; n++) { |
| 4382 if (tif->tif_dirlist[n] == diroff) | 4379 if (tif->tif_dirlist[n] == diroff) |
| 4383 return 0; | 4380 return 0; |
| 4384 } | 4381 } |
| 4385 | 4382 |
| 4386 tif->tif_dirnumber++; | 4383 tif->tif_dirnumber++; |
| 4387 | 4384 |
| 4388 if (tif->tif_dirnumber > tif->tif_dirlistsize) { | 4385 if (tif->tif_dirnumber > tif->tif_dirlistsize) { |
| 4389 uint64* new_dirlist; | 4386 uint64* new_dirlist; |
| 4390 | 4387 |
| 4391 /* | 4388 /* |
| 4392 * XXX: Reduce memory allocation granularity of the dirlist | 4389 * XXX: Reduce memory allocation granularity of the dirlist |
| 4393 * array. | 4390 * array. |
| 4394 */ | 4391 */ |
| 4395 new_dirlist = (uint64*)_TIFFCheckRealloc(tif, tif->tif_dirlist, | 4392 new_dirlist = (uint64*)_TIFFCheckRealloc(tif, tif->tif_dirlist, |
| 4396 tif->tif_dirnumber, 2 * sizeof(uint64), "for IFD list"); | 4393 tif->tif_dirnumber, 2 * sizeof(uint64), "for IFD list"); |
| 4397 if (!new_dirlist) | 4394 if (!new_dirlist) |
| 4398 return 0; | 4395 return 0; |
| 4399 » » tif->tif_dirlistsize = 2 * tif->tif_dirnumber; | 4396 » » if( tif->tif_dirnumber >= 32768 ) |
| 4397 » » tif->tif_dirlistsize = 65535; |
| 4398 » » else |
| 4399 » » tif->tif_dirlistsize = 2 * tif->tif_dirnumber; |
| 4400 tif->tif_dirlist = new_dirlist; | 4400 tif->tif_dirlist = new_dirlist; |
| 4401 } | 4401 } |
| 4402 | 4402 |
| 4403 tif->tif_dirlist[tif->tif_dirnumber - 1] = diroff; | 4403 tif->tif_dirlist[tif->tif_dirnumber - 1] = diroff; |
| 4404 | 4404 |
| 4405 return 1; | 4405 return 1; |
| 4406 } | 4406 } |
| 4407 | 4407 |
| 4408 /* | 4408 /* |
| 4409 * Check the count field of a directory entry against a known value. The | 4409 * Check the count field of a directory entry against a known value. The |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4701 const TIFFField* fip = NULL; | 4701 const TIFFField* fip = NULL; |
| 4702 TIFFReadDirectoryFindFieldInfo(tif,dp->tdir_tag,&fii); | 4702 TIFFReadDirectoryFindFieldInfo(tif,dp->tdir_tag,&fii); |
| 4703 if( fii == FAILED_FII ) | 4703 if( fii == FAILED_FII ) |
| 4704 { | 4704 { |
| 4705 TIFFErrorExt(tif->tif_clientdata, "TIFFFetchNormalTag", | 4705 TIFFErrorExt(tif->tif_clientdata, "TIFFFetchNormalTag", |
| 4706 "No definition found for tag %d", | 4706 "No definition found for tag %d", |
| 4707 dp->tdir_tag); | 4707 dp->tdir_tag); |
| 4708 return 0; | 4708 return 0; |
| 4709 } | 4709 } |
| 4710 fip=tif->tif_fields[fii]; | 4710 fip=tif->tif_fields[fii]; |
| 4711 assert(fip != NULL); /* should not happen */ |
| 4711 assert(fip->set_field_type!=TIFF_SETGET_OTHER); /* if so, we shouldn't
arrive here but deal with this in specialized code */ | 4712 assert(fip->set_field_type!=TIFF_SETGET_OTHER); /* if so, we shouldn't
arrive here but deal with this in specialized code */ |
| 4712 assert(fip->set_field_type!=TIFF_SETGET_INT); /* if so, we shouldn't
arrive here as this is only the case for pseudo-tags */ | 4713 assert(fip->set_field_type!=TIFF_SETGET_INT); /* if so, we shouldn't
arrive here as this is only the case for pseudo-tags */ |
| 4713 err=TIFFReadDirEntryErrOk; | 4714 err=TIFFReadDirEntryErrOk; |
| 4714 switch (fip->set_field_type) | 4715 switch (fip->set_field_type) |
| 4715 { | 4716 { |
| 4716 case TIFF_SETGET_UNDEFINED: | 4717 case TIFF_SETGET_UNDEFINED: |
| 4717 break; | 4718 break; |
| 4718 case TIFF_SETGET_ASCII: | 4719 case TIFF_SETGET_ASCII: |
| 4719 { | 4720 { |
| 4720 uint8* data; | 4721 uint8* data; |
| (...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5348 return(0); | 5349 return(0); |
| 5349 } | 5350 } |
| 5350 } | 5351 } |
| 5351 break; | 5352 break; |
| 5352 default: | 5353 default: |
| 5353 assert(0); /* we should never get here */ | 5354 assert(0); /* we should never get here */ |
| 5354 break; | 5355 break; |
| 5355 } | 5356 } |
| 5356 if (err!=TIFFReadDirEntryErrOk) | 5357 if (err!=TIFFReadDirEntryErrOk) |
| 5357 { | 5358 { |
| 5358 » » TIFFReadDirEntryOutputErr(tif,err,module,fip ? fip->field_name :
"unknown tagname",recover); | 5359 » » TIFFReadDirEntryOutputErr(tif,err,module,fip->field_name,recover
); |
| 5359 return(0); | 5360 return(0); |
| 5360 } | 5361 } |
| 5361 return(1); | 5362 return(1); |
| 5362 } | 5363 } |
| 5363 | 5364 |
| 5364 /* | 5365 /* |
| 5365 * Fetch a set of offsets or lengths. | 5366 * Fetch a set of offsets or lengths. |
| 5366 * While this routine says "strips", in fact it's also used for tiles. | 5367 * While this routine says "strips", in fact it's also used for tiles. |
| 5367 */ | 5368 */ |
| 5368 static int | 5369 static int |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5604 | 5605 |
| 5605 | 5606 |
| 5606 /* vim: set ts=8 sts=8 sw=8 noet: */ | 5607 /* vim: set ts=8 sts=8 sw=8 noet: */ |
| 5607 /* | 5608 /* |
| 5608 * Local Variables: | 5609 * Local Variables: |
| 5609 * mode: c | 5610 * mode: c |
| 5610 * c-basic-offset: 8 | 5611 * c-basic-offset: 8 |
| 5611 * fill-column: 78 | 5612 * fill-column: 78 |
| 5612 * End: | 5613 * End: |
| 5613 */ | 5614 */ |
| 5614 | |
| OLD | NEW |