From cfb6f46473777e444c8124318aa78d33aae64459 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Mon, 20 Mar 2017 15:46:06 -0700 Subject: Upgrade libtiff to 4.0.7. Change-Id: If3f67767f738b7f23230ca8c37c9af2e31696e82 Reviewed-on: https://pdfium-review.googlesource.com/3117 Commit-Queue: dsinclair Reviewed-by: dsinclair --- third_party/libtiff/tif_getimage.c | 186 ++++++++++++++++++++++--------------- 1 file changed, 110 insertions(+), 76 deletions(-) (limited to 'third_party/libtiff/tif_getimage.c') diff --git a/third_party/libtiff/tif_getimage.c b/third_party/libtiff/tif_getimage.c index 5ed1b7a370..84cc1d1a76 100644 --- a/third_party/libtiff/tif_getimage.c +++ b/third_party/libtiff/tif_getimage.c @@ -1,4 +1,4 @@ -/* $Id: tif_getimage.c,v 1.90 2015-06-17 01:34:08 bfriesen Exp $ */ +/* $Id: tif_getimage.c,v 1.98 2016-11-18 02:47:45 bfriesen Exp $ */ /* * Copyright (c) 1991-1997 Sam Leffler @@ -96,6 +96,10 @@ TIFFRGBAImageOK(TIFF* tif, char emsg[1024]) td->td_bitspersample); return (0); } + if (td->td_sampleformat == SAMPLEFORMAT_IEEEFP) { + sprintf(emsg, "Sorry, can not handle images with IEEE floating-point samples"); + return (0); + } colorchannels = td->td_samplesperpixel - td->td_extrasamples; if (!TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &photometric)) { switch (colorchannels) { @@ -183,27 +187,25 @@ TIFFRGBAImageOK(TIFF* tif, char emsg[1024]) "Planarconfiguration", td->td_planarconfig); return (0); } - if( td->td_samplesperpixel != 3 || colorchannels != 3 ) - { - sprintf(emsg, - "Sorry, can not handle image with %s=%d, %s=%d", - "Samples/pixel", td->td_samplesperpixel, - "colorchannels", colorchannels); - return 0; - } + if ( td->td_samplesperpixel != 3 || colorchannels != 3 ) { + sprintf(emsg, + "Sorry, can not handle image with %s=%d, %s=%d", + "Samples/pixel", td->td_samplesperpixel, + "colorchannels", colorchannels); + return 0; + } break; case PHOTOMETRIC_CIELAB: - if( td->td_samplesperpixel != 3 || colorchannels != 3 || td->td_bitspersample != 8 ) - { - sprintf(emsg, - "Sorry, can not handle image with %s=%d, %s=%d and %s=%d", - "Samples/pixel", td->td_samplesperpixel, - "colorchannels", colorchannels, - "Bits/sample", td->td_bitspersample); - return 0; - } + if ( td->td_samplesperpixel != 3 || colorchannels != 3 || td->td_bitspersample != 8 ) { + sprintf(emsg, + "Sorry, can not handle image with %s=%d, %s=%d and %s=%d", + "Samples/pixel", td->td_samplesperpixel, + "colorchannels", colorchannels, + "Bits/sample", td->td_bitspersample); + return 0; + } break; - default: + default: sprintf(emsg, "Sorry, can not handle image with %s=%d", photoTag, photometric); return (0); @@ -214,20 +216,34 @@ TIFFRGBAImageOK(TIFF* tif, char emsg[1024]) void TIFFRGBAImageEnd(TIFFRGBAImage* img) { - if (img->Map) - _TIFFfree(img->Map), img->Map = NULL; - if (img->BWmap) - _TIFFfree(img->BWmap), img->BWmap = NULL; - if (img->PALmap) - _TIFFfree(img->PALmap), img->PALmap = NULL; - if (img->ycbcr) - _TIFFfree(img->ycbcr), img->ycbcr = NULL; - if (img->cielab) - _TIFFfree(img->cielab), img->cielab = NULL; - if (img->UaToAa) - _TIFFfree(img->UaToAa), img->UaToAa = NULL; - if (img->Bitdepth16To8) - _TIFFfree(img->Bitdepth16To8), img->Bitdepth16To8 = NULL; + if (img->Map) { + _TIFFfree(img->Map); + img->Map = NULL; + } + if (img->BWmap) { + _TIFFfree(img->BWmap); + img->BWmap = NULL; + } + if (img->PALmap) { + _TIFFfree(img->PALmap); + img->PALmap = NULL; + } + if (img->ycbcr) { + _TIFFfree(img->ycbcr); + img->ycbcr = NULL; + } + if (img->cielab) { + _TIFFfree(img->cielab); + img->cielab = NULL; + } + if (img->UaToAa) { + _TIFFfree(img->UaToAa); + img->UaToAa = NULL; + } + if (img->Bitdepth16To8) { + _TIFFfree(img->Bitdepth16To8); + img->Bitdepth16To8 = NULL; + } if( img->redcmap ) { _TIFFfree( img->redcmap ); @@ -351,7 +367,7 @@ TIFFRGBAImageBegin(TIFFRGBAImage* img, TIFF* tif, int stop, char emsg[1024]) } /* copy the colormaps so we can modify them */ - n_color = (1L << img->bitspersample); + n_color = (1U << img->bitspersample); img->redcmap = (uint16 *) _TIFFmalloc(sizeof(uint16)*n_color); img->greencmap = (uint16 *) _TIFFmalloc(sizeof(uint16)*n_color); img->bluecmap = (uint16 *) _TIFFmalloc(sizeof(uint16)*n_color); @@ -364,7 +380,7 @@ TIFFRGBAImageBegin(TIFFRGBAImage* img, TIFF* tif, int stop, char emsg[1024]) _TIFFmemcpy( img->greencmap, green_orig, n_color * 2 ); _TIFFmemcpy( img->bluecmap, blue_orig, n_color * 2 ); - /* fall thru... */ + /* fall through... */ case PHOTOMETRIC_MINISWHITE: case PHOTOMETRIC_MINISBLACK: if (planarconfig == PLANARCONFIG_CONTIG @@ -479,7 +495,7 @@ TIFFRGBAImageBegin(TIFFRGBAImage* img, TIFF* tif, int stop, char emsg[1024]) return 1; fail_return: - TIFFRGBAImageEnd( img ); + TIFFRGBAImageEnd(img); return 0; } @@ -512,7 +528,7 @@ TIFFReadRGBAImageOriented(TIFF* tif, int ok; if (TIFFRGBAImageOK(tif, emsg) && TIFFRGBAImageBegin(&img, tif, stop, emsg)) { - img.req_orientation = orientation; + img.req_orientation = (uint16)orientation; /* XXX verify rwidth and rheight against width and height */ ok = TIFFRGBAImageGet(&img, raster+(rheight-img.height)*rwidth, rwidth, img.height); @@ -643,14 +659,14 @@ gtTileContig(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) safeskew -= tw; safeskew +=w; } + if(safeskew > INT_MAX || safeskew < INT_MIN){ - _TIFFfree(buf); - TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "%s", "Invalid skew"); - return (0); + _TIFFfree(buf); + TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "%s", "Invalid skew"); + return (0); } toskew = safeskew; - /* * Leftmost tile is clipped on left side if col_offset > 0. */ @@ -659,9 +675,9 @@ gtTileContig(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) safeskew = toskew; safeskew += leftmost_fromskew; if(safeskew > INT_MAX || safeskew < INT_MIN){ - _TIFFfree(buf); - TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "%s", "Invalid skew"); - return (0); + _TIFFfree(buf); + TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "%s", "Invalid skew"); + return (0); } leftmost_toskew = safeskew; for (row = 0; row < h; row += nrow) @@ -692,18 +708,18 @@ gtTileContig(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) safeskew -= w; safeskew += tocol; if(safeskew > INT_MAX || safeskew < INT_MIN){ - _TIFFfree(buf); - TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "%s", "Invalid skew"); - return (0); + _TIFFfree(buf); + TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "%s", "Invalid skew"); + return (0); } fromskew = safeskew; this_tw = tw - fromskew; safeskew = toskew; safeskew += fromskew; if(safeskew > INT_MAX || safeskew < INT_MIN){ - _TIFFfree(buf); - TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "%s", "Invalid skew"); - return (0); + _TIFFfree(buf); + TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "%s", "Invalid skew"); + return (0); } this_toskew = safeskew; } @@ -733,7 +749,8 @@ gtTileContig(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) uint32 temp = *left; *left = *right; *right = temp; - left++, right--; + left++; + right--; } } } @@ -766,7 +783,7 @@ gtTileSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) int alpha = img->alpha; uint32 nrow; int ret = 1, flip; - int colorchannels; + uint16 colorchannels; uint32 this_tw, tocol; int32 this_toskew, leftmost_toskew; int32 leftmost_fromskew; @@ -900,7 +917,8 @@ gtTileSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) uint32 temp = *left; *left = *right; *right = temp; - left++, right--; + left++; + right--; } } } @@ -990,7 +1008,8 @@ gtStripContig(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) uint32 temp = *left; *left = *right; *right = temp; - left++, right--; + left++; + right--; } } } @@ -1021,7 +1040,8 @@ gtStripSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) tmsize_t bufsize; int32 fromskew, toskew; int alpha = img->alpha; - int ret = 1, flip, colorchannels; + int ret = 1, flip; + uint16 colorchannels; stripsize = TIFFStripSize(tif); bufsize = TIFFSafeMultiply(tmsize_t,alpha?4:3,stripsize); @@ -1123,7 +1143,8 @@ gtStripSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) uint32 temp = *left; *left = *right; *right = temp; - left++, right--; + left++; + right--; } } } @@ -1451,7 +1472,7 @@ DECLAREContigPutFunc(putRGBUAcontig8bittile) uint8* m; for (x = w; x-- > 0;) { a = pp[3]; - m = img->UaToAa+(a<<8); + m = img->UaToAa+((size_t) a<<8); r = m[pp[0]]; g = m[pp[1]]; b = m[pp[2]]; @@ -1522,7 +1543,7 @@ DECLAREContigPutFunc(putRGBUAcontig16bittile) uint8* m; for (x = w; x-- > 0;) { a = img->Bitdepth16To8[wp[3]]; - m = img->UaToAa+(a<<8); + m = img->UaToAa+((size_t) a<<8); r = m[img->Bitdepth16To8[wp[0]]]; g = m[img->Bitdepth16To8[wp[1]]]; b = m[img->Bitdepth16To8[wp[2]]]; @@ -1653,7 +1674,7 @@ DECLARESepPutFunc(putRGBUAseparate8bittile) uint8* m; for (x = w; x-- > 0;) { av = *a++; - m = img->UaToAa+(av<<8); + m = img->UaToAa+((size_t) av<<8); rv = m[*r++]; gv = m[*g++]; bv = m[*b++]; @@ -1715,15 +1736,15 @@ DECLARESepPutFunc(putRGBUAseparate16bittile) uint16 *wa = (uint16*) a; (void) img; (void) y; while (h-- > 0) { - uint32 r,g,b,a; + uint32 r2,g2,b2,a2; uint8* m; for (x = w; x-- > 0;) { - a = img->Bitdepth16To8[*wa++]; - m = img->UaToAa+(a<<8); - r = m[img->Bitdepth16To8[*wr++]]; - g = m[img->Bitdepth16To8[*wg++]]; - b = m[img->Bitdepth16To8[*wb++]]; - *cp++ = PACK4(r,g,b,a); + a2 = img->Bitdepth16To8[*wa++]; + m = img->UaToAa+((size_t) a2<<8); + r2 = m[img->Bitdepth16To8[*wr++]]; + g2 = m[img->Bitdepth16To8[*wg++]]; + b2 = m[img->Bitdepth16To8[*wb++]]; + *cp++ = PACK4(r2,g2,b2,a2); } SKEW4(wr, wg, wb, wa, fromskew); cp += toskew; @@ -1878,10 +1899,16 @@ DECLAREContigPutFunc(putcontig8bitYCbCr44tile) YCbCrtoRGB(cp3[2], pp[14]); YCbCrtoRGB(cp3[3], pp[15]); - cp += 4, cp1 += 4, cp2 += 4, cp3 += 4; + cp += 4; + cp1 += 4; + cp2 += 4; + cp3 += 4; pp += 18; } while (--x); - cp += incr, cp1 += incr, cp2 += incr, cp3 += incr; + cp += incr; + cp1 += incr; + cp2 += incr; + cp3 += incr; pp += fromskew; } } else { @@ -1932,7 +1959,10 @@ DECLAREContigPutFunc(putcontig8bitYCbCr44tile) if (h <= 4) break; h -= 4; - cp += incr, cp1 += incr, cp2 += incr, cp3 += incr; + cp += incr; + cp1 += incr; + cp2 += incr; + cp3 += incr; pp += fromskew; } } @@ -1964,10 +1994,12 @@ DECLAREContigPutFunc(putcontig8bitYCbCr42tile) YCbCrtoRGB(cp1[2], pp[6]); YCbCrtoRGB(cp1[3], pp[7]); - cp += 4, cp1 += 4; + cp += 4; + cp1 += 4; pp += 10; } while (--x); - cp += incr, cp1 += incr; + cp += incr; + cp1 += incr; pp += fromskew; } } else { @@ -2010,7 +2042,8 @@ DECLAREContigPutFunc(putcontig8bitYCbCr42tile) if (h <= 2) break; h -= 2; - cp += incr, cp1 += incr; + cp += incr; + cp1 += incr; pp += fromskew; } } @@ -2399,7 +2432,8 @@ setupMap(TIFFRGBAImage* img) if (!makebwmap(img)) return (0); /* no longer need Map, free it */ - _TIFFfree(img->Map), img->Map = NULL; + _TIFFfree(img->Map); + img->Map = NULL; } return (1); } @@ -2507,7 +2541,7 @@ buildMap(TIFFRGBAImage* img) case PHOTOMETRIC_SEPARATED: if (img->bitspersample == 8) break; - /* fall thru... */ + /* fall through... */ case PHOTOMETRIC_MINISBLACK: case PHOTOMETRIC_MINISWHITE: if (!setupMap(img)) @@ -2777,7 +2811,7 @@ BuildMapUaToAa(TIFFRGBAImage* img) for (na=0; na<256; na++) { for (nv=0; nv<256; nv++) - *m++=(nv*na+127)/255; + *m++=(uint8)((nv*na+127)/255); } return(1); } @@ -2797,7 +2831,7 @@ BuildMapBitdepth16To8(TIFFRGBAImage* img) } m=img->Bitdepth16To8; for (n=0; n<65536; n++) - *m++=(n+128)/257; + *m++=(uint8)((n+128)/257); return(1); } -- cgit v1.2.3