summaryrefslogtreecommitdiff
path: root/third_party/libtiff/tif_dir.c
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2017-03-20 15:46:06 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-03-21 13:12:16 +0000
commitcfb6f46473777e444c8124318aa78d33aae64459 (patch)
tree272d17a7ba02251fd6d62a90c431e5af169af85a /third_party/libtiff/tif_dir.c
parent34a28b470a9a4d7c7edd04e9b6a1e02a7490e58b (diff)
downloadpdfium-cfb6f46473777e444c8124318aa78d33aae64459.tar.xz
Upgrade libtiff to 4.0.7.
Change-Id: If3f67767f738b7f23230ca8c37c9af2e31696e82 Reviewed-on: https://pdfium-review.googlesource.com/3117 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'third_party/libtiff/tif_dir.c')
-rw-r--r--third_party/libtiff/tif_dir.c112
1 files changed, 68 insertions, 44 deletions
diff --git a/third_party/libtiff/tif_dir.c b/third_party/libtiff/tif_dir.c
index 16ce3d3cee..4b3632ab1e 100644
--- a/third_party/libtiff/tif_dir.c
+++ b/third_party/libtiff/tif_dir.c
@@ -1,4 +1,4 @@
-/* $Id: tif_dir.c,v 1.121 2015-05-31 23:11:43 bfriesen Exp $ */
+/* $Id: tif_dir.c,v 1.127 2016-10-25 21:35:15 erouault Exp $ */
/*
* Copyright (c) 1988-1997 Sam Leffler
@@ -43,8 +43,10 @@
static void
setByteArray(void** vpp, void* vp, size_t nmemb, size_t elem_size)
{
- if (*vpp)
- _TIFFfree(*vpp), *vpp = 0;
+ if (*vpp) {
+ _TIFFfree(*vpp);
+ *vpp = 0;
+ }
if (vp) {
tmsize_t bytes = (tmsize_t)(nmemb * elem_size);
if (elem_size && bytes / elem_size == nmemb)
@@ -57,13 +59,13 @@ void _TIFFsetByteArray(void** vpp, void* vp, uint32 n)
{ setByteArray(vpp, vp, n, 1); }
void _TIFFsetString(char** cpp, char* cp)
{ setByteArray((void**) cpp, (void*) cp, strlen(cp)+1, 1); }
-void _TIFFsetNString(char** cpp, char* cp, uint32 n)
+static void _TIFFsetNString(char** cpp, char* cp, uint32 n)
{ setByteArray((void**) cpp, (void*) cp, n, 1); }
void _TIFFsetShortArray(uint16** wpp, uint16* wp, uint32 n)
{ setByteArray((void**) wpp, (void*) wp, n, sizeof (uint16)); }
void _TIFFsetLongArray(uint32** lpp, uint32* lp, uint32 n)
{ setByteArray((void**) lpp, (void*) lp, n, sizeof (uint32)); }
-void _TIFFsetLong8Array(uint64** lpp, uint64* lp, uint32 n)
+static void _TIFFsetLong8Array(uint64** lpp, uint64* lp, uint32 n)
{ setByteArray((void**) lpp, (void*) lp, n, sizeof (uint64)); }
void _TIFFsetFloatArray(float** fpp, float* fp, uint32 n)
{ setByteArray((void**) fpp, (void*) fp, n, sizeof (float)); }
@@ -170,7 +172,7 @@ _TIFFVSetField(TIFF* tif, uint32 tag, va_list ap)
* We want to force the custom code to be used for custom
* fields even if the tag happens to match a well known
* one - important for reinterpreted handling of standard
- * tag values in custom directories (ie. EXIF)
+ * tag values in custom directories (i.e. EXIF)
*/
if (fip->field_bit == FIELD_CUSTOM) {
standard_tag = 0;
@@ -254,6 +256,28 @@ _TIFFVSetField(TIFF* tif, uint32 tag, va_list ap)
v = (uint16) va_arg(ap, uint16_vap);
if (v == 0)
goto badvalue;
+ if( v != td->td_samplesperpixel )
+ {
+ /* See http://bugzilla.maptools.org/show_bug.cgi?id=2500 */
+ if( td->td_sminsamplevalue != NULL )
+ {
+ TIFFWarningExt(tif->tif_clientdata,module,
+ "SamplesPerPixel tag value is changing, "
+ "but SMinSampleValue tag was read with a different value. Cancelling it");
+ TIFFClrFieldBit(tif,FIELD_SMINSAMPLEVALUE);
+ _TIFFfree(td->td_sminsamplevalue);
+ td->td_sminsamplevalue = NULL;
+ }
+ if( td->td_smaxsamplevalue != NULL )
+ {
+ TIFFWarningExt(tif->tif_clientdata,module,
+ "SamplesPerPixel tag value is changing, "
+ "but SMaxSampleValue tag was read with a different value. Cancelling it");
+ TIFFClrFieldBit(tif,FIELD_SMAXSAMPLEVALUE);
+ _TIFFfree(td->td_smaxsamplevalue);
+ td->td_smaxsamplevalue = NULL;
+ }
+ }
td->td_samplesperpixel = (uint16) v;
break;
case TIFFTAG_ROWSPERSTRIP:
@@ -402,7 +426,7 @@ _TIFFVSetField(TIFF* tif, uint32 tag, va_list ap)
if ((tif->tif_flags & TIFF_INSUBIFD) == 0) {
td->td_nsubifd = (uint16) va_arg(ap, uint16_vap);
_TIFFsetLong8Array(&td->td_subifd, (uint64*) va_arg(ap, uint64*),
- (long) td->td_nsubifd);
+ (uint32) td->td_nsubifd);
} else {
TIFFErrorExt(tif->tif_clientdata, module,
"%s: Sorry, cannot nest SubIFDs",
@@ -421,7 +445,7 @@ _TIFFVSetField(TIFF* tif, uint32 tag, va_list ap)
v = (td->td_samplesperpixel - td->td_extrasamples) > 1 ? 3 : 1;
for (i = 0; i < v; i++)
_TIFFsetShortArray(&td->td_transferfunction[i],
- va_arg(ap, uint16*), 1L<<td->td_bitspersample);
+ va_arg(ap, uint16*), 1U<<td->td_bitspersample);
break;
case TIFFTAG_REFERENCEBLACKWHITE:
/* XXX should check for null range */
@@ -587,10 +611,10 @@ _TIFFVSetField(TIFF* tif, uint32 tag, va_list ap)
handled this way ... likely best if we move it into
the directory structure with an explicit field in
libtiff 4.1 and assign it a FIELD_ value */
- uint16 v[2];
- v[0] = (uint16)va_arg(ap, int);
- v[1] = (uint16)va_arg(ap, int);
- _TIFFmemcpy(tv->value, &v, 4);
+ uint16 v2[2];
+ v2[0] = (uint16)va_arg(ap, int);
+ v2[1] = (uint16)va_arg(ap, int);
+ _TIFFmemcpy(tv->value, &v2, 4);
}
else if (fip->field_passcount
@@ -608,66 +632,66 @@ _TIFFVSetField(TIFF* tif, uint32 tag, va_list ap)
case TIFF_BYTE:
case TIFF_UNDEFINED:
{
- uint8 v = (uint8)va_arg(ap, int);
- _TIFFmemcpy(val, &v, tv_size);
+ uint8 v2 = (uint8)va_arg(ap, int);
+ _TIFFmemcpy(val, &v2, tv_size);
}
break;
case TIFF_SBYTE:
{
- int8 v = (int8)va_arg(ap, int);
- _TIFFmemcpy(val, &v, tv_size);
+ int8 v2 = (int8)va_arg(ap, int);
+ _TIFFmemcpy(val, &v2, tv_size);
}
break;
case TIFF_SHORT:
{
- uint16 v = (uint16)va_arg(ap, int);
- _TIFFmemcpy(val, &v, tv_size);
+ uint16 v2 = (uint16)va_arg(ap, int);
+ _TIFFmemcpy(val, &v2, tv_size);
}
break;
case TIFF_SSHORT:
{
- int16 v = (int16)va_arg(ap, int);
- _TIFFmemcpy(val, &v, tv_size);
+ int16 v2 = (int16)va_arg(ap, int);
+ _TIFFmemcpy(val, &v2, tv_size);
}
break;
case TIFF_LONG:
case TIFF_IFD:
{
- uint32 v = va_arg(ap, uint32);
- _TIFFmemcpy(val, &v, tv_size);
+ uint32 v2 = va_arg(ap, uint32);
+ _TIFFmemcpy(val, &v2, tv_size);
}
break;
case TIFF_SLONG:
{
- int32 v = va_arg(ap, int32);
- _TIFFmemcpy(val, &v, tv_size);
+ int32 v2 = va_arg(ap, int32);
+ _TIFFmemcpy(val, &v2, tv_size);
}
break;
case TIFF_LONG8:
case TIFF_IFD8:
{
- uint64 v = va_arg(ap, uint64);
- _TIFFmemcpy(val, &v, tv_size);
+ uint64 v2 = va_arg(ap, uint64);
+ _TIFFmemcpy(val, &v2, tv_size);
}
break;
case TIFF_SLONG8:
{
- int64 v = va_arg(ap, int64);
- _TIFFmemcpy(val, &v, tv_size);
+ int64 v2 = va_arg(ap, int64);
+ _TIFFmemcpy(val, &v2, tv_size);
}
break;
case TIFF_RATIONAL:
case TIFF_SRATIONAL:
case TIFF_FLOAT:
{
- float v = (float)va_arg(ap, double);
- _TIFFmemcpy(val, &v, tv_size);
+ float v2 = (float)va_arg(ap, double);
+ _TIFFmemcpy(val, &v2, tv_size);
}
break;
case TIFF_DOUBLE:
{
- double v = va_arg(ap, double);
- _TIFFmemcpy(val, &v, tv_size);
+ double v2 = va_arg(ap, double);
+ _TIFFmemcpy(val, &v2, tv_size);
}
break;
default:
@@ -680,9 +704,9 @@ _TIFFVSetField(TIFF* tif, uint32 tag, va_list ap)
}
}
if (status) {
- const TIFFField* fip=TIFFFieldWithTag(tif,tag);
- if (fip)
- TIFFSetFieldBit(tif, fip->field_bit);
+ const TIFFField* fip2=TIFFFieldWithTag(tif,tag);
+ if (fip2)
+ TIFFSetFieldBit(tif, fip2->field_bit);
tif->tif_flags |= TIFF_DIRTYDIRECT;
}
@@ -691,31 +715,31 @@ end:
return (status);
badvalue:
{
- const TIFFField* fip=TIFFFieldWithTag(tif,tag);
+ const TIFFField* fip2=TIFFFieldWithTag(tif,tag);
TIFFErrorExt(tif->tif_clientdata, module,
"%s: Bad value %u for \"%s\" tag",
tif->tif_name, v,
- fip ? fip->field_name : "Unknown");
+ fip2 ? fip2->field_name : "Unknown");
va_end(ap);
}
return (0);
badvalue32:
{
- const TIFFField* fip=TIFFFieldWithTag(tif,tag);
+ const TIFFField* fip2=TIFFFieldWithTag(tif,tag);
TIFFErrorExt(tif->tif_clientdata, module,
"%s: Bad value %u for \"%s\" tag",
tif->tif_name, v32,
- fip ? fip->field_name : "Unknown");
+ fip2 ? fip2->field_name : "Unknown");
va_end(ap);
}
return (0);
badvaluedouble:
{
- const TIFFField* fip=TIFFFieldWithTag(tif,tag);
+ const TIFFField* fip2=TIFFFieldWithTag(tif,tag);
TIFFErrorExt(tif->tif_clientdata, module,
"%s: Bad value %f for \"%s\" tag",
tif->tif_name, dblval,
- fip ? fip->field_name : "Unknown");
+ fip2 ? fip2->field_name : "Unknown");
va_end(ap);
}
return (0);
@@ -842,7 +866,7 @@ _TIFFVGetField(TIFF* tif, uint32 tag, va_list ap)
* We want to force the custom code to be used for custom
* fields even if the tag happens to match a well known
* one - important for reinterpreted handling of standard
- * tag values in custom directories (ie. EXIF)
+ * tag values in custom directories (i.e. EXIF)
*/
if (fip->field_bit == FIELD_CUSTOM) {
standard_tag = 0;
@@ -893,7 +917,7 @@ _TIFFVGetField(TIFF* tif, uint32 tag, va_list ap)
*va_arg(ap, double**) = td->td_sminsamplevalue;
else
{
- /* libtiff historially treats this as a single value. */
+ /* libtiff historically treats this as a single value. */
uint16 i;
double v = td->td_sminsamplevalue[0];
for (i=1; i < td->td_samplesperpixel; ++i)
@@ -907,7 +931,7 @@ _TIFFVGetField(TIFF* tif, uint32 tag, va_list ap)
*va_arg(ap, double**) = td->td_smaxsamplevalue;
else
{
- /* libtiff historially treats this as a single value. */
+ /* libtiff historically treats this as a single value. */
uint16 i;
double v = td->td_smaxsamplevalue[0];
for (i=1; i < td->td_samplesperpixel; ++i)