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/0000-build-config.patch | 2 +- third_party/libtiff/0002-CVE-2015-8665-8683.patch | 114 ------------- .../libtiff/0003-CVE-2015-8781-8782-8783.patch | 172 ------------------- third_party/libtiff/0004-CVE-2015-8784.patch | 50 ------ ...ferOverflow-ChopUpSingleUncompressedStrip.patch | 6 +- .../0009-HeapBufferOverflow-PixarLogDecode.patch | 33 ---- .../libtiff/0011-fix-leak-imagebegin2.patch | 63 +++---- .../libtiff/0015-fix-leaks-in-tif_ojpeg.patch | 74 ++++---- .../0016-fix-leak-in-pixarlogsetupdecode.patch | 24 --- .../libtiff/0017-safe_skews_in_gtTileContig.patch | 84 +++++----- .../0018-fix-leak-in-PredictorSetupDecode.patch | 44 ++--- ...0019-fix-invalid-reads-TIFFFetchNormalTag.patch | 28 ---- .../0020-unreasonable-td-bitspersample.patch | 22 --- .../0021-fix-leaks-ojpegreaderinfosectables.patch | 31 ---- third_party/libtiff/README.pdfium | 10 +- third_party/libtiff/tif_aux.c | 33 ++-- third_party/libtiff/tif_close.c | 12 +- third_party/libtiff/tif_color.c | 22 +-- third_party/libtiff/tif_compress.c | 8 +- third_party/libtiff/tif_dir.c | 112 ++++++++----- third_party/libtiff/tif_dirinfo.c | 40 +++-- third_party/libtiff/tif_dirread.c | 47 ++++-- third_party/libtiff/tif_dirwrite.c | 78 +++++---- third_party/libtiff/tif_dumpmode.c | 4 +- third_party/libtiff/tif_extension.c | 38 ++--- third_party/libtiff/tif_fax3.c | 63 ++++--- third_party/libtiff/tif_fax3.h | 6 +- third_party/libtiff/tif_getimage.c | 186 ++++++++++++--------- third_party/libtiff/tif_jpeg.c | 33 ++-- third_party/libtiff/tif_luv.c | 46 +++-- third_party/libtiff/tif_lzw.c | 56 ++++--- third_party/libtiff/tif_next.c | 10 +- third_party/libtiff/tif_ojpeg.c | 79 ++++++--- third_party/libtiff/tif_open.c | 8 +- third_party/libtiff/tif_packbits.c | 15 +- third_party/libtiff/tif_pixarlog.c | 168 +++++++++---------- third_party/libtiff/tif_predict.c | 176 +++++++++++++------ third_party/libtiff/tif_predict.h | 8 +- third_party/libtiff/tif_print.c | 14 +- third_party/libtiff/tif_read.c | 65 +++++-- third_party/libtiff/tif_strip.c | 11 +- third_party/libtiff/tif_swab.c | 8 +- third_party/libtiff/tif_thunder.c | 5 +- third_party/libtiff/tif_write.c | 53 +++++- third_party/libtiff/tif_zip.c | 14 +- third_party/libtiff/tiff.h | 6 +- third_party/libtiff/tiffio.h | 6 +- third_party/libtiff/tiffiop.h | 52 +++--- third_party/libtiff/tiffvers.h | 4 +- third_party/libtiff/uvcode.h | 2 +- 50 files changed, 1053 insertions(+), 1192 deletions(-) delete mode 100644 third_party/libtiff/0002-CVE-2015-8665-8683.patch delete mode 100644 third_party/libtiff/0003-CVE-2015-8781-8782-8783.patch delete mode 100644 third_party/libtiff/0004-CVE-2015-8784.patch delete mode 100644 third_party/libtiff/0009-HeapBufferOverflow-PixarLogDecode.patch delete mode 100644 third_party/libtiff/0016-fix-leak-in-pixarlogsetupdecode.patch delete mode 100644 third_party/libtiff/0019-fix-invalid-reads-TIFFFetchNormalTag.patch delete mode 100644 third_party/libtiff/0020-unreasonable-td-bitspersample.patch delete mode 100644 third_party/libtiff/0021-fix-leaks-ojpegreaderinfosectables.patch diff --git a/third_party/libtiff/0000-build-config.patch b/third_party/libtiff/0000-build-config.patch index 64e86e60ad..a6c5b2706b 100644 --- a/third_party/libtiff/0000-build-config.patch +++ b/third_party/libtiff/0000-build-config.patch @@ -102,7 +102,7 @@ diff a/third_party/libtiff/tiffconf.h b/third_party/libtiff/tiffconf.h +#ifndef _TIFFCONF_ +#define _TIFFCONF_ + -+#include "core/include/fxcrt/fx_system.h" ++#include "core/fxcrt/fx_system.h" + +//NOTE: The tiff codec requires an ANSI C compiler environment for building and +// presumes an ANSI C environment for use. diff --git a/third_party/libtiff/0002-CVE-2015-8665-8683.patch b/third_party/libtiff/0002-CVE-2015-8665-8683.patch deleted file mode 100644 index 0d740e229d..0000000000 --- a/third_party/libtiff/0002-CVE-2015-8665-8683.patch +++ /dev/null @@ -1,114 +0,0 @@ -From f94a29a822f5528d2334592760fbb7938f15eb55 Mon Sep 17 00:00:00 2001 -From: erouault -Date: Sat, 26 Dec 2015 17:32:03 +0000 -Subject: [PATCH] * libtiff/tif_getimage.c: fix out-of-bound reads in - TIFFRGBAImage interface in case of unsupported values of - SamplesPerPixel/ExtraSamples for LogLUV / CIELab. Add explicit call to - TIFFRGBAImageOK() in TIFFRGBAImageBegin(). Fix CVE-2015-8665 reported by - limingxing and CVE-2015-8683 reported by zzf of Alibaba. - ---- - ChangeLog | 8 ++++++++ - libtiff/tif_getimage.c | 35 ++++++++++++++++++++++------------- - 2 files changed, 30 insertions(+), 13 deletions(-) - -Index: tiff-4.0.3/libtiff/tif_getimage.c -=================================================================== ---- tiff-4.0.3.orig/libtiff/tif_getimage.c 2016-03-23 10:13:42.728371661 -0400 -+++ tiff-4.0.3/libtiff/tif_getimage.c 2016-03-23 10:13:42.724371614 -0400 -@@ -182,20 +182,22 @@ - "Planarconfiguration", td->td_planarconfig); - return (0); - } -- if( td->td_samplesperpixel != 3 ) -+ if( td->td_samplesperpixel != 3 || colorchannels != 3 ) - { - sprintf(emsg, -- "Sorry, can not handle image with %s=%d", -- "Samples/pixel", td->td_samplesperpixel); -+ "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 || td->td_bitspersample != 8 ) -+ if( td->td_samplesperpixel != 3 || colorchannels != 3 || td->td_bitspersample != 8 ) - { - sprintf(emsg, -- "Sorry, can not handle image with %s=%d and %s=%d", -+ "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; - } -@@ -255,6 +257,9 @@ - int colorchannels; - uint16 *red_orig, *green_orig, *blue_orig; - int n_color; -+ -+ if( !TIFFRGBAImageOK(tif, emsg) ) -+ return 0; - - /* Initialize to normal values */ - img->row_offset = 0; -@@ -2470,29 +2475,33 @@ - case PHOTOMETRIC_RGB: - switch (img->bitspersample) { - case 8: -- if (img->alpha == EXTRASAMPLE_ASSOCALPHA) -+ if (img->alpha == EXTRASAMPLE_ASSOCALPHA && -+ img->samplesperpixel >= 4) - img->put.contig = putRGBAAcontig8bittile; -- else if (img->alpha == EXTRASAMPLE_UNASSALPHA) -+ else if (img->alpha == EXTRASAMPLE_UNASSALPHA && -+ img->samplesperpixel >= 4) - { - if (BuildMapUaToAa(img)) - img->put.contig = putRGBUAcontig8bittile; - } -- else -+ else if( img->samplesperpixel >= 3 ) - img->put.contig = putRGBcontig8bittile; - break; - case 16: -- if (img->alpha == EXTRASAMPLE_ASSOCALPHA) -+ if (img->alpha == EXTRASAMPLE_ASSOCALPHA && -+ img->samplesperpixel >=4 ) - { - if (BuildMapBitdepth16To8(img)) - img->put.contig = putRGBAAcontig16bittile; - } -- else if (img->alpha == EXTRASAMPLE_UNASSALPHA) -+ else if (img->alpha == EXTRASAMPLE_UNASSALPHA && -+ img->samplesperpixel >=4 ) - { - if (BuildMapBitdepth16To8(img) && - BuildMapUaToAa(img)) - img->put.contig = putRGBUAcontig16bittile; - } -- else -+ else if( img->samplesperpixel >=3 ) - { - if (BuildMapBitdepth16To8(img)) - img->put.contig = putRGBcontig16bittile; -@@ -2501,7 +2510,7 @@ - } - break; - case PHOTOMETRIC_SEPARATED: -- if (buildMap(img)) { -+ if (img->samplesperpixel >=4 && buildMap(img)) { - if (img->bitspersample == 8) { - if (!img->Map) - img->put.contig = putRGBcontig8bitCMYKtile; -@@ -2597,7 +2606,7 @@ - } - break; - case PHOTOMETRIC_CIELAB: -- if (buildMap(img)) { -+ if (img->samplesperpixel == 3 && buildMap(img)) { - if (img->bitspersample == 8) - img->put.contig = initCIELabConversion(img); - break; diff --git a/third_party/libtiff/0003-CVE-2015-8781-8782-8783.patch b/third_party/libtiff/0003-CVE-2015-8781-8782-8783.patch deleted file mode 100644 index c4ed67dfc8..0000000000 --- a/third_party/libtiff/0003-CVE-2015-8781-8782-8783.patch +++ /dev/null @@ -1,172 +0,0 @@ -From aaab5c3c9d2a2c6984f23ccbc79702610439bc65 Mon Sep 17 00:00:00 2001 -From: erouault -Date: Sun, 27 Dec 2015 16:25:11 +0000 -Subject: [PATCH] * libtiff/tif_luv.c: fix potential out-of-bound writes in - decode functions in non debug builds by replacing assert()s by regular if - checks (bugzilla #2522). Fix potential out-of-bound reads in case of short - input data. - ---- - ChangeLog | 7 +++++++ - libtiff/tif_luv.c | 55 ++++++++++++++++++++++++++++++++++++++++++++----------- - 2 files changed, 51 insertions(+), 11 deletions(-) - -Index: tiff-4.0.3/libtiff/tif_luv.c -=================================================================== ---- tiff-4.0.3.orig/libtiff/tif_luv.c 2016-03-23 10:13:56.868540963 -0400 -+++ tiff-4.0.3/libtiff/tif_luv.c 2016-03-23 10:13:56.864540914 -0400 -@@ -202,7 +202,11 @@ - if (sp->user_datafmt == SGILOGDATAFMT_16BIT) - tp = (int16*) op; - else { -- assert(sp->tbuflen >= npixels); -+ if(sp->tbuflen < npixels) { -+ TIFFErrorExt(tif->tif_clientdata, module, -+ "Translation buffer too short"); -+ return (0); -+ } - tp = (int16*) sp->tbuf; - } - _TIFFmemset((void*) tp, 0, npixels*sizeof (tp[0])); -@@ -211,9 +215,11 @@ - cc = tif->tif_rawcc; - /* get each byte string */ - for (shft = 2*8; (shft -= 8) >= 0; ) { -- for (i = 0; i < npixels && cc > 0; ) -+ for (i = 0; i < npixels && cc > 0; ) { - if (*bp >= 128) { /* run */ -- rc = *bp++ + (2-128); /* TODO: potential input buffer overrun when decoding corrupt or truncated data */ -+ if( cc < 2 ) -+ break; -+ rc = *bp++ + (2-128); - b = (int16)(*bp++ << shft); - cc -= 2; - while (rc-- && i < npixels) -@@ -223,6 +229,7 @@ - while (--cc && rc-- && i < npixels) - tp[i++] |= (int16)*bp++ << shft; - } -+ } - if (i != npixels) { - #if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) - TIFFErrorExt(tif->tif_clientdata, module, -@@ -268,13 +275,17 @@ - if (sp->user_datafmt == SGILOGDATAFMT_RAW) - tp = (uint32 *)op; - else { -- assert(sp->tbuflen >= npixels); -+ if(sp->tbuflen < npixels) { -+ TIFFErrorExt(tif->tif_clientdata, module, -+ "Translation buffer too short"); -+ return (0); -+ } - tp = (uint32 *) sp->tbuf; - } - /* copy to array of uint32 */ - bp = (unsigned char*) tif->tif_rawcp; - cc = tif->tif_rawcc; -- for (i = 0; i < npixels && cc > 0; i++) { -+ for (i = 0; i < npixels && cc >= 3; i++) { - tp[i] = bp[0] << 16 | bp[1] << 8 | bp[2]; - bp += 3; - cc -= 3; -@@ -325,7 +336,11 @@ - if (sp->user_datafmt == SGILOGDATAFMT_RAW) - tp = (uint32*) op; - else { -- assert(sp->tbuflen >= npixels); -+ if(sp->tbuflen < npixels) { -+ TIFFErrorExt(tif->tif_clientdata, module, -+ "Translation buffer too short"); -+ return (0); -+ } - tp = (uint32*) sp->tbuf; - } - _TIFFmemset((void*) tp, 0, npixels*sizeof (tp[0])); -@@ -334,11 +349,13 @@ - cc = tif->tif_rawcc; - /* get each byte string */ - for (shft = 4*8; (shft -= 8) >= 0; ) { -- for (i = 0; i < npixels && cc > 0; ) -+ for (i = 0; i < npixels && cc > 0; ) { - if (*bp >= 128) { /* run */ -+ if( cc < 2 ) -+ break; - rc = *bp++ + (2-128); - b = (uint32)*bp++ << shft; -- cc -= 2; /* TODO: potential input buffer overrun when decoding corrupt or truncated data */ -+ cc -= 2; - while (rc-- && i < npixels) - tp[i++] |= b; - } else { /* non-run */ -@@ -346,6 +363,7 @@ - while (--cc && rc-- && i < npixels) - tp[i++] |= (uint32)*bp++ << shft; - } -+ } - if (i != npixels) { - #if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) - TIFFErrorExt(tif->tif_clientdata, module, -@@ -407,6 +425,7 @@ - static int - LogL16Encode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) - { -+ static const char module[] = "LogL16Encode"; - LogLuvState* sp = EncoderState(tif); - int shft; - tmsize_t i; -@@ -427,7 +446,11 @@ - tp = (int16*) bp; - else { - tp = (int16*) sp->tbuf; -- assert(sp->tbuflen >= npixels); -+ if(sp->tbuflen < npixels) { -+ TIFFErrorExt(tif->tif_clientdata, module, -+ "Translation buffer too short"); -+ return (0); -+ } - (*sp->tfunc)(sp, bp, npixels); - } - /* compress each byte string */ -@@ -500,6 +523,7 @@ - static int - LogLuvEncode24(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) - { -+ static const char module[] = "LogLuvEncode24"; - LogLuvState* sp = EncoderState(tif); - tmsize_t i; - tmsize_t npixels; -@@ -515,7 +539,11 @@ - tp = (uint32*) bp; - else { - tp = (uint32*) sp->tbuf; -- assert(sp->tbuflen >= npixels); -+ if(sp->tbuflen < npixels) { -+ TIFFErrorExt(tif->tif_clientdata, module, -+ "Translation buffer too short"); -+ return (0); -+ } - (*sp->tfunc)(sp, bp, npixels); - } - /* write out encoded pixels */ -@@ -547,6 +575,7 @@ - static int - LogLuvEncode32(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) - { -+ static const char module[] = "LogLuvEncode32"; - LogLuvState* sp = EncoderState(tif); - int shft; - tmsize_t i; -@@ -568,7 +597,11 @@ - tp = (uint32*) bp; - else { - tp = (uint32*) sp->tbuf; -- assert(sp->tbuflen >= npixels); -+ if(sp->tbuflen < npixels) { -+ TIFFErrorExt(tif->tif_clientdata, module, -+ "Translation buffer too short"); -+ return (0); -+ } - (*sp->tfunc)(sp, bp, npixels); - } - /* compress each byte string */ diff --git a/third_party/libtiff/0004-CVE-2015-8784.patch b/third_party/libtiff/0004-CVE-2015-8784.patch deleted file mode 100644 index e4415de6c1..0000000000 --- a/third_party/libtiff/0004-CVE-2015-8784.patch +++ /dev/null @@ -1,50 +0,0 @@ -From b18012dae552f85dcc5c57d3bf4e997a15b1cc1c Mon Sep 17 00:00:00 2001 -From: erouault -Date: Sun, 27 Dec 2015 16:55:20 +0000 -Subject: [PATCH] * libtiff/tif_next.c: fix potential out-of-bound write in - NeXTDecode() triggered by http://lcamtuf.coredump.cx/afl/vulns/libtiff5.tif - (bugzilla #2508) - ---- - ChangeLog | 6 ++++++ - libtiff/tif_next.c | 10 ++++++++-- - 2 files changed, 14 insertions(+), 2 deletions(-) - -diff --git a/libtiff/tif_next.c b/libtiff/tif_next.c -index dd669cc..0a5b635 100644 ---- a/libtiff/tif_next.c -+++ b/libtiff/tif_next.c -@@ -37,7 +37,7 @@ - case 0: op[0] = (unsigned char) ((v) << 6); break; \ - case 1: op[0] |= (v) << 4; break; \ - case 2: op[0] |= (v) << 2; break; \ -- case 3: *op++ |= (v); break; \ -+ case 3: *op++ |= (v); op_offset++; break; \ - } \ - } - -@@ -106,6 +106,7 @@ NeXTDecode(TIFF* tif, uint8* buf, tmsize_t occ, uint16 s) - uint32 imagewidth = tif->tif_dir.td_imagewidth; - if( isTiled(tif) ) - imagewidth = tif->tif_dir.td_tilewidth; -+ tmsize_t op_offset = 0; - - /* - * The scanline is composed of a sequence of constant -@@ -122,10 +123,15 @@ NeXTDecode(TIFF* tif, uint8* buf, tmsize_t occ, uint16 s) - * bounds, potentially resulting in a security - * issue. - */ -- while (n-- > 0 && npixels < imagewidth) -+ while (n-- > 0 && npixels < imagewidth && op_offset < scanline) - SETPIXEL(op, grey); - if (npixels >= imagewidth) - break; -+ if (op_offset >= scanline ) { -+ TIFFErrorExt(tif->tif_clientdata, module, "Invalid data for scanline %ld", -+ (long) tif->tif_row); -+ return (0); -+ } - if (cc == 0) - goto bad; - n = *bp++, cc--; diff --git a/third_party/libtiff/0006-HeapBufferOverflow-ChopUpSingleUncompressedStrip.patch b/third_party/libtiff/0006-HeapBufferOverflow-ChopUpSingleUncompressedStrip.patch index 583f068c95..cdb8fc6fdf 100644 --- a/third_party/libtiff/0006-HeapBufferOverflow-ChopUpSingleUncompressedStrip.patch +++ b/third_party/libtiff/0006-HeapBufferOverflow-ChopUpSingleUncompressedStrip.patch @@ -1,7 +1,7 @@ -diff --git a/core/fxcodec/codec/fx_codec_tiff.cpp b/core/fxcodec/codec/fx_codec_tiff.cpp +diff --git a/core/fxcodec/codec/ccodec_tiffmodule.cpp b/core/fxcodec/codec/ccodec_tiffmodule.cpp index 09cfea4..20fda63 100644 ---- a/core/fxcodec/codec/fx_codec_tiff.cpp -+++ b/core/fxcodec/codec/fx_codec_tiff.cpp +--- a/core/fxcodec/codec/ccodec_tiffmodule.cpp ++++ b/core/fxcodec/codec/ccodec_tiffmodule.cpp @@ -79,6 +79,10 @@ int _TIFFmemcmp(const void* ptr1, const void* ptr2, tmsize_t size) { return FXSYS_memcmp(ptr1, ptr2, (size_t)size); } diff --git a/third_party/libtiff/0009-HeapBufferOverflow-PixarLogDecode.patch b/third_party/libtiff/0009-HeapBufferOverflow-PixarLogDecode.patch deleted file mode 100644 index 57dbe2efb7..0000000000 --- a/third_party/libtiff/0009-HeapBufferOverflow-PixarLogDecode.patch +++ /dev/null @@ -1,33 +0,0 @@ -diff --git a/third_party/libtiff/tif_pixarlog.c b/third_party/libtiff/tif_pixarlog.c -index b93b4c7..0674fa4 100644 ---- a/third_party/libtiff/tif_pixarlog.c -+++ b/third_party/libtiff/tif_pixarlog.c -@@ -457,6 +457,7 @@ horizontalAccumulate8abgr(uint16 *wp, int n, int stride, unsigned char *op, - typedef struct { - TIFFPredictorState predict; - z_stream stream; -+ tmsize_t tbuf_size; /* only set/used on reading for now */ - uint16 *tbuf; - uint16 stride; - int state; -@@ -692,6 +693,7 @@ PixarLogSetupDecode(TIFF* tif) - sp->tbuf = (uint16 *) _TIFFmalloc(tbuf_size); - if (sp->tbuf == NULL) - return (0); -+ sp->tbuf_size = tbuf_size; - if (sp->user_datafmt == PIXARLOGDATAFMT_UNKNOWN) - sp->user_datafmt = PixarLogGuessDataFmt(td); - if (sp->user_datafmt == PIXARLOGDATAFMT_UNKNOWN) { -@@ -781,6 +783,12 @@ PixarLogDecode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s) - TIFFErrorExt(tif->tif_clientdata, module, "ZLib cannot deal with buffers this size"); - return (0); - } -+ /* Check that we will not fill more than what was allocated */ -+ if ((tmsize_t)sp->stream.avail_out > sp->tbuf_size) -+ { -+ TIFFErrorExt(tif->tif_clientdata, module, "sp->stream.avail_out > sp->tbuf_size"); -+ return (0); -+ } - do { - int state = inflate(&sp->stream, Z_PARTIAL_FLUSH); - if (state == Z_STREAM_END) { diff --git a/third_party/libtiff/0011-fix-leak-imagebegin2.patch b/third_party/libtiff/0011-fix-leak-imagebegin2.patch index 91f82c939e..6d8e402ea7 100644 --- a/third_party/libtiff/0011-fix-leak-imagebegin2.patch +++ b/third_party/libtiff/0011-fix-leak-imagebegin2.patch @@ -1,41 +1,32 @@ diff --git a/third_party/libtiff/tif_getimage.c b/third_party/libtiff/tif_getimage.c -index 97fa94d..1cf6ac6 100644 +index 66ace060e..6e605c441 100644 --- a/third_party/libtiff/tif_getimage.c +++ b/third_party/libtiff/tif_getimage.c -@@ -267,6 +267,13 @@ TIFFRGBAImageBegin(TIFFRGBAImage* img, TIFF* tif, int stop, char emsg[1024]) - img->redcmap = NULL; - img->greencmap = NULL; - img->bluecmap = NULL; -+ img->Map = NULL; -+ img->BWmap = NULL; -+ img->PALmap = NULL; -+ img->ycbcr = NULL; -+ img->cielab = NULL; -+ img->UaToAa = NULL; -+ img->Bitdepth16To8 = NULL; - img->req_orientation = ORIENTATION_BOTLEFT; /* It is the default */ +@@ -284,6 +283,13 @@ TIFFRGBAImageBegin(TIFFRGBAImage* img, TIFF* tif, int stop, char emsg[1024]) + img->redcmap = NULL; + img->greencmap = NULL; + img->bluecmap = NULL; ++ img->Map = NULL; ++ img->BWmap = NULL; ++ img->PALmap = NULL; ++ img->ycbcr = NULL; ++ img->cielab = NULL; ++ img->UaToAa = NULL; ++ img->Bitdepth16To8 = NULL; + img->req_orientation = ORIENTATION_BOTLEFT; /* It is the default */ - img->tif = tif; -@@ -452,13 +459,6 @@ TIFFRGBAImageBegin(TIFFRGBAImage* img, TIFF* tif, int stop, char emsg[1024]) - photoTag, img->photometric); + img->tif = tif; +@@ -476,13 +468,6 @@ TIFFRGBAImageBegin(TIFFRGBAImage* img, TIFF* tif, int stop, char emsg[1024]) + photoTag, img->photometric); goto fail_return; - } -- img->Map = NULL; -- img->BWmap = NULL; -- img->PALmap = NULL; -- img->ycbcr = NULL; -- img->cielab = NULL; -- img->UaToAa = NULL; -- img->Bitdepth16To8 = NULL; - TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &img->width); - TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &img->height); - TIFFGetFieldDefaulted(tif, TIFFTAG_ORIENTATION, &img->orientation); -@@ -478,7 +478,7 @@ TIFFRGBAImageBegin(TIFFRGBAImage* img, TIFF* tif, int stop, char emsg[1024]) - return 1; - - fail_return: -- TIFFRGBAImageEnd(img); -+ TIFFRGBAImageEnd( img ); - return 0; - } - \ No newline at end of file + } +- img->Map = NULL; +- img->BWmap = NULL; +- img->PALmap = NULL; +- img->ycbcr = NULL; +- img->cielab = NULL; +- img->UaToAa = NULL; +- img->Bitdepth16To8 = NULL; + TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &img->width); + TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &img->height); + TIFFGetFieldDefaulted(tif, TIFFTAG_ORIENTATION, &img->orientation); diff --git a/third_party/libtiff/0015-fix-leaks-in-tif_ojpeg.patch b/third_party/libtiff/0015-fix-leaks-in-tif_ojpeg.patch index e9d3a408bf..d2ddd4aad6 100644 --- a/third_party/libtiff/0015-fix-leaks-in-tif_ojpeg.patch +++ b/third_party/libtiff/0015-fix-leaks-in-tif_ojpeg.patch @@ -1,37 +1,43 @@ diff --git a/third_party/libtiff/tif_ojpeg.c b/third_party/libtiff/tif_ojpeg.c -index cc5449cd6..f69b00148 100644 +index e128887bf..465f9ebc4 100644 --- a/third_party/libtiff/tif_ojpeg.c +++ b/third_party/libtiff/tif_ojpeg.c -@@ -1790,7 +1790,10 @@ OJPEGReadHeaderInfoSecTablesQTable(TIFF* tif) - TIFFSeekFile(tif,sp->qtable_offset[m],SEEK_SET); - p=TIFFReadFile(tif,&ob[sizeof(uint32)+5],64); - if (p!=64) -+ { -+ _TIFFfree(ob); - return(0); -+ } - sp->qtable[m]=ob; - sp->sof_tq[m]=m; - } -@@ -1854,7 +1857,10 @@ OJPEGReadHeaderInfoSecTablesDcTable(TIFF* tif) - rb[sizeof(uint32)+5+n]=o[n]; - p=TIFFReadFile(tif,&(rb[sizeof(uint32)+21]),q); - if (p!=q) -+ { -+ _TIFFfree(rb); - return(0); -+ } - sp->dctable[m]=rb; - sp->sos_tda[m]=(m<<4); - } -@@ -1918,7 +1924,10 @@ OJPEGReadHeaderInfoSecTablesAcTable(TIFF* tif) - rb[sizeof(uint32)+5+n]=o[n]; - p=TIFFReadFile(tif,&(rb[sizeof(uint32)+21]),q); - if (p!=q) -+ { -+ _TIFFfree(rb); - return(0); -+ } - sp->actable[m]=rb; - sp->sos_tda[m]=(sp->sos_tda[m]|m); - } +@@ -1791,7 +1791,12 @@ OJPEGReadHeaderInfoSecTablesQTable(TIFF* tif) + TIFFSeekFile(tif,sp->qtable_offset[m],SEEK_SET); + p=(uint32)TIFFReadFile(tif,&ob[sizeof(uint32)+5],64); + if (p!=64) ++ { ++ _TIFFfree(ob); + return(0); ++ } ++ if (sp->qtable[m]!=0) ++ _TIFFfree(sp->qtable[m]); + sp->qtable[m]=ob; + sp->sof_tq[m]=m; + } +@@ -1860,7 +1855,12 @@ OJPEGReadHeaderInfoSecTablesDcTable(TIFF* tif) + rb[sizeof(uint32)+5+n]=o[n]; + p=(uint32)TIFFReadFile(tif,&(rb[sizeof(uint32)+21]),q); + if (p!=q) ++ { ++ _TIFFfree(rb); + return(0); ++ } ++ if (sp->dctable[m]!=0) ++ _TIFFfree(sp->dctable[m]); + sp->dctable[m]=rb; + sp->sos_tda[m]=(m<<4); + } +@@ -1929,7 +1919,12 @@ OJPEGReadHeaderInfoSecTablesAcTable(TIFF* tif) + rb[sizeof(uint32)+5+n]=o[n]; + p=(uint32)TIFFReadFile(tif,&(rb[sizeof(uint32)+21]),q); + if (p!=q) ++ { ++ _TIFFfree(rb); + return(0); ++ } ++ if (sp->actable[m]) ++ _TIFFfree(sp->actable[m]); + sp->actable[m]=rb; + sp->sos_tda[m]=(sp->sos_tda[m]|m); + } diff --git a/third_party/libtiff/0016-fix-leak-in-pixarlogsetupdecode.patch b/third_party/libtiff/0016-fix-leak-in-pixarlogsetupdecode.patch deleted file mode 100644 index c49e676c34..0000000000 --- a/third_party/libtiff/0016-fix-leak-in-pixarlogsetupdecode.patch +++ /dev/null @@ -1,24 +0,0 @@ -diff --git a/third_party/libtiff/tif_pixarlog.c b/third_party/libtiff/tif_pixarlog.c -index 29535d31e..80006d5b1 100644 ---- a/third_party/libtiff/tif_pixarlog.c -+++ b/third_party/libtiff/tif_pixarlog.c -@@ -697,6 +697,9 @@ PixarLogSetupDecode(TIFF* tif) - if (sp->user_datafmt == PIXARLOGDATAFMT_UNKNOWN) - sp->user_datafmt = PixarLogGuessDataFmt(td); - if (sp->user_datafmt == PIXARLOGDATAFMT_UNKNOWN) { -+ _TIFFfree(sp->tbuf); -+ sp->tbuf = NULL; -+ sp->tbuf_size = 0; - TIFFErrorExt(tif->tif_clientdata, module, - "PixarLog compression can't handle bits depth/data format combination (depth: %d)", - td->td_bitspersample); -@@ -704,6 +707,9 @@ PixarLogSetupDecode(TIFF* tif) - } - - if (inflateInit(&sp->stream) != Z_OK) { -+ _TIFFfree(sp->tbuf); -+ sp->tbuf = NULL; -+ sp->tbuf_size = 0; - TIFFErrorExt(tif->tif_clientdata, module, "%s", sp->stream.msg); - return (0); - } else { diff --git a/third_party/libtiff/0017-safe_skews_in_gtTileContig.patch b/third_party/libtiff/0017-safe_skews_in_gtTileContig.patch index 10c5077392..ad6d33daee 100644 --- a/third_party/libtiff/0017-safe_skews_in_gtTileContig.patch +++ b/third_party/libtiff/0017-safe_skews_in_gtTileContig.patch @@ -1,5 +1,5 @@ diff --git a/third_party/libtiff/tif_getimage.c b/third_party/libtiff/tif_getimage.c -index 2861cdd1e..5ed1b7a37 100644 +index 84cc1d1a7..82e19164e 100644 --- a/third_party/libtiff/tif_getimage.c +++ b/third_party/libtiff/tif_getimage.c @@ -31,6 +31,7 @@ @@ -10,7 +10,7 @@ index 2861cdd1e..5ed1b7a37 100644 static int gtTileContig(TIFFRGBAImage*, uint32*, uint32, uint32); static int gtTileSeparate(TIFFRGBAImage*, uint32*, uint32, uint32); -@@ -612,6 +613,7 @@ gtTileContig(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) +@@ -629,6 +628,7 @@ gtTileContig(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) uint32 tw, th; unsigned char* buf; int32 fromskew, toskew; @@ -18,22 +18,23 @@ index 2861cdd1e..5ed1b7a37 100644 uint32 nrow; int ret = 1, flip; uint32 this_tw, tocol; -@@ -631,19 +633,37 @@ gtTileContig(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) +@@ -649,19 +647,37 @@ gtTileContig(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) flip = setorientation(img); if (flip & FLIP_VERTICALLY) { - y = h - 1; -- toskew = -(int32)(tw + w); -+ safeskew = 0; -+ safeskew -= tw; -+ safeskew -= w; + y = h - 1; +- toskew = -(int32)(tw + w); ++ safeskew = 0; ++ safeskew -= tw; ++ safeskew -= w; } else { - y = 0; -- toskew = -(int32)(tw - w); -+ safeskew = 0; -+ safeskew -= tw; -+ safeskew +=w; + y = 0; +- toskew = -(int32)(tw - w); ++ safeskew = 0; ++ safeskew -= tw; ++ safeskew +=w; } + + if(safeskew > INT_MAX || safeskew < INT_MIN){ + _TIFFfree(buf); + TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "%s", "Invalid skew"); @@ -41,9 +42,8 @@ index 2861cdd1e..5ed1b7a37 100644 + } + toskew = safeskew; + - /* - * Leftmost tile is clipped on left side if col_offset > 0. + * Leftmost tile is clipped on left side if col_offset > 0. */ leftmost_fromskew = img->col_offset % tw; leftmost_tw = tw - leftmost_fromskew; @@ -59,30 +59,30 @@ index 2861cdd1e..5ed1b7a37 100644 for (row = 0; row < h; row += nrow) { rowstoread = th - (row + img->row_offset) % th; -@@ -668,9 +688,24 @@ gtTileContig(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) - /* - * Rightmost tile is clipped on right side. - */ -- fromskew = tw - (w - tocol); -+ safeskew = tw; -+ safeskew -= w; -+ safeskew += tocol; -+ if(safeskew > INT_MAX || safeskew < INT_MIN){ -+ _TIFFfree(buf); -+ TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "%s", "Invalid skew"); -+ return (0); -+ } -+ fromskew = safeskew; - this_tw = tw - fromskew; -- this_toskew = toskew + 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); -+ } -+ this_toskew = safeskew; - } - (*put)(img, raster+y*w+tocol, tocol, y, this_tw, nrow, fromskew, this_toskew, buf + pos); - tocol += this_tw; +@@ -704,9 +684,24 @@ gtTileContig(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h) + /* + * Rightmost tile is clipped on right side. + */ +- fromskew = tw - (w - tocol); ++ safeskew = tw; ++ safeskew -= w; ++ safeskew += tocol; ++ if(safeskew > INT_MAX || safeskew < INT_MIN){ ++ _TIFFfree(buf); ++ TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "%s", "Invalid skew"); ++ return (0); ++ } ++ fromskew = safeskew; + this_tw = tw - fromskew; +- this_toskew = toskew + 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); ++ } ++ this_toskew = safeskew; + } + (*put)(img, raster+y*w+tocol, tocol, y, this_tw, nrow, fromskew, this_toskew, buf + pos); + tocol += this_tw; diff --git a/third_party/libtiff/0018-fix-leak-in-PredictorSetupDecode.patch b/third_party/libtiff/0018-fix-leak-in-PredictorSetupDecode.patch index a18df77409..e7758eb573 100644 --- a/third_party/libtiff/0018-fix-leak-in-PredictorSetupDecode.patch +++ b/third_party/libtiff/0018-fix-leak-in-PredictorSetupDecode.patch @@ -1,39 +1,15 @@ -diff --git a/third_party/libtiff/tif_pixarlog.c b/third_party/libtiff/tif_pixarlog.c -index 80006d5b1..29535d31e 100644 ---- a/third_party/libtiff/tif_pixarlog.c -+++ b/third_party/libtiff/tif_pixarlog.c -@@ -697,9 +697,6 @@ PixarLogSetupDecode(TIFF* tif) - if (sp->user_datafmt == PIXARLOGDATAFMT_UNKNOWN) - sp->user_datafmt = PixarLogGuessDataFmt(td); - if (sp->user_datafmt == PIXARLOGDATAFMT_UNKNOWN) { -- _TIFFfree(sp->tbuf); -- sp->tbuf = NULL; -- sp->tbuf_size = 0; - TIFFErrorExt(tif->tif_clientdata, module, - "PixarLog compression can't handle bits depth/data format combination (depth: %d)", - td->td_bitspersample); -@@ -707,9 +704,6 @@ PixarLogSetupDecode(TIFF* tif) - } - - if (inflateInit(&sp->stream) != Z_OK) { -- _TIFFfree(sp->tbuf); -- sp->tbuf = NULL; -- sp->tbuf_size = 0; - TIFFErrorExt(tif->tif_clientdata, module, "%s", sp->stream.msg); - return (0); - } else { diff --git a/third_party/libtiff/tif_predict.c b/third_party/libtiff/tif_predict.c -index 1388dde59..8975672ae 100644 +index 1bb78e209..0b185d2e2 100644 --- a/third_party/libtiff/tif_predict.c +++ b/third_party/libtiff/tif_predict.c -@@ -109,7 +109,10 @@ PredictorSetupDecode(TIFF* tif) - TIFFDirectory* td = &tif->tif_dir; +@@ -118,7 +118,10 @@ PredictorSetupDecode(TIFF* tif) + TIFFDirectory* td = &tif->tif_dir; - if (!(*sp->setupdecode)(tif) || !PredictorSetup(tif)) -+ { -+ (*tif->tif_cleanup)(tif); - return 0; -+ } + if (!(*sp->setupdecode)(tif) || !PredictorSetup(tif)) ++ { ++ (*tif->tif_cleanup)(tif); + return 0; ++ } - if (sp->predictor == 2) { - switch (td->td_bitspersample) { + if (sp->predictor == 2) { + switch (td->td_bitspersample) { diff --git a/third_party/libtiff/0019-fix-invalid-reads-TIFFFetchNormalTag.patch b/third_party/libtiff/0019-fix-invalid-reads-TIFFFetchNormalTag.patch deleted file mode 100644 index 9ebb7ef8db..0000000000 --- a/third_party/libtiff/0019-fix-invalid-reads-TIFFFetchNormalTag.patch +++ /dev/null @@ -1,28 +0,0 @@ -diff --git a/third_party/libtiff/tif_dirread.c b/third_party/libtiff/tif_dirread.c -index bc4102184..0e3f8ccd4 100644 ---- a/third_party/libtiff/tif_dirread.c -+++ b/third_party/libtiff/tif_dirread.c -@@ -4983,6 +4983,11 @@ TIFFFetchNormalTag(TIFF* tif, TIFFDirEntry* dp, int recover) - if (err==TIFFReadDirEntryErrOk) - { - int m; -+ if( dp->tdir_count > 0 && data[dp->tdir_count-1] != '\0' ) -+ { -+ TIFFWarningExt(tif->tif_clientdata,module,"ASCII value for tag \"%s\" does not end in null byte. Forcing it to be null",fip->field_name); -+ data[dp->tdir_count-1] = '\0'; -+ } - m=TIFFSetField(tif,dp->tdir_tag,(uint16)(dp->tdir_count),data); - if (data!=0) - _TIFFfree(data); -@@ -5155,6 +5160,11 @@ TIFFFetchNormalTag(TIFF* tif, TIFFDirEntry* dp, int recover) - if (err==TIFFReadDirEntryErrOk) - { - int m; -+ if( dp->tdir_count > 0 && data[dp->tdir_count-1] != '\0' ) -+ { -+ TIFFWarningExt(tif->tif_clientdata,module,"ASCII value for tag \"%s\" does not end in null byte. Forcing it to be null",fip->field_name); -+ data[dp->tdir_count-1] = '\0'; -+ } - m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data); - if (data!=0) - _TIFFfree(data); diff --git a/third_party/libtiff/0020-unreasonable-td-bitspersample.patch b/third_party/libtiff/0020-unreasonable-td-bitspersample.patch deleted file mode 100644 index 1ad5e34e3c..0000000000 --- a/third_party/libtiff/0020-unreasonable-td-bitspersample.patch +++ /dev/null @@ -1,22 +0,0 @@ -diff --git a/third_party/libtiff/tif_dirread.c b/third_party/libtiff/tif_dirread.c -index 0e3f8ccd4..e0403aef3 100644 ---- a/third_party/libtiff/tif_dirread.c -+++ b/third_party/libtiff/tif_dirread.c -@@ -3754,6 +3754,17 @@ TIFFReadDirectory(TIFF* tif) - fip ? fip->field_name : "unknown tagname"); - continue; - } -+ /* ColorMap or TransferFunction for high bit */ -+ /* depths do not make much sense and could be */ -+ /* used as a denial of service vector */ -+ if (tif->tif_dir.td_bitspersample > 24) -+ { -+ TIFFWarningExt(tif->tif_clientdata,module, -+ "Ignoring %s because BitsPerSample=%d>24", -+ fip ? fip->field_name : "unknown tagname", -+ tif->tif_dir.td_bitspersample); -+ continue; -+ } - countpersample=(1L<tif_dir.td_bitspersample); - if ((dp->tdir_tag==TIFFTAG_TRANSFERFUNCTION)&&(dp->tdir_count==(uint64)countpersample)) - { diff --git a/third_party/libtiff/0021-fix-leaks-ojpegreaderinfosectables.patch b/third_party/libtiff/0021-fix-leaks-ojpegreaderinfosectables.patch deleted file mode 100644 index e3b4bd8964..0000000000 --- a/third_party/libtiff/0021-fix-leaks-ojpegreaderinfosectables.patch +++ /dev/null @@ -1,31 +0,0 @@ -diff --git a/third_party/libtiff/tif_ojpeg.c b/third_party/libtiff/tif_ojpeg.c -index f69b00148..276d562df 100644 ---- a/third_party/libtiff/tif_ojpeg.c -+++ b/third_party/libtiff/tif_ojpeg.c -@@ -1794,6 +1794,8 @@ OJPEGReadHeaderInfoSecTablesQTable(TIFF* tif) - _TIFFfree(ob); - return(0); - } -+ if (sp->qtable[m]!=0) -+ _TIFFfree(sp->qtable[m]); - sp->qtable[m]=ob; - sp->sof_tq[m]=m; - } -@@ -1861,6 +1863,8 @@ OJPEGReadHeaderInfoSecTablesDcTable(TIFF* tif) - _TIFFfree(rb); - return(0); - } -+ if (sp->dctable[m]!=0) -+ _TIFFfree(sp->dctable[m]); - sp->dctable[m]=rb; - sp->sos_tda[m]=(m<<4); - } -@@ -1928,6 +1932,8 @@ OJPEGReadHeaderInfoSecTablesAcTable(TIFF* tif) - _TIFFfree(rb); - return(0); - } -+ if (sp->actable[m]) -+ _TIFFfree(sp->actable[m]); - sp->actable[m]=rb; - sp->sos_tda[m]=(sp->sos_tda[m]|m); - } diff --git a/third_party/libtiff/README.pdfium b/third_party/libtiff/README.pdfium index e4436d21fd..0b6b800604 100644 --- a/third_party/libtiff/README.pdfium +++ b/third_party/libtiff/README.pdfium @@ -1,6 +1,6 @@ Name: LibTIFF URL: http://www.remotesensing.org/libtiff/ -Version: 4.0.6 +Version: 4.0.7 Security Critical: yes License: BSD @@ -11,23 +11,15 @@ Local Modifications: 0000-build-config.patch: Local build configuration changes. 0001-build-config.patch: Enable HAVE_SEARCH_H in tiffconf.h for VS 2015 -0002-CVE-2015-8665-8683.patch: Security fixes -0003-CVE-2015-8781-8782-8783.patch: Security fixes -0004-CVE-2015-8784.patch: Security fixes 0005-Leak-TIFFFetchStripThing.patch: Fix a memory leak 0006-HeapBufferOverflow-ChopUpSingleUncompressedStrip.patch: Fix a heap buffer overflow 0007-uninitialized-value.patch: Fix potentially uninitialized dircount value 0008-HeapBufferOverflow-ChopUpSingleUncompressedStrip.patch: Fix a heap buffer overflow -0009-HeapBufferOverflow-PixarLogDecode.patch: Fix a heap buffer overflow 0010-fix-leak-imagebegin: Fix a leak when TIFFRGBAImageBegin fails 0011-fix-leak-imagebegin2: Apply upstream fix related to our previous patch 0012-initialize-tif-rawdata.patch: Initialize tif_rawdata to guard against unitialized access 0013-validate-refblackwhite.patch: Make sure the refblackwhite values aren't nan. 0014-cast-to-unsigned-in-putagreytile.patch: casting to avoid undefined shifts. 0015-fix-leaks-in-tif_ojpeg.patch: fix direct leaks in tif_ojpeg.c methods -0016-fix-leak-in-pixarlogsetupdecode.patch: Free sp->tbuf if setup fails 0017-safe_skews_in_gtTileContig.patch: return error if to/from skews overflow from int32. 0018-fix-leak-in-PredictorSetupDecode.patch: call tif->tif_cleanup if the setup fails. -0019-fix-invalid-reads-TIFFFetchNormalTag.patch: upstream security fix in tif_dirread. -0020-unreasonable-td-bitspersample.patch: upstream patch ignoring large td_bitspersample. -0021-fix-leaks-ojpegreaderinfosectables.patch: more direct leak fixes in tif_ojpeg.c. diff --git a/third_party/libtiff/tif_aux.c b/third_party/libtiff/tif_aux.c index bc4ea01928..74532c8c6f 100644 --- a/third_party/libtiff/tif_aux.c +++ b/third_party/libtiff/tif_aux.c @@ -1,4 +1,4 @@ -/* $Id: tif_aux.c,v 1.26 2010-07-01 15:33:28 dron Exp $ */ +/* $Id: tif_aux.c,v 1.29 2016-11-11 20:45:53 erouault Exp $ */ /* * Copyright (c) 1991-1997 Sam Leffler @@ -100,7 +100,8 @@ TIFFDefaultTransferFunction(TIFFDirectory* td) n = ((tmsize_t)1)<td_bitspersample; nbytes = n * sizeof (uint16); - if (!(tf[0] = (uint16 *)_TIFFmalloc(nbytes))) + tf[0] = (uint16 *)_TIFFmalloc(nbytes); + if (tf[0] == NULL) return 0; tf[0][0] = 0; for (i = 1; i < n; i++) { @@ -109,10 +110,12 @@ TIFFDefaultTransferFunction(TIFFDirectory* td) } if (td->td_samplesperpixel - td->td_extrasamples > 1) { - if (!(tf[1] = (uint16 *)_TIFFmalloc(nbytes))) + tf[1] = (uint16 *)_TIFFmalloc(nbytes); + if(tf[1] == NULL) goto bad; _TIFFmemcpy(tf[1], tf[0], nbytes); - if (!(tf[2] = (uint16 *)_TIFFmalloc(nbytes))) + tf[2] = (uint16 *)_TIFFmalloc(nbytes); + if (tf[2] == NULL) goto bad; _TIFFmemcpy(tf[2], tf[0], nbytes); } @@ -134,7 +137,8 @@ TIFFDefaultRefBlackWhite(TIFFDirectory* td) { int i; - if (!(td->td_refblackwhite = (float *)_TIFFmalloc(6*sizeof (float)))) + td->td_refblackwhite = (float *)_TIFFmalloc(6*sizeof (float)); + if (td->td_refblackwhite == NULL) return 0; if (td->td_photometric == PHOTOMETRIC_YCBCR) { /* @@ -163,7 +167,7 @@ TIFFDefaultRefBlackWhite(TIFFDirectory* td) * value if the tag is not present in the directory. * * NB: We use the value in the directory, rather than - * explcit values so that defaults exist only one + * explicit values so that defaults exist only one * place in the library -- in TIFFDefaultDirectory. */ int @@ -208,11 +212,18 @@ TIFFVGetFieldDefaulted(TIFF* tif, uint32 tag, va_list ap) *va_arg(ap, uint16 *) = td->td_resolutionunit; return (1); case TIFFTAG_PREDICTOR: - { - TIFFPredictorState* sp = (TIFFPredictorState*) tif->tif_data; - *va_arg(ap, uint16*) = (uint16) sp->predictor; - return 1; - } + { + TIFFPredictorState* sp = (TIFFPredictorState*) tif->tif_data; + if( sp == NULL ) + { + TIFFErrorExt(tif->tif_clientdata, tif->tif_name, + "Cannot get \"Predictor\" tag as plugin is not configured"); + *va_arg(ap, uint16*) = 0; + return 0; + } + *va_arg(ap, uint16*) = (uint16) sp->predictor; + return 1; + } case TIFFTAG_DOTRANGE: *va_arg(ap, uint16 *) = 0; *va_arg(ap, uint16 *) = (1<td_bitspersample)-1; diff --git a/third_party/libtiff/tif_close.c b/third_party/libtiff/tif_close.c index 13d2bab5ce..a0cb661311 100644 --- a/third_party/libtiff/tif_close.c +++ b/third_party/libtiff/tif_close.c @@ -1,4 +1,4 @@ -/* $Id: tif_close.c,v 1.19 2010-03-10 18:56:48 bfriesen Exp $ */ +/* $Id: tif_close.c,v 1.21 2016-01-23 21:20:34 erouault Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -36,7 +36,7 @@ /** * Auxiliary function to free the TIFF structure. Given structure will be - * completetly freed, so you should save opened file handle and pointer + * completely freed, so you should save opened file handle and pointer * to the close procedure in external variables before calling * _TIFFCleanup(), if you will need these ones to close the file. * @@ -62,11 +62,11 @@ TIFFCleanup(TIFF* tif) */ while( tif->tif_clientinfo ) { - TIFFClientInfoLink *link = tif->tif_clientinfo; + TIFFClientInfoLink *psLink = tif->tif_clientinfo; - tif->tif_clientinfo = link->next; - _TIFFfree( link->name ); - _TIFFfree( link ); + tif->tif_clientinfo = psLink->next; + _TIFFfree( psLink->name ); + _TIFFfree( psLink ); } if (tif->tif_rawdata && (tif->tif_flags&TIFF_MYBUFFER)) diff --git a/third_party/libtiff/tif_color.c b/third_party/libtiff/tif_color.c index be4850ce6b..89194c2076 100644 --- a/third_party/libtiff/tif_color.c +++ b/third_party/libtiff/tif_color.c @@ -1,4 +1,4 @@ -/* $Id: tif_color.c,v 1.19 2010-12-14 02:22:42 faxguy Exp $ */ +/* $Id: tif_color.c,v 1.22 2016-09-04 21:32:56 erouault Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -126,37 +126,37 @@ TIFFCIELabToRGBInit(TIFFCIELabToRGB* cielab, const TIFFDisplay *display, float *refWhite) { int i; - double gamma; + double dfGamma; cielab->range = CIELABTORGB_TABLE_RANGE; _TIFFmemcpy(&cielab->display, display, sizeof(TIFFDisplay)); /* Red */ - gamma = 1.0 / cielab->display.d_gammaR ; + dfGamma = 1.0 / cielab->display.d_gammaR ; cielab->rstep = (cielab->display.d_YCR - cielab->display.d_Y0R) / cielab->range; for(i = 0; i <= cielab->range; i++) { cielab->Yr2r[i] = cielab->display.d_Vrwr - * ((float)pow((double)i / cielab->range, gamma)); + * ((float)pow((double)i / cielab->range, dfGamma)); } /* Green */ - gamma = 1.0 / cielab->display.d_gammaG ; + dfGamma = 1.0 / cielab->display.d_gammaG ; cielab->gstep = (cielab->display.d_YCR - cielab->display.d_Y0R) / cielab->range; for(i = 0; i <= cielab->range; i++) { cielab->Yg2g[i] = cielab->display.d_Vrwg - * ((float)pow((double)i / cielab->range, gamma)); + * ((float)pow((double)i / cielab->range, dfGamma)); } /* Blue */ - gamma = 1.0 / cielab->display.d_gammaB ; + dfGamma = 1.0 / cielab->display.d_gammaB ; cielab->bstep = (cielab->display.d_YCR - cielab->display.d_Y0R) / cielab->range; for(i = 0; i <= cielab->range; i++) { cielab->Yb2b[i] = cielab->display.d_Vrwb - * ((float)pow((double)i / cielab->range, gamma)); + * ((float)pow((double)i / cielab->range, dfGamma)); } /* Init reference white point */ @@ -175,7 +175,7 @@ TIFFCIELabToRGBInit(TIFFCIELabToRGB* cielab, #define SHIFT 16 #define FIX(x) ((int32)((x) * (1L<(max)?(max):(f)) #define HICLAMP(f,max) ((f)>(max)?(max):(f)) @@ -186,7 +186,9 @@ TIFFYCbCrtoRGB(TIFFYCbCrToRGB *ycbcr, uint32 Y, int32 Cb, int32 Cr, int32 i; /* XXX: Only 8-bit YCbCr input supported for now */ - Y = HICLAMP(Y, 255), Cb = CLAMP(Cb, 0, 255), Cr = CLAMP(Cr, 0, 255); + Y = HICLAMP(Y, 255); + Cb = CLAMP(Cb, 0, 255); + Cr = CLAMP(Cr, 0, 255); i = ycbcr->Y_tab[Y] + ycbcr->Cr_r_tab[Cr]; *r = CLAMP(i, 0, 255); diff --git a/third_party/libtiff/tif_compress.c b/third_party/libtiff/tif_compress.c index 20e72fd073..b571d19545 100644 --- a/third_party/libtiff/tif_compress.c +++ b/third_party/libtiff/tif_compress.c @@ -1,4 +1,4 @@ -/* $Id: tif_compress.c,v 1.22 2010-03-10 18:56:48 bfriesen Exp $ */ +/* $Id: tif_compress.c,v 1.25 2016-10-25 20:04:22 erouault Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -82,10 +82,10 @@ TIFFNoDecode(TIFF* tif, const char* method) TIFFErrorExt(tif->tif_clientdata, tif->tif_name, "Compression scheme %u %s decoding is not implemented", tif->tif_dir.td_compression, method); - return (-1); + return (0); } -int +static int _TIFFNoFixupTags(TIFF* tif) { (void) tif; @@ -227,7 +227,7 @@ TIFFUnRegisterCODEC(TIFFCodec* c) codec_t* cd; codec_t** pcd; - for (pcd = ®isteredCODECS; (cd = *pcd); pcd = &cd->next) + for (pcd = ®isteredCODECS; (cd = *pcd) != NULL; pcd = &cd->next) if (cd->info == c) { *pcd = cd->next; _TIFFfree(cd); 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_bitspersample); + va_arg(ap, uint16*), 1U<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) diff --git a/third_party/libtiff/tif_dirinfo.c b/third_party/libtiff/tif_dirinfo.c index 7db4bdb95c..23ad002055 100644 --- a/third_party/libtiff/tif_dirinfo.c +++ b/third_party/libtiff/tif_dirinfo.c @@ -1,4 +1,4 @@ -/* $Id: tif_dirinfo.c,v 1.121 2014-05-07 01:58:46 bfriesen Exp $ */ +/* $Id: tif_dirinfo.c,v 1.126 2016-11-18 02:52:13 bfriesen Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -38,14 +38,22 @@ * NOTE: The second field (field_readcount) and third field (field_writecount) * sometimes use the values TIFF_VARIABLE (-1), TIFF_VARIABLE2 (-3) * and TIFF_SPP (-2). The macros should be used but would throw off - * the formatting of the code, so please interprete the -1, -2 and -3 + * the formatting of the code, so please interpret the -1, -2 and -3 * values accordingly. */ -static TIFFFieldArray tiffFieldArray; -static TIFFFieldArray exifFieldArray; - -static TIFFField +/* const object should be initialized */ +#ifdef _MSC_VER +#pragma warning( push ) +#pragma warning( disable : 4132 ) +#endif +static const TIFFFieldArray tiffFieldArray; +static const TIFFFieldArray exifFieldArray; +#ifdef _MSC_VER +#pragma warning( pop ) +#endif + +static const TIFFField tiffFields[] = { { TIFFTAG_SUBFILETYPE, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_SUBFILETYPE, 1, 0, "SubfileType", NULL }, { TIFFTAG_OSUBFILETYPE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_SUBFILETYPE, 1, 0, "OldSubfileType", NULL }, @@ -95,7 +103,7 @@ tiffFields[] = { { TIFFTAG_TILELENGTH, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UNDEFINED, FIELD_TILEDIMENSIONS, 0, 0, "TileLength", NULL }, { TIFFTAG_TILEOFFSETS, -1, 1, TIFF_LONG8, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_STRIPOFFSETS, 0, 0, "TileOffsets", NULL }, { TIFFTAG_TILEBYTECOUNTS, -1, 1, TIFF_LONG8, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_STRIPBYTECOUNTS, 0, 0, "TileByteCounts", NULL }, - { TIFFTAG_SUBIFD, -1, -1, TIFF_IFD8, 0, TIFF_SETGET_C16_IFD8, TIFF_SETGET_UNDEFINED, FIELD_SUBIFD, 1, 1, "SubIFD", &tiffFieldArray }, + { TIFFTAG_SUBIFD, -1, -1, TIFF_IFD8, 0, TIFF_SETGET_C16_IFD8, TIFF_SETGET_UNDEFINED, FIELD_SUBIFD, 1, 1, "SubIFD", (TIFFFieldArray*) &tiffFieldArray }, { TIFFTAG_INKSET, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "InkSet", NULL }, { TIFFTAG_INKNAMES, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_C16_ASCII, TIFF_SETGET_UNDEFINED, FIELD_INKNAMES, 1, 1, "InkNames", NULL }, { TIFFTAG_NUMBEROFINKS, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "NumberOfInks", NULL }, @@ -134,7 +142,7 @@ tiffFields[] = { /* end Pixar tags */ { TIFFTAG_RICHTIFFIPTC, -3, -3, TIFF_LONG, 0, TIFF_SETGET_C32_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "RichTIFFIPTC", NULL }, { TIFFTAG_PHOTOSHOP, -3, -3, TIFF_BYTE, 0, TIFF_SETGET_C32_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "Photoshop", NULL }, - { TIFFTAG_EXIFIFD, 1, 1, TIFF_IFD8, 0, TIFF_SETGET_IFD8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "EXIFIFDOffset", &exifFieldArray }, + { TIFFTAG_EXIFIFD, 1, 1, TIFF_IFD8, 0, TIFF_SETGET_IFD8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "EXIFIFDOffset", (TIFFFieldArray*) &exifFieldArray }, { TIFFTAG_ICCPROFILE, -3, -3, TIFF_UNDEFINED, 0, TIFF_SETGET_C32_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 1, "ICC Profile", NULL }, { TIFFTAG_GPSIFD, 1, 1, TIFF_IFD8, 0, TIFF_SETGET_IFD8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 0, 0, "GPSIFDOffset", NULL }, { TIFFTAG_FAXRECVPARAMS, 1, 1, TIFF_LONG, 0, TIFF_SETGET_UINT32, TIFF_SETGET_UINT32, FIELD_CUSTOM, TRUE, FALSE, "FaxRecvParams", NULL }, @@ -211,7 +219,7 @@ tiffFields[] = { /* begin pseudo tags */ }; -static TIFFField +static const TIFFField exifFields[] = { { EXIFTAG_EXPOSURETIME, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ExposureTime", NULL }, { EXIFTAG_FNUMBER, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_DOUBLE, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "FNumber", NULL }, @@ -271,13 +279,13 @@ exifFields[] = { { EXIFTAG_IMAGEUNIQUEID, 33, 33, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ImageUniqueID", NULL } }; -static TIFFFieldArray -tiffFieldArray = { tfiatImage, 0, TIFFArrayCount(tiffFields), tiffFields }; -static TIFFFieldArray -exifFieldArray = { tfiatExif, 0, TIFFArrayCount(exifFields), exifFields }; +static const TIFFFieldArray +tiffFieldArray = { tfiatImage, 0, TIFFArrayCount(tiffFields), (TIFFField*) tiffFields }; +static const TIFFFieldArray +exifFieldArray = { tfiatExif, 0, TIFFArrayCount(exifFields), (TIFFField*) exifFields }; /* - * We have our own local lfind() equivelent to avoid subtle differences + * We have our own local lfind() equivalent to avoid subtle differences * in types passed to lfind() on different systems. */ @@ -521,7 +529,7 @@ TIFFFindField(TIFF* tif, uint32 tag, TIFFDataType dt) return tif->tif_foundfield = (ret ? *ret : NULL); } -const TIFFField* +static const TIFFField* _TIFFFindFieldByName(TIFF* tif, const char *field_name, TIFFDataType dt) { TIFFField key = {0, 0, 0, TIFF_NOTYPE, 0, 0, 0, 0, 0, 0, NULL, NULL}; @@ -713,7 +721,7 @@ _TIFFCreateAnonField(TIFF *tif, uint32 tag, TIFFDataType field_type) * note that this name is a special sign to TIFFClose() and * _TIFFSetupFields() to free the field */ - snprintf(fld->field_name, 32, "Tag %d", (int) tag); + (void) snprintf(fld->field_name, 32, "Tag %d", (int) tag); return fld; } diff --git a/third_party/libtiff/tif_dirread.c b/third_party/libtiff/tif_dirread.c index e0403aef31..7dd9444834 100644 --- a/third_party/libtiff/tif_dirread.c +++ b/third_party/libtiff/tif_dirread.c @@ -1,4 +1,4 @@ -/* $Id: tif_dirread.c,v 1.191 2015-09-05 20:31:41 bfriesen Exp $ */ +/* $Id: tif_dirread.c,v 1.204 2016-11-16 15:14:15 erouault Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -166,6 +166,8 @@ static int TIFFFetchSubjectDistance(TIFF*, TIFFDirEntry*); static void ChopUpSingleUncompressedStrip(TIFF*); static uint64 TIFFReadUInt64(const uint8 *value); +static int _TIFFFillStrilesInternal( TIFF *tif, int loadStripByteCount ); + typedef union _UInt64Aligned_t { double d; @@ -3457,12 +3459,12 @@ TIFFReadDirectory(TIFF* tif) * the fields to check type and tag information, * and to extract info required to size data * structures. A second pass is made afterwards - * to read in everthing not taken in the first pass. + * to read in everything not taken in the first pass. * But we must process the Compression tag first * in order to merge in codec-private tag definitions (otherwise * we may get complaints about unknown tags). However, the * Compression tag may be dependent on the SamplesPerPixel - * tag value because older TIFF specs permited Compression + * tag value because older TIFF specs permitted Compression * to be written as a SamplesPerPixel-count tag entry. * Thus if we don't first figure out the correct SamplesPerPixel * tag value then we may end up ignoring the Compression tag @@ -3626,6 +3628,7 @@ TIFFReadDirectory(TIFF* tif) if (tif->tif_dir.td_planarconfig == PLANARCONFIG_SEPARATE) tif->tif_dir.td_stripsperimage /= tif->tif_dir.td_samplesperpixel; if (!TIFFFieldSet(tif, FIELD_STRIPOFFSETS)) { +#ifdef OJPEG_SUPPORT if ((tif->tif_dir.td_compression==COMPRESSION_OJPEG) && (isTiled(tif)==0) && (tif->tif_dir.td_nstrips==1)) { @@ -3638,7 +3641,9 @@ TIFFReadDirectory(TIFF* tif) * JpegInterchangeFormat stream. */ TIFFSetFieldBit(tif, FIELD_STRIPOFFSETS); - } else { + } else +#endif + { MissingRequired(tif, isTiled(tif) ? "TileOffsets" : "StripOffsets"); goto bad; @@ -3663,7 +3668,7 @@ TIFFReadDirectory(TIFF* tif) * DataType and SampleFormat tags are supposed to be * written as one value/sample, but some vendors * incorrectly write one value only -- so we accept - * that as well (yech). Other vendors write correct + * that as well (yuck). Other vendors write correct * value for NumberOfSamples, but incorrect one for * BitsPerSample and friends, and we will read this * too. @@ -3690,7 +3695,7 @@ TIFFReadDirectory(TIFF* tif) case TIFFTAG_SMAXSAMPLEVALUE: { - double *data; + double *data = NULL; enum TIFFReadDirEntryErr err; uint32 saved_flags; int m; @@ -3741,7 +3746,7 @@ TIFFReadDirectory(TIFF* tif) uint32 countrequired; uint32 incrementpersample; uint16* value=NULL; - /* It would be dangerous to instanciate those tag values */ + /* It would be dangerous to instantiate those tag values */ /* since if td_bitspersample has not yet been read (due to */ /* unordered tags), it could be read afterwards with a */ /* values greater than the default one (1), which may cause */ @@ -3759,13 +3764,14 @@ TIFFReadDirectory(TIFF* tif) /* used as a denial of service vector */ if (tif->tif_dir.td_bitspersample > 24) { + fip = TIFFFieldWithTag(tif,dp->tdir_tag); TIFFWarningExt(tif->tif_clientdata,module, "Ignoring %s because BitsPerSample=%d>24", fip ? fip->field_name : "unknown tagname", tif->tif_dir.td_bitspersample); continue; } - countpersample=(1L<tif_dir.td_bitspersample); + countpersample=(1U<tif_dir.td_bitspersample); if ((dp->tdir_tag==TIFFTAG_TRANSFERFUNCTION)&&(dp->tdir_count==(uint64)countpersample)) { countrequired=countpersample; @@ -4153,7 +4159,7 @@ TIFFReadDirectoryFindFieldInfo(TIFF* tif, uint16 tagid, uint32* fii) } /* - * Read custom directory from the arbitarry offset. + * Read custom directory from the arbitrary offset. * The code is very similar to TIFFReadDirectory(). */ int @@ -4280,8 +4286,9 @@ EstimateStripByteCounts(TIFF* tif, TIFFDirEntry* dir, uint16 dircount) TIFFDirectory *td = &tif->tif_dir; uint32 strip; - if( !_TIFFFillStriles( tif ) ) - return -1; + /* Do not try to load stripbytecount as we will compute it */ + if( !_TIFFFillStrilesInternal( tif, 0 ) ) + return -1; if (td->td_stripbytecount) _TIFFfree(td->td_stripbytecount); @@ -4303,7 +4310,7 @@ EstimateStripByteCounts(TIFF* tif, TIFFDirEntry* dir, uint16 dircount) /* calculate amount of space used by indirect values */ for (dp = dir, n = dircount; n > 0; n--, dp++) { - uint32 typewidth = TIFFDataWidth((TIFFDataType) dp->tdir_type); + uint32 typewidth; uint64 datasize; typewidth = TIFFDataWidth((TIFFDataType) dp->tdir_type); if (typewidth == 0) { @@ -4393,7 +4400,7 @@ TIFFCheckDirOffset(TIFF* tif, uint64 diroff) tif->tif_dirnumber++; - if (tif->tif_dirnumber > tif->tif_dirlistsize) { + if (tif->tif_dirlist == NULL || tif->tif_dirnumber > tif->tif_dirlistsize) { uint64* new_dirlist; /* @@ -4583,7 +4590,6 @@ TIFFFetchDirectory(TIFF* tif, uint64 diroff, TIFFDirEntry** pdir, } else { - tmsize_t m; uint64 dircount64; m=off+sizeof(uint64); if ((mtif->tif_size)) { @@ -4994,7 +5000,7 @@ TIFFFetchNormalTag(TIFF* tif, TIFFDirEntry* dp, int recover) if (err==TIFFReadDirEntryErrOk) { int m; - if( dp->tdir_count > 0 && data[dp->tdir_count-1] != '\0' ) + if( dp->tdir_count > 0 && data[dp->tdir_count-1] != '\0' ) { TIFFWarningExt(tif->tif_clientdata,module,"ASCII value for tag \"%s\" does not end in null byte. Forcing it to be null",fip->field_name); data[dp->tdir_count-1] = '\0'; @@ -5171,7 +5177,7 @@ TIFFFetchNormalTag(TIFF* tif, TIFFDirEntry* dp, int recover) if (err==TIFFReadDirEntryErrOk) { int m; - if( dp->tdir_count > 0 && data[dp->tdir_count-1] != '\0' ) + if( dp->tdir_count > 0 && data[dp->tdir_count-1] != '\0' ) { TIFFWarningExt(tif->tif_clientdata,module,"ASCII value for tag \"%s\" does not end in null byte. Forcing it to be null",fip->field_name); data[dp->tdir_count-1] = '\0'; @@ -5580,6 +5586,11 @@ ChopUpSingleUncompressedStrip(TIFF* tif) } int _TIFFFillStriles( TIFF *tif ) +{ + return _TIFFFillStrilesInternal( tif, 1 ); +} + +static int _TIFFFillStrilesInternal( TIFF *tif, int loadStripByteCount ) { #if defined(DEFER_STRILE_LOAD) register TIFFDirectory *td = &tif->tif_dir; @@ -5597,7 +5608,8 @@ int _TIFFFillStriles( TIFF *tif ) return_value = 0; } - if (!TIFFFetchStripThing(tif,&(td->td_stripbytecount_entry), + if (loadStripByteCount && + !TIFFFetchStripThing(tif,&(td->td_stripbytecount_entry), td->td_nstrips,&td->td_stripbytecount)) { return_value = 0; @@ -5622,6 +5634,7 @@ int _TIFFFillStriles( TIFF *tif ) return return_value; #else /* !defined(DEFER_STRILE_LOAD) */ (void) tif; + (void) loadStripByteCount; return 1; #endif } diff --git a/third_party/libtiff/tif_dirwrite.c b/third_party/libtiff/tif_dirwrite.c index a0fd8dc2f6..d34f6f611d 100644 --- a/third_party/libtiff/tif_dirwrite.c +++ b/third_party/libtiff/tif_dirwrite.c @@ -1,4 +1,4 @@ -/* $Id: tif_dirwrite.c,v 1.78 2015-05-31 00:38:46 bfriesen Exp $ */ +/* $Id: tif_dirwrite.c,v 1.83 2016-10-25 21:35:15 erouault Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -542,8 +542,20 @@ TIFFWriteDirectorySec(TIFF* tif, int isimage, int imagedone, uint64* pdiroff) { if (!isTiled(tif)) { - if (!TIFFWriteDirectoryTagLongLong8Array(tif,&ndir,dir,TIFFTAG_STRIPOFFSETS,tif->tif_dir.td_nstrips,tif->tif_dir.td_stripoffset)) - goto bad; + /* td_stripoffset might be NULL in an odd OJPEG case. See + * tif_dirread.c around line 3634. + * XXX: OJPEG hack. + * If a) compression is OJPEG, b) it's not a tiled TIFF, + * and c) the number of strips is 1, + * then we tolerate the absence of stripoffsets tag, + * because, presumably, all required data is in the + * JpegInterchangeFormat stream. + * We can get here when using tiffset on such a file. + * See http://bugzilla.maptools.org/show_bug.cgi?id=2500 + */ + if (tif->tif_dir.td_stripoffset != NULL && + !TIFFWriteDirectoryTagLongLong8Array(tif,&ndir,dir,TIFFTAG_STRIPOFFSETS,tif->tif_dir.td_nstrips,tif->tif_dir.td_stripoffset)) + goto bad; } else { @@ -645,7 +657,7 @@ TIFFWriteDirectorySec(TIFF* tif, int isimage, int imagedone, uint64* pdiroff) assert(o->field_passcount==0); TIFFGetField(tif,o->field_tag,&pb); pa=(uint32)(strlen(pb)); - if (!TIFFWriteDirectoryTagAscii(tif,&ndir,dir,o->field_tag,pa,pb)) + if (!TIFFWriteDirectoryTagAscii(tif,&ndir,dir,(uint16)o->field_tag,pa,pb)) goto bad; } break; @@ -656,7 +668,7 @@ TIFFWriteDirectorySec(TIFF* tif, int isimage, int imagedone, uint64* pdiroff) assert(o->field_readcount==1); assert(o->field_passcount==0); TIFFGetField(tif,o->field_tag,&p); - if (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,o->field_tag,p)) + if (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,(uint16)o->field_tag,p)) goto bad; } break; @@ -667,7 +679,7 @@ TIFFWriteDirectorySec(TIFF* tif, int isimage, int imagedone, uint64* pdiroff) assert(o->field_readcount==1); assert(o->field_passcount==0); TIFFGetField(tif,o->field_tag,&p); - if (!TIFFWriteDirectoryTagLong(tif,&ndir,dir,o->field_tag,p)) + if (!TIFFWriteDirectoryTagLong(tif,&ndir,dir,(uint16)o->field_tag,p)) goto bad; } break; @@ -679,7 +691,7 @@ TIFFWriteDirectorySec(TIFF* tif, int isimage, int imagedone, uint64* pdiroff) assert(o->field_readcount==TIFF_VARIABLE2); assert(o->field_passcount==1); TIFFGetField(tif,o->field_tag,&pa,&pb); - if (!TIFFWriteDirectoryTagUndefinedArray(tif,&ndir,dir,o->field_tag,pa,pb)) + if (!TIFFWriteDirectoryTagUndefinedArray(tif,&ndir,dir,(uint16)o->field_tag,pa,pb)) goto bad; } break; @@ -693,70 +705,72 @@ TIFFWriteDirectorySec(TIFF* tif, int isimage, int imagedone, uint64* pdiroff) } for (m=0; m<(uint32)(tif->tif_dir.td_customValueCount); m++) { + uint16 tag = (uint16)tif->tif_dir.td_customValues[m].info->field_tag; + uint32 count = tif->tif_dir.td_customValues[m].count; switch (tif->tif_dir.td_customValues[m].info->field_type) { case TIFF_ASCII: - if (!TIFFWriteDirectoryTagAscii(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value)) + if (!TIFFWriteDirectoryTagAscii(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value)) goto bad; break; case TIFF_UNDEFINED: - if (!TIFFWriteDirectoryTagUndefinedArray(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value)) + if (!TIFFWriteDirectoryTagUndefinedArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value)) goto bad; break; case TIFF_BYTE: - if (!TIFFWriteDirectoryTagByteArray(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value)) + if (!TIFFWriteDirectoryTagByteArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value)) goto bad; break; case TIFF_SBYTE: - if (!TIFFWriteDirectoryTagSbyteArray(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value)) + if (!TIFFWriteDirectoryTagSbyteArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value)) goto bad; break; case TIFF_SHORT: - if (!TIFFWriteDirectoryTagShortArray(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value)) + if (!TIFFWriteDirectoryTagShortArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value)) goto bad; break; case TIFF_SSHORT: - if (!TIFFWriteDirectoryTagSshortArray(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value)) + if (!TIFFWriteDirectoryTagSshortArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value)) goto bad; break; case TIFF_LONG: - if (!TIFFWriteDirectoryTagLongArray(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value)) + if (!TIFFWriteDirectoryTagLongArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value)) goto bad; break; case TIFF_SLONG: - if (!TIFFWriteDirectoryTagSlongArray(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value)) + if (!TIFFWriteDirectoryTagSlongArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value)) goto bad; break; case TIFF_LONG8: - if (!TIFFWriteDirectoryTagLong8Array(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value)) + if (!TIFFWriteDirectoryTagLong8Array(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value)) goto bad; break; case TIFF_SLONG8: - if (!TIFFWriteDirectoryTagSlong8Array(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value)) + if (!TIFFWriteDirectoryTagSlong8Array(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value)) goto bad; break; case TIFF_RATIONAL: - if (!TIFFWriteDirectoryTagRationalArray(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value)) + if (!TIFFWriteDirectoryTagRationalArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value)) goto bad; break; case TIFF_SRATIONAL: - if (!TIFFWriteDirectoryTagSrationalArray(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value)) + if (!TIFFWriteDirectoryTagSrationalArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value)) goto bad; break; case TIFF_FLOAT: - if (!TIFFWriteDirectoryTagFloatArray(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value)) + if (!TIFFWriteDirectoryTagFloatArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value)) goto bad; break; case TIFF_DOUBLE: - if (!TIFFWriteDirectoryTagDoubleArray(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value)) + if (!TIFFWriteDirectoryTagDoubleArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value)) goto bad; break; case TIFF_IFD: - if (!TIFFWriteDirectoryTagIfdArray(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value)) + if (!TIFFWriteDirectoryTagIfdArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value)) goto bad; break; case TIFF_IFD8: - if (!TIFFWriteDirectoryTagIfdIfd8Array(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value)) + if (!TIFFWriteDirectoryTagIfdIfd8Array(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value)) goto bad; break; default: @@ -778,7 +792,7 @@ TIFFWriteDirectorySec(TIFF* tif, int isimage, int imagedone, uint64* pdiroff) goto bad; } else - tif->tif_diroff=(TIFFSeekFile(tif,0,SEEK_END)+1)&(~1); + tif->tif_diroff=(TIFFSeekFile(tif,0,SEEK_END)+1)&(~((toff_t)1)); if (pdiroff!=NULL) *pdiroff=tif->tif_diroff; if (!(tif->tif_flags&TIFF_BIGTIFF)) @@ -828,7 +842,7 @@ TIFFWriteDirectorySec(TIFF* tif, int isimage, int imagedone, uint64* pdiroff) uint32 nTmp; TIFFDirEntry* o; n=dirmem; - *(uint16*)n=ndir; + *(uint16*)n=(uint16)ndir; if (tif->tif_flags&TIFF_SWAB) TIFFSwabShort((uint16*)n); n+=2; @@ -2141,13 +2155,13 @@ TIFFWriteDirectoryTagCheckedRationalArray(TIFF* tif, uint32* ndir, TIFFDirEntry* } else if (*na<1.0) { - nb[0]=(uint32)((*na)*0xFFFFFFFF); + nb[0]=(uint32)((double)(*na)*0xFFFFFFFF); nb[1]=0xFFFFFFFF; } else { nb[0]=0xFFFFFFFF; - nb[1]=(uint32)(0xFFFFFFFF/(*na)); + nb[1]=(uint32)((double)0xFFFFFFFF/(*na)); } } if (tif->tif_flags&TIFF_SWAB) @@ -2184,13 +2198,13 @@ TIFFWriteDirectoryTagCheckedSrationalArray(TIFF* tif, uint32* ndir, TIFFDirEntry } else if (*na>-1.0) { - nb[0]=-(int32)((-*na)*0x7FFFFFFF); + nb[0]=-(int32)((double)(-*na)*0x7FFFFFFF); nb[1]=0x7FFFFFFF; } else { nb[0]=-0x7FFFFFFF; - nb[1]=(int32)(0x7FFFFFFF/(-*na)); + nb[1]=(int32)((double)0x7FFFFFFF/(-*na)); } } else @@ -2202,13 +2216,13 @@ TIFFWriteDirectoryTagCheckedSrationalArray(TIFF* tif, uint32* ndir, TIFFDirEntry } else if (*na<1.0) { - nb[0]=(int32)((*na)*0x7FFFFFFF); + nb[0]=(int32)((double)(*na)*0x7FFFFFFF); nb[1]=0x7FFFFFFF; } else { nb[0]=0x7FFFFFFF; - nb[1]=(int32)(0x7FFFFFFF/(*na)); + nb[1]=(int32)((double)0x7FFFFFFF/(*na)); } } } @@ -2368,7 +2382,7 @@ TIFFLinkDirectory(TIFF* tif) { static const char module[] = "TIFFLinkDirectory"; - tif->tif_diroff = (TIFFSeekFile(tif,0,SEEK_END)+1) &~ 1; + tif->tif_diroff = (TIFFSeekFile(tif,0,SEEK_END)+1) & (~((toff_t)1)); /* * Handle SubIFDs diff --git a/third_party/libtiff/tif_dumpmode.c b/third_party/libtiff/tif_dumpmode.c index a94cf0b34a..a6a94c04d5 100644 --- a/third_party/libtiff/tif_dumpmode.c +++ b/third_party/libtiff/tif_dumpmode.c @@ -1,4 +1,4 @@ -/* $Header: /cvs/maptools/cvsroot/libtiff/libtiff/tif_dumpmode.c,v 1.14 2011-04-02 20:54:09 bfriesen Exp $ */ +/* $Header: /cvs/maptools/cvsroot/libtiff/libtiff/tif_dumpmode.c,v 1.15 2015-12-12 18:04:26 erouault Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -66,7 +66,7 @@ DumpModeEncode(TIFF* tif, uint8* pp, tmsize_t cc, uint16 s) cc -= n; if (tif->tif_rawcc >= tif->tif_rawdatasize && !TIFFFlushData1(tif)) - return (-1); + return (0); } return (1); } diff --git a/third_party/libtiff/tif_extension.c b/third_party/libtiff/tif_extension.c index 10afd4162c..39fab4c7ba 100644 --- a/third_party/libtiff/tif_extension.c +++ b/third_party/libtiff/tif_extension.c @@ -1,4 +1,4 @@ -/* $Header: /cvs/maptools/cvsroot/libtiff/libtiff/tif_extension.c,v 1.7 2010-03-10 18:56:48 bfriesen Exp $ */ +/* $Header: /cvs/maptools/cvsroot/libtiff/libtiff/tif_extension.c,v 1.8 2015-12-06 11:13:43 erouault Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -66,13 +66,13 @@ TIFFTagMethods *TIFFAccessTagMethods( TIFF *tif ) void *TIFFGetClientInfo( TIFF *tif, const char *name ) { - TIFFClientInfoLink *link = tif->tif_clientinfo; + TIFFClientInfoLink *psLink = tif->tif_clientinfo; - while( link != NULL && strcmp(link->name,name) != 0 ) - link = link->next; + while( psLink != NULL && strcmp(psLink->name,name) != 0 ) + psLink = psLink->next; - if( link != NULL ) - return link->data; + if( psLink != NULL ) + return psLink->data; else return NULL; } @@ -80,18 +80,18 @@ void *TIFFGetClientInfo( TIFF *tif, const char *name ) void TIFFSetClientInfo( TIFF *tif, void *data, const char *name ) { - TIFFClientInfoLink *link = tif->tif_clientinfo; + TIFFClientInfoLink *psLink = tif->tif_clientinfo; /* ** Do we have an existing link with this name? If so, just ** set it. */ - while( link != NULL && strcmp(link->name,name) != 0 ) - link = link->next; + while( psLink != NULL && strcmp(psLink->name,name) != 0 ) + psLink = psLink->next; - if( link != NULL ) + if( psLink != NULL ) { - link->data = data; + psLink->data = data; return; } @@ -99,15 +99,15 @@ void TIFFSetClientInfo( TIFF *tif, void *data, const char *name ) ** Create a new link. */ - link = (TIFFClientInfoLink *) _TIFFmalloc(sizeof(TIFFClientInfoLink)); - assert (link != NULL); - link->next = tif->tif_clientinfo; - link->name = (char *) _TIFFmalloc((tmsize_t)(strlen(name)+1)); - assert (link->name != NULL); - strcpy(link->name, name); - link->data = data; + psLink = (TIFFClientInfoLink *) _TIFFmalloc(sizeof(TIFFClientInfoLink)); + assert (psLink != NULL); + psLink->next = tif->tif_clientinfo; + psLink->name = (char *) _TIFFmalloc((tmsize_t)(strlen(name)+1)); + assert (psLink->name != NULL); + strcpy(psLink->name, name); + psLink->data = data; - tif->tif_clientinfo = link; + tif->tif_clientinfo = psLink; } /* * Local Variables: diff --git a/third_party/libtiff/tif_fax3.c b/third_party/libtiff/tif_fax3.c index bbe72555be..16bb4d36f0 100644 --- a/third_party/libtiff/tif_fax3.c +++ b/third_party/libtiff/tif_fax3.c @@ -1,4 +1,4 @@ -/* $Id: tif_fax3.c,v 1.75 2015-08-30 20:49:55 erouault Exp $ */ +/* $Id: tif_fax3.c,v 1.78 2016-09-04 21:32:56 erouault Exp $ */ /* * Copyright (c) 1990-1997 Sam Leffler @@ -644,7 +644,8 @@ putspan(TIFF* tif, int32 span, const tableentry* tab) while (span >= 2624) { const tableentry* te = &tab[63 + (2560>>6)]; - code = te->code, length = te->length; + code = te->code; + length = te->length; #ifdef FAX3_DEBUG DEBUG_PRINT("MakeUp", te->runlen); #endif @@ -654,14 +655,16 @@ putspan(TIFF* tif, int32 span, const tableentry* tab) if (span >= 64) { const tableentry* te = &tab[63 + (span>>6)]; assert(te->runlen == 64*(span>>6)); - code = te->code, length = te->length; + code = te->code; + length = te->length; #ifdef FAX3_DEBUG DEBUG_PRINT("MakeUp", te->runlen); #endif _PutBits(tif, code, length); span -= te->runlen; } - code = tab[span].code, length = tab[span].length; + code = tab[span].code; + length = tab[span].length; #ifdef FAX3_DEBUG DEBUG_PRINT(" Term", tab[span].runlen); #endif @@ -697,14 +700,16 @@ Fax3PutEOL(TIFF* tif) align = sp->bit + (8 - align); else align = sp->bit - align; - code = 0; tparm=align; _PutBits(tif, 0, tparm); } } - code = EOL, length = 12; - if (is2DEncoding(sp)) - code = (code<<1) | (sp->tag == G3_1D), length++; + code = EOL; + length = 12; + if (is2DEncoding(sp)) { + code = (code<<1) | (sp->tag == G3_1D); + length++; + } _PutBits(tif, code, length); sp->data = data; @@ -815,7 +820,7 @@ find0span(unsigned char* bp, int32 bs, int32 be) /* * Check partial byte on lhs. */ - if (bits > 0 && (n = (bs & 7))) { + if (bits > 0 && (n = (bs & 7)) != 0) { span = zeroruns[(*bp << n) & 0xff]; if (span > 8-n) /* table value too generous */ span = 8-n; @@ -835,12 +840,14 @@ find0span(unsigned char* bp, int32 bs, int32 be) while (!isAligned(bp, long)) { if (*bp != 0x00) return (span + zeroruns[*bp]); - span += 8, bits -= 8; + span += 8; + bits -= 8; bp++; } lp = (long*) bp; while ((bits >= (int32)(8 * sizeof(long))) && (0 == *lp)) { - span += 8*sizeof (long), bits -= 8*sizeof (long); + span += 8*sizeof (long); + bits -= 8*sizeof (long); lp++; } bp = (unsigned char*) lp; @@ -851,7 +858,8 @@ find0span(unsigned char* bp, int32 bs, int32 be) while (bits >= 8) { if (*bp != 0x00) /* end of run */ return (span + zeroruns[*bp]); - span += 8, bits -= 8; + span += 8; + bits -= 8; bp++; } /* @@ -874,7 +882,7 @@ find1span(unsigned char* bp, int32 bs, int32 be) /* * Check partial byte on lhs. */ - if (bits > 0 && (n = (bs & 7))) { + if (bits > 0 && (n = (bs & 7)) != 0) { span = oneruns[(*bp << n) & 0xff]; if (span > 8-n) /* table value too generous */ span = 8-n; @@ -894,12 +902,14 @@ find1span(unsigned char* bp, int32 bs, int32 be) while (!isAligned(bp, long)) { if (*bp != 0xff) return (span + oneruns[*bp]); - span += 8, bits -= 8; + span += 8; + bits -= 8; bp++; } lp = (long*) bp; while ((bits >= (int32)(8 * sizeof(long))) && (~0 == *lp)) { - span += 8*sizeof (long), bits -= 8*sizeof (long); + span += 8*sizeof (long); + bits -= 8*sizeof (long); lp++; } bp = (unsigned char*) lp; @@ -910,7 +920,8 @@ find1span(unsigned char* bp, int32 bs, int32 be) while (bits >= 8) { if (*bp != 0xff) /* end of run */ return (span + oneruns[*bp]); - span += 8, bits -= 8; + span += 8; + bits -= 8; bp++; } /* @@ -1094,8 +1105,10 @@ Fax3Close(TIFF* tif) unsigned int length = 12; int i; - if (is2DEncoding(sp)) - code = (code<<1) | (sp->tag == G3_1D), length++; + if (is2DEncoding(sp)) { + code = (code<<1) | (sp->tag == G3_1D); + length++; + } for (i = 0; i < 6; i++) Fax3PutBits(tif, code, length); Fax3FlushBits(tif, sp); @@ -1182,7 +1195,7 @@ Fax3VSetField(TIFF* tif, uint32 tag, va_list ap) return (*sp->vsetparent)(tif, tag, ap); } - if ((fip = TIFFFieldWithTag(tif, tag))) + if ((fip = TIFFFieldWithTag(tif, tag)) != NULL) TIFFSetFieldBit(tif, fip->field_bit); else return 0; @@ -1241,10 +1254,14 @@ Fax3PrintDir(TIFF* tif, FILE* fd, long flags) } else { fprintf(fd, " Group 3 Options:"); - if (sp->groupoptions & GROUP3OPT_2DENCODING) - fprintf(fd, "%s2-d encoding", sep), sep = "+"; - if (sp->groupoptions & GROUP3OPT_FILLBITS) - fprintf(fd, "%sEOL padding", sep), sep = "+"; + if (sp->groupoptions & GROUP3OPT_2DENCODING) { + fprintf(fd, "%s2-d encoding", sep); + sep = "+"; + } + if (sp->groupoptions & GROUP3OPT_FILLBITS) { + fprintf(fd, "%sEOL padding", sep); + sep = "+"; + } if (sp->groupoptions & GROUP3OPT_UNCOMPRESSED) fprintf(fd, "%suncompressed data", sep); } diff --git a/third_party/libtiff/tif_fax3.h b/third_party/libtiff/tif_fax3.h index b0f46c9a43..e0b2ca6bfc 100644 --- a/third_party/libtiff/tif_fax3.h +++ b/third_party/libtiff/tif_fax3.h @@ -1,4 +1,4 @@ -/* $Id: tif_fax3.h,v 1.9 2011-03-10 20:23:07 fwarmerdam Exp $ */ +/* $Id: tif_fax3.h,v 1.11 2016-01-23 21:20:34 erouault Exp $ */ /* * Copyright (c) 1990-1997 Sam Leffler @@ -39,7 +39,7 @@ /* * To override the default routine used to image decoded - * spans one can use the pseduo tag TIFFTAG_FAXFILLFUNC. + * spans one can use the pseudo tag TIFFTAG_FAXFILLFUNC. * The routine must have the type signature given below; * for example: * @@ -84,7 +84,7 @@ extern void _TIFFFax3fillruns(unsigned char*, uint32*, uint32*, uint32); typedef struct { /* state table entry */ unsigned char State; /* see above */ unsigned char Width; /* width of code in bits */ - uint32 Param; /* unsigned 32-bit run length in bits */ + uint16 Param; /* unsigned 16-bit run length in bits */ } TIFFFaxTabEnt; extern const TIFFFaxTabEnt TIFFFaxMainTable[]; 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); } diff --git a/third_party/libtiff/tif_jpeg.c b/third_party/libtiff/tif_jpeg.c index 6659909299..abd0b0aa2f 100644 --- a/third_party/libtiff/tif_jpeg.c +++ b/third_party/libtiff/tif_jpeg.c @@ -1,4 +1,4 @@ -/* $Id: tif_jpeg.c,v 1.119 2015-08-15 20:13:07 bfriesen Exp $ */ +/* $Id: tif_jpeg.c,v 1.123 2016-01-23 21:20:34 erouault Exp $ */ /* * Copyright (c) 1994-1997 Sam Leffler @@ -58,7 +58,7 @@ int TIFFReInitJPEG_12( TIFF *tif, int scheme, int is_encode ); Libjpeg's jmorecfg.h defines INT16 and INT32, but only if XMD_H is not defined. Unfortunately, the MinGW and Borland compilers include a typedef for INT32, which causes a conflict. MSVC does not include - a conficting typedef given the headers which are included. + a conflicting typedef given the headers which are included. */ #if defined(__BORLANDC__) || defined(__MINGW32__) # define XMD_H 1 @@ -945,7 +945,7 @@ JPEGFixupTagsSubsamplingSkip(struct JPEGFixupTagsSubsamplingData* data, uint16 s else { uint16 m; - m=skiplength-data->bufferbytesleft; + m=(uint16)(skiplength-data->bufferbytesleft); if (m<=data->filebytesleft) { data->bufferbytesleft=0; @@ -1291,7 +1291,7 @@ JPEGDecode(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s) if( line_work_buf != NULL ) { /* - * In the MK1 case, we aways read into a 16bit + * In the MK1 case, we always read into a 16bit * buffer, and then pack down to 12bit or 8bit. * In 6B case we only read into 16 bit buffer * for 12bit data, which we need to repack. @@ -1311,10 +1311,10 @@ JPEGDecode(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s) ((unsigned char *) buf) + iPair * 3; JSAMPLE *in_ptr = line_work_buf + iPair * 2; - out_ptr[0] = (in_ptr[0] & 0xff0) >> 4; - out_ptr[1] = ((in_ptr[0] & 0xf) << 4) - | ((in_ptr[1] & 0xf00) >> 8); - out_ptr[2] = ((in_ptr[1] & 0xff) >> 0); + out_ptr[0] = (unsigned char)((in_ptr[0] & 0xff0) >> 4); + out_ptr[1] = (unsigned char)(((in_ptr[0] & 0xf) << 4) + | ((in_ptr[1] & 0xf00) >> 8)); + out_ptr[2] = (unsigned char)(((in_ptr[1] & 0xff) >> 0)); } } else if( sp->cinfo.d.data_precision == 8 ) @@ -1375,7 +1375,7 @@ JPEGDecodeRaw(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s) (void) s; /* data is expected to be read in multiples of a scanline */ - if ( (nrows = sp->cinfo.d.image_height) ) { + if ( (nrows = sp->cinfo.d.image_height) != 0 ) { /* Cb,Cr both have sampling factors 1, so this is correct */ JDIMENSION clumps_per_line = sp->cinfo.d.comp_info[1].downsampled_width; @@ -1475,10 +1475,10 @@ JPEGDecodeRaw(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s) { unsigned char *out_ptr = ((unsigned char *) buf) + iPair * 3; JSAMPLE *in_ptr = (JSAMPLE *) (tmpbuf + iPair * 2); - out_ptr[0] = (in_ptr[0] & 0xff0) >> 4; - out_ptr[1] = ((in_ptr[0] & 0xf) << 4) - | ((in_ptr[1] & 0xf00) >> 8); - out_ptr[2] = ((in_ptr[1] & 0xff) >> 0); + out_ptr[0] = (unsigned char)((in_ptr[0] & 0xff0) >> 4); + out_ptr[1] = (unsigned char)(((in_ptr[0] & 0xf) << 4) + | ((in_ptr[1] & 0xf00) >> 8)); + out_ptr[2] = (unsigned char)(((in_ptr[1] & 0xff) >> 0)); } } } @@ -1901,7 +1901,7 @@ JPEGEncode(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s) if( sp->cinfo.c.data_precision == 12 ) { - line16_count = (sp->bytesperline * 2) / 3; + line16_count = (int)((sp->bytesperline * 2) / 3); line16 = (short *) _TIFFmalloc(sizeof(short) * line16_count); if (!line16) { @@ -2146,8 +2146,7 @@ JPEGVSetField(TIFF* tif, uint32 tag, va_list ap) /* XXX */ return (0); } - _TIFFsetByteArray(&sp->jpegtables, va_arg(ap, void*), - (long) v32); + _TIFFsetByteArray(&sp->jpegtables, va_arg(ap, void*), v32); sp->jpegtables_length = v32; TIFFSetFieldBit(tif, FIELD_JPEGTABLES); break; @@ -2176,7 +2175,7 @@ JPEGVSetField(TIFF* tif, uint32 tag, va_list ap) return (*sp->vsetparent)(tif, tag, ap); } - if ((fip = TIFFFieldWithTag(tif, tag))) { + if ((fip = TIFFFieldWithTag(tif, tag)) != NULL) { TIFFSetFieldBit(tif, fip->field_bit); } else { return (0); diff --git a/third_party/libtiff/tif_luv.c b/third_party/libtiff/tif_luv.c index 01f39c0d63..ca08f30a76 100644 --- a/third_party/libtiff/tif_luv.c +++ b/third_party/libtiff/tif_luv.c @@ -1,4 +1,4 @@ -/* $Id: tif_luv.c,v 1.40 2015-06-21 01:09:09 bfriesen Exp $ */ +/* $Id: tif_luv.c,v 1.43 2016-09-04 21:32:56 erouault Exp $ */ /* * Copyright (c) 1997 Greg Ward Larson @@ -401,8 +401,10 @@ LogLuvDecodeStrip(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) return 0; assert(cc%rowlen == 0); - while (cc && (*tif->tif_decoderow)(tif, bp, rowlen, s)) - bp += rowlen, cc -= rowlen; + while (cc && (*tif->tif_decoderow)(tif, bp, rowlen, s)) { + bp += rowlen; + cc -= rowlen; + } return (cc == 0); } @@ -420,8 +422,10 @@ LogLuvDecodeTile(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) return 0; assert(cc%rowlen == 0); - while (cc && (*tif->tif_decoderow)(tif, bp, rowlen, s)) - bp += rowlen, cc -= rowlen; + while (cc && (*tif->tif_decoderow)(tif, bp, rowlen, s)) { + bp += rowlen; + cc -= rowlen; + } return (cc == 0); } @@ -687,8 +691,10 @@ LogLuvEncodeStrip(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) return 0; assert(cc%rowlen == 0); - while (cc && (*tif->tif_encoderow)(tif, bp, rowlen, s) == 1) - bp += rowlen, cc -= rowlen; + while (cc && (*tif->tif_encoderow)(tif, bp, rowlen, s) == 1) { + bp += rowlen; + cc -= rowlen; + } return (cc == 0); } @@ -705,8 +711,10 @@ LogLuvEncodeTile(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) return 0; assert(cc%rowlen == 0); - while (cc && (*tif->tif_encoderow)(tif, bp, rowlen, s) == 1) - bp += rowlen, cc -= rowlen; + while (cc && (*tif->tif_encoderow)(tif, bp, rowlen, s) == 1) { + bp += rowlen; + cc -= rowlen; + } return (cc == 0); } @@ -1276,6 +1284,14 @@ LogL16InitState(TIFF* tif) assert(sp != NULL); assert(td->td_photometric == PHOTOMETRIC_LOGL); + if( td->td_samplesperpixel != 1 ) + { + TIFFErrorExt(tif->tif_clientdata, module, + "Sorry, can not handle LogL image with %s=%d", + "Samples/pixel", td->td_samplesperpixel); + return 0; + } + /* for some reason, we can't do this in TIFFInitLogL16 */ if (sp->user_datafmt == SGILOGDATAFMT_UNKNOWN) sp->user_datafmt = LogL16GuessDataFmt(td); @@ -1598,17 +1614,21 @@ LogLuvVSetField(TIFF* tif, uint32 tag, va_list ap) */ switch (sp->user_datafmt) { case SGILOGDATAFMT_FLOAT: - bps = 32, fmt = SAMPLEFORMAT_IEEEFP; + bps = 32; + fmt = SAMPLEFORMAT_IEEEFP; break; case SGILOGDATAFMT_16BIT: - bps = 16, fmt = SAMPLEFORMAT_INT; + bps = 16; + fmt = SAMPLEFORMAT_INT; break; case SGILOGDATAFMT_RAW: - bps = 32, fmt = SAMPLEFORMAT_UINT; + bps = 32; + fmt = SAMPLEFORMAT_UINT; TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 1); break; case SGILOGDATAFMT_8BIT: - bps = 8, fmt = SAMPLEFORMAT_UINT; + bps = 8; + fmt = SAMPLEFORMAT_UINT; break; default: TIFFErrorExt(tif->tif_clientdata, tif->tif_name, diff --git a/third_party/libtiff/tif_lzw.c b/third_party/libtiff/tif_lzw.c index 9b76dd03b3..240e19c2e0 100644 --- a/third_party/libtiff/tif_lzw.c +++ b/third_party/libtiff/tif_lzw.c @@ -1,4 +1,4 @@ -/* $Id: tif_lzw.c,v 1.49 2015-08-30 21:07:44 erouault Exp $ */ +/* $Id: tif_lzw.c,v 1.52 2016-09-04 21:32:56 erouault Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -240,8 +240,8 @@ LZWSetupDecode(TIFF* tif) */ code = 255; do { - sp->dec_codetab[code].value = code; - sp->dec_codetab[code].firstchar = code; + sp->dec_codetab[code].value = (unsigned char)code; + sp->dec_codetab[code].firstchar = (unsigned char)code; sp->dec_codetab[code].length = 1; sp->dec_codetab[code].next = NULL; } while (code--); @@ -411,14 +411,15 @@ LZWDecode(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s) /* * Residue satisfies only part of the decode request. */ - op += residue, occ -= residue; + op += residue; + occ -= residue; tp = op; do { int t; --tp; t = codep->value; codep = codep->next; - *tp = t; + *tp = (char)t; } while (--residue && codep); sp->dec_restart = 0; } @@ -454,7 +455,8 @@ LZWDecode(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s) tif->tif_row); return (0); } - *op++ = (char)code, occ--; + *op++ = (char)code; + occ--; oldcodep = sp->dec_codetab + code; continue; } @@ -532,16 +534,19 @@ LZWDecode(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s) --tp; t = codep->value; codep = codep->next; - *tp = t; + *tp = (char)t; } while (codep && tp > op); if (codep) { codeLoop(tif, module); break; } assert(occ >= len); - op += len, occ -= len; - } else - *op++ = (char)code, occ--; + op += len; + occ -= len; + } else { + *op++ = (char)code; + occ--; + } } tif->tif_rawcp = (uint8*) bp; @@ -635,7 +640,8 @@ LZWDecodeCompat(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s) /* * Residue satisfies only part of the decode request. */ - op += residue, occ -= residue; + op += residue; + occ -= residue; tp = op; do { *--tp = codep->value; @@ -675,7 +681,8 @@ LZWDecodeCompat(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s) tif->tif_row); return (0); } - *op++ = code, occ--; + *op++ = (char)code; + occ--; oldcodep = sp->dec_codetab + code; continue; } @@ -741,17 +748,20 @@ LZWDecodeCompat(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s) break; } assert(occ >= codep->length); - op += codep->length, occ -= codep->length; + op += codep->length; + occ -= codep->length; tp = op; do { *--tp = codep->value; } while( (codep = codep->next) != NULL ); - } else - *op++ = code, occ--; + } else { + *op++ = (char)code; + occ--; + } } tif->tif_rawcp = (uint8*) bp; - sp->lzw_nbits = nbits; + sp->lzw_nbits = (unsigned short)nbits; sp->lzw_nextdata = nextdata; sp->lzw_nextbits = nextbits; sp->dec_nbitsmask = nbitsmask; @@ -900,7 +910,7 @@ LZWEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) nbits = sp->lzw_nbits; op = tif->tif_rawcp; limit = sp->enc_rawlimit; - ent = sp->enc_oldcode; + ent = (hcode_t)sp->enc_oldcode; if (ent == (hcode_t) -1 && cc > 0) { /* @@ -936,7 +946,7 @@ LZWEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) disp = 1; do { /* - * Avoid pointer arithmetic 'cuz of + * Avoid pointer arithmetic because of * wraparound problems with segments. */ if ((h -= disp) < 0) @@ -963,8 +973,8 @@ LZWEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) op = tif->tif_rawdata; } PutNextCode(op, ent); - ent = c; - hp->code = free_ent++; + ent = (hcode_t)c; + hp->code = (hcode_t)(free_ent++); hp->hash = fcode; if (free_ent == CODE_MAX-1) { /* table is full, emit clear code and reset */ @@ -1021,9 +1031,9 @@ LZWEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) sp->enc_oldcode = ent; sp->lzw_nextdata = nextdata; sp->lzw_nextbits = nextbits; - sp->lzw_free_ent = free_ent; - sp->lzw_maxcode = maxcode; - sp->lzw_nbits = nbits; + sp->lzw_free_ent = (unsigned short)free_ent; + sp->lzw_maxcode = (unsigned short)maxcode; + sp->lzw_nbits = (unsigned short)nbits; tif->tif_rawcp = op; return (1); } diff --git a/third_party/libtiff/tif_next.c b/third_party/libtiff/tif_next.c index b2076a0b01..08211788ac 100644 --- a/third_party/libtiff/tif_next.c +++ b/third_party/libtiff/tif_next.c @@ -1,4 +1,4 @@ -/* $Id: tif_next.c,v 1.16 2014-12-29 12:09:11 erouault Exp $ */ +/* $Id: tif_next.c,v 1.19 2016-09-04 21:32:56 erouault Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -72,7 +72,8 @@ NeXTDecode(TIFF* tif, uint8* buf, tmsize_t occ, uint16 s) return (0); } for (row = buf; cc > 0 && occ > 0; occ -= scanline, row += scanline) { - n = *bp++, cc--; + n = *bp++; + cc--; switch (n) { case LITERALROW: /* @@ -103,10 +104,10 @@ NeXTDecode(TIFF* tif, uint8* buf, tmsize_t occ, uint16 s) } default: { uint32 npixels = 0, grey; + tmsize_t op_offset = 0; uint32 imagewidth = tif->tif_dir.td_imagewidth; if( isTiled(tif) ) imagewidth = tif->tif_dir.td_tilewidth; - tmsize_t op_offset = 0; /* * The scanline is composed of a sequence of constant @@ -134,7 +135,8 @@ NeXTDecode(TIFF* tif, uint8* buf, tmsize_t occ, uint16 s) } if (cc == 0) goto bad; - n = *bp++, cc--; + n = *bp++; + cc--; } break; } diff --git a/third_party/libtiff/tif_ojpeg.c b/third_party/libtiff/tif_ojpeg.c index 276d562dfb..e128887bf6 100644 --- a/third_party/libtiff/tif_ojpeg.c +++ b/third_party/libtiff/tif_ojpeg.c @@ -1,4 +1,4 @@ -/* $Id: tif_ojpeg.c,v 1.60 2015-05-31 00:38:46 bfriesen Exp $ */ +/* $Id: tif_ojpeg.c,v 1.65 2016-09-04 21:32:56 erouault Exp $ */ /* WARNING: The type of JPEG encapsulation defined by the TIFF Version 6.0 specification is now totally obsolete and deprecated for new applications and @@ -75,7 +75,7 @@ OJPEGSubsamplingCorrect, making no note of any other data, reporting no warnings or errors, up to the point where either these values are read, or it's clear they aren't there. This means that some of the data is read twice, but we feel speed - in correcting these values is important enough to warrant this sacrifice. Allthough + in correcting these values is important enough to warrant this sacrifice. Although there is currently no define or other configuration mechanism to disable this behaviour, the actual header scanning is build to robustly respond with error report if it should encounter an uncorrected mismatch of subsampling values. See @@ -84,7 +84,7 @@ The restart interval and restart markers are the most tricky part... The restart interval can be specified in a tag. It can also be set inside the input JPEG stream. It can be used inside the input JPEG stream. If reading from strile data, we've - consistenly discovered the need to insert restart markers in between the different + consistently discovered the need to insert restart markers in between the different striles, as is also probably the most likely interpretation of the original TIFF 6.0 specification. With all this setting of interval, and actual use of markers that is not predictable at the time of valid JPEG header assembly, the restart thing may turn @@ -113,7 +113,7 @@ planarconfig is not separate (vast majority). We may one day use that to build converters to JPEG, and/or to new-style JPEG compression inside TIFF. - A dissadvantage is the lack of random access to the individual striles. This is the + A disadvantage is the lack of random access to the individual striles. This is the reason for much of the complicated restart-and-position stuff inside OJPEGPreDecode. Applications would do well accessing all striles in order, as this will result in a single sequential scan of the input stream, and no restarting of LibJpeg decoding @@ -135,7 +135,7 @@ * The default mode, without JPEG_ENCAP_EXTERNAL, implements the call encapsulators * here, internally, with normal longjump. * SETJMP, LONGJMP, JMP_BUF: On some machines/environments a longjump equivalent is - * conviniently available, but still it may be worthwhile to use _setjmp or sigsetjmp + * conveniently available, but still it may be worthwhile to use _setjmp or sigsetjmp * in place of plain setjmp. These macros will make it easier. It is useless * to fiddle with these if you define JPEG_ENCAP_EXTERNAL. * OJPEG_BUFFER: Define the size of the desired buffer here. Should be small enough so as to guarantee @@ -200,7 +200,7 @@ static const TIFFField ojpegFields[] = { Libjpeg's jmorecfg.h defines INT16 and INT32, but only if XMD_H is not defined. Unfortunately, the MinGW and Borland compilers include a typedef for INT32, which causes a conflict. MSVC does not include - a conficting typedef given the headers which are included. + a conflicting typedef given the headers which are included. */ #if defined(__BORLANDC__) || defined(__MINGW32__) # define XMD_H 1 @@ -1090,7 +1090,7 @@ OJPEGReadHeaderInfo(TIFF* tif) TIFFErrorExt(tif->tif_clientdata,module,"Incompatible vertical subsampling and image strip/tile length"); return(0); } - sp->restart_interval=((sp->strile_width+sp->subsampling_hor*8-1)/(sp->subsampling_hor*8))*(sp->strile_length/(sp->subsampling_ver*8)); + sp->restart_interval=(uint16)(((sp->strile_width+sp->subsampling_hor*8-1)/(sp->subsampling_hor*8))*(sp->strile_length/(sp->subsampling_ver*8))); } if (OJPEGReadHeaderInfoSec(tif)==0) return(0); @@ -1112,7 +1112,7 @@ OJPEGReadSecondarySos(TIFF* tif, uint16 s) assert(s<3); assert(sp->sos_end[0].log!=0); assert(sp->sos_end[s].log==0); - sp->plane_sample_offset=s-1; + sp->plane_sample_offset=(uint8)(s-1); while(sp->sos_end[sp->plane_sample_offset].log==0) sp->plane_sample_offset--; sp->in_buffer_source=sp->sos_end[sp->plane_sample_offset].in_buffer_source; @@ -1390,7 +1390,8 @@ OJPEGReadHeaderInfoSec(TIFF* tif) static int OJPEGReadHeaderInfoSecStreamDri(TIFF* tif) { - /* this could easilly cause trouble in some cases... but no such cases have occured sofar */ + /* This could easily cause trouble in some cases... but no such cases have + occurred so far */ static const char module[]="OJPEGReadHeaderInfoSecStreamDri"; OJPEGState* sp=(OJPEGState*)tif->tif_data; uint16 m; @@ -1788,7 +1789,7 @@ OJPEGReadHeaderInfoSecTablesQTable(TIFF* tif) ob[sizeof(uint32)+3]=67; ob[sizeof(uint32)+4]=m; TIFFSeekFile(tif,sp->qtable_offset[m],SEEK_SET); - p=TIFFReadFile(tif,&ob[sizeof(uint32)+5],64); + p=(uint32)TIFFReadFile(tif,&ob[sizeof(uint32)+5],64); if (p!=64) { _TIFFfree(ob); @@ -1836,7 +1837,7 @@ OJPEGReadHeaderInfoSecTablesDcTable(TIFF* tif) } } TIFFSeekFile(tif,sp->dctable_offset[m],SEEK_SET); - p=TIFFReadFile(tif,o,16); + p=(uint32)TIFFReadFile(tif,o,16); if (p!=16) return(0); q=0; @@ -1852,12 +1853,12 @@ OJPEGReadHeaderInfoSecTablesDcTable(TIFF* tif) *(uint32*)rb=ra; rb[sizeof(uint32)]=255; rb[sizeof(uint32)+1]=JPEG_MARKER_DHT; - rb[sizeof(uint32)+2]=((19+q)>>8); + rb[sizeof(uint32)+2]=(uint8)((19+q)>>8); rb[sizeof(uint32)+3]=((19+q)&255); rb[sizeof(uint32)+4]=m; for (n=0; n<16; n++) rb[sizeof(uint32)+5+n]=o[n]; - p=TIFFReadFile(tif,&(rb[sizeof(uint32)+21]),q); + p=(uint32)TIFFReadFile(tif,&(rb[sizeof(uint32)+21]),q); if (p!=q) { _TIFFfree(rb); @@ -1905,7 +1906,7 @@ OJPEGReadHeaderInfoSecTablesAcTable(TIFF* tif) } } TIFFSeekFile(tif,sp->actable_offset[m],SEEK_SET); - p=TIFFReadFile(tif,o,16); + p=(uint32)TIFFReadFile(tif,o,16); if (p!=16) return(0); q=0; @@ -1921,12 +1922,12 @@ OJPEGReadHeaderInfoSecTablesAcTable(TIFF* tif) *(uint32*)rb=ra; rb[sizeof(uint32)]=255; rb[sizeof(uint32)+1]=JPEG_MARKER_DHT; - rb[sizeof(uint32)+2]=((19+q)>>8); + rb[sizeof(uint32)+2]=(uint8)((19+q)>>8); rb[sizeof(uint32)+3]=((19+q)&255); rb[sizeof(uint32)+4]=(16|m); for (n=0; n<16; n++) rb[sizeof(uint32)+5+n]=o[n]; - p=TIFFReadFile(tif,&(rb[sizeof(uint32)+21]),q); + p=(uint32)TIFFReadFile(tif,&(rb[sizeof(uint32)+21]),q); if (p!=q) { _TIFFfree(rb); @@ -2293,10 +2294,10 @@ OJPEGWriteStreamSof(TIFF* tif, void** mem, uint32* len) /* P */ sp->out_buffer[4]=8; /* Y */ - sp->out_buffer[5]=(sp->sof_y>>8); + sp->out_buffer[5]=(uint8)(sp->sof_y>>8); sp->out_buffer[6]=(sp->sof_y&255); /* X */ - sp->out_buffer[7]=(sp->sof_x>>8); + sp->out_buffer[7]=(uint8)(sp->sof_x>>8); sp->out_buffer[8]=(sp->sof_x&255); /* Nf */ sp->out_buffer[9]=sp->samples_per_pixel_per_plane; @@ -2409,7 +2410,12 @@ OJPEGWriteStreamEoi(TIFF* tif, void** mem, uint32* len) static int jpeg_create_decompress_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo) { - return(SETJMP(sp->exit_jmpbuf)?0:(jpeg_create_decompress(cinfo),1)); + if( SETJMP(sp->exit_jmpbuf) ) + return 0; + else { + jpeg_create_decompress(cinfo); + return 1; + } } #endif @@ -2417,7 +2423,12 @@ jpeg_create_decompress_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo) static int jpeg_read_header_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo, uint8 require_image) { - return(SETJMP(sp->exit_jmpbuf)?0:(jpeg_read_header(cinfo,require_image),1)); + if( SETJMP(sp->exit_jmpbuf) ) + return 0; + else { + jpeg_read_header(cinfo,require_image); + return 1; + } } #endif @@ -2425,7 +2436,12 @@ jpeg_read_header_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo, uint8 requ static int jpeg_start_decompress_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo) { - return(SETJMP(sp->exit_jmpbuf)?0:(jpeg_start_decompress(cinfo),1)); + if( SETJMP(sp->exit_jmpbuf) ) + return 0; + else { + jpeg_start_decompress(cinfo); + return 1; + } } #endif @@ -2433,7 +2449,12 @@ jpeg_start_decompress_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo) static int jpeg_read_scanlines_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo, void* scanlines, uint32 max_lines) { - return(SETJMP(sp->exit_jmpbuf)?0:(jpeg_read_scanlines(cinfo,scanlines,max_lines),1)); + if( SETJMP(sp->exit_jmpbuf) ) + return 0; + else { + jpeg_read_scanlines(cinfo,scanlines,max_lines); + return 1; + } } #endif @@ -2441,7 +2462,12 @@ jpeg_read_scanlines_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo, void* s static int jpeg_read_raw_data_encap(OJPEGState* sp, jpeg_decompress_struct* cinfo, void* data, uint32 max_lines) { - return(SETJMP(sp->exit_jmpbuf)?0:(jpeg_read_raw_data(cinfo,data,max_lines),1)); + if( SETJMP(sp->exit_jmpbuf) ) + return 0; + else { + jpeg_read_raw_data(cinfo,data,max_lines); + return 1; + } } #endif @@ -2503,6 +2529,10 @@ OJPEGLibjpegJpegSourceMgrSkipInputData(jpeg_decompress_struct* cinfo, long num_b jpeg_encap_unwind(tif); } +#ifdef _MSC_VER +#pragma warning( push ) +#pragma warning( disable : 4702 ) /* unreachable code */ +#endif static boolean OJPEGLibjpegJpegSourceMgrResyncToRestart(jpeg_decompress_struct* cinfo, int desired) { @@ -2512,6 +2542,9 @@ OJPEGLibjpegJpegSourceMgrResyncToRestart(jpeg_decompress_struct* cinfo, int desi jpeg_encap_unwind(tif); return(0); } +#ifdef _MSC_VER +#pragma warning( pop ) +#endif static void OJPEGLibjpegJpegSourceMgrTermSource(jpeg_decompress_struct* cinfo) diff --git a/third_party/libtiff/tif_open.c b/third_party/libtiff/tif_open.c index 8c88328cf2..5c9036e6b4 100644 --- a/third_party/libtiff/tif_open.c +++ b/third_party/libtiff/tif_open.c @@ -1,4 +1,4 @@ -/* $Id: tif_open.c,v 1.46 2010-12-06 16:54:54 faxguy Exp $ */ +/* $Id: tif_open.c,v 1.47 2016-01-23 21:20:34 erouault Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -168,7 +168,7 @@ TIFFClientOpen( * The following flags may be used to control intrinsic library * behaviour that may or may not be desirable (usually for * compatibility with some application that claims to support - * TIFF but only supports some braindead idea of what the + * TIFF but only supports some brain dead idea of what the * vendor thinks TIFF is): * * 'l' use little-endian byte order for creating a file @@ -198,8 +198,8 @@ TIFFClientOpen( * The 'L', 'B', and 'H' flags are intended for applications * that can optimize operations on data by using a particular * bit order. By default the library returns data in MSB2LSB - * bit order for compatibiltiy with older versions of this - * library. Returning data in the bit order of the native cpu + * bit order for compatibility with older versions of this + * library. Returning data in the bit order of the native CPU * makes the most sense but also requires applications to check * the value of the FillOrder tag; something they probably do * not do right now. diff --git a/third_party/libtiff/tif_packbits.c b/third_party/libtiff/tif_packbits.c index 9e77190131..d2a0165de9 100644 --- a/third_party/libtiff/tif_packbits.c +++ b/third_party/libtiff/tif_packbits.c @@ -1,4 +1,4 @@ -/* $Id: tif_packbits.c,v 1.22 2012-06-20 05:25:33 fwarmerdam Exp $ */ +/* $Id: tif_packbits.c,v 1.24 2016-09-04 21:32:56 erouault Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -38,7 +38,8 @@ PackBitsPreEncode(TIFF* tif, uint16 s) { (void) s; - if (!(tif->tif_data = (uint8*)_TIFFmalloc(sizeof(tmsize_t)))) + tif->tif_data = (uint8*)_TIFFmalloc(sizeof(tmsize_t)); + if (tif->tif_data == NULL) return (0); /* * Calculate the scanline/tile-width size in bytes. @@ -81,7 +82,9 @@ PackBitsEncode(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s) /* * Find the longest string of identical bytes. */ - b = *bp++, cc--, n = 1; + b = *bp++; + cc--; + n = 1; for (; cc > 0 && b == *bp; cc--, bp++) n++; again: @@ -222,7 +225,8 @@ PackBitsDecode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s) bp = (char*) tif->tif_rawcp; cc = tif->tif_rawcc; while (cc > 0 && occ > 0) { - n = (long) *bp++, cc--; + n = (long) *bp++; + cc--; /* * Watch out for compilers that * don't sign extend chars... @@ -241,7 +245,8 @@ PackBitsDecode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s) n = (long)occ; } occ -= n; - b = *bp++, cc--; + b = *bp++; + cc--; while (n-- > 0) *op++ = (uint8) b; } else { /* copy next n+1 bytes literally */ diff --git a/third_party/libtiff/tif_pixarlog.c b/third_party/libtiff/tif_pixarlog.c index 29535d31ee..0cf7f3a1ee 100644 --- a/third_party/libtiff/tif_pixarlog.c +++ b/third_party/libtiff/tif_pixarlog.c @@ -1,4 +1,4 @@ -/* $Id: tif_pixarlog.c,v 1.39 2012-12-10 17:27:13 tgl Exp $ */ +/* $Id: tif_pixarlog.c,v 1.48 2016-09-23 22:12:18 erouault Exp $ */ /* * Copyright (c) 1996-1997 Sam Leffler @@ -45,15 +45,15 @@ * input is assumed to be unsigned linear color values that represent * the range 0-1. In the case of IEEE values, the 0-1 range is assumed to * be the normal linear color range, in addition over 1 values are - * accepted up to a value of about 25.0 to encode "hot" hightlights and such. + * accepted up to a value of about 25.0 to encode "hot" highlights and such. * The encoding is lossless for 8-bit values, slightly lossy for the * other bit depths. The actual color precision should be better * than the human eye can perceive with extra room to allow for * error introduced by further image computation. As with any quantized * color format, it is possible to perform image calculations which * expose the quantization error. This format should certainly be less - * susceptable to such errors than standard 8-bit encodings, but more - * susceptable than straight 16-bit or 32-bit encodings. + * susceptible to such errors than standard 8-bit encodings, but more + * susceptible than straight 16-bit or 32-bit encodings. * * On reading the internal format is converted to the desired output format. * The program can request which format it desires by setting the internal @@ -296,33 +296,35 @@ horizontalAccumulate16(uint16 *wp, int n, int stride, uint16 *op, static void horizontalAccumulate11(uint16 *wp, int n, int stride, uint16 *op) { - register unsigned int cr, cg, cb, ca, mask; + register unsigned int cr, cg, cb, ca, mask; if (n >= stride) { mask = CODE_MASK; if (stride == 3) { - op[0] = cr = wp[0]; op[1] = cg = wp[1]; op[2] = cb = wp[2]; + op[0] = wp[0]; op[1] = wp[1]; op[2] = wp[2]; + cr = wp[0]; cg = wp[1]; cb = wp[2]; n -= 3; while (n > 0) { wp += 3; op += 3; n -= 3; - op[0] = (cr += wp[0]) & mask; - op[1] = (cg += wp[1]) & mask; - op[2] = (cb += wp[2]) & mask; + op[0] = (uint16)((cr += wp[0]) & mask); + op[1] = (uint16)((cg += wp[1]) & mask); + op[2] = (uint16)((cb += wp[2]) & mask); } } else if (stride == 4) { - op[0] = cr = wp[0]; op[1] = cg = wp[1]; - op[2] = cb = wp[2]; op[3] = ca = wp[3]; + op[0] = wp[0]; op[1] = wp[1]; + op[2] = wp[2]; op[3] = wp[3]; + cr = wp[0]; cg = wp[1]; cb = wp[2]; ca = wp[3]; n -= 4; while (n > 0) { wp += 4; op += 4; n -= 4; - op[0] = (cr += wp[0]) & mask; - op[1] = (cg += wp[1]) & mask; - op[2] = (cb += wp[2]) & mask; - op[3] = (ca += wp[3]) & mask; + op[0] = (uint16)((cr += wp[0]) & mask); + op[1] = (uint16)((cg += wp[1]) & mask); + op[2] = (uint16)((cb += wp[2]) & mask); + op[3] = (uint16)((ca += wp[3]) & mask); } } else { REPEAT(stride, *op = *wp&mask; wp++; op++) @@ -557,7 +559,7 @@ PixarLogMakeTables(PixarLogState *sp) for (i = 0; i < lt2size; i++) { if ((i*linstep)*(i*linstep) > ToLinearF[j]*ToLinearF[j+1]) j++; - FromLT2[i] = j; + FromLT2[i] = (uint16)j; } /* @@ -569,14 +571,14 @@ PixarLogMakeTables(PixarLogState *sp) for (i = 0; i < 16384; i++) { while ((i/16383.)*(i/16383.) > ToLinearF[j]*ToLinearF[j+1]) j++; - From14[i] = j; + From14[i] = (uint16)j; } j = 0; for (i = 0; i < 256; i++) { while ((i/255.)*(i/255.) > ToLinearF[j]*ToLinearF[j+1]) j++; - From8[i] = j; + From8[i] = (uint16)j; } Fltsize = (float)(lt2size/2); @@ -704,7 +706,7 @@ PixarLogSetupDecode(TIFF* tif) } if (inflateInit(&sp->stream) != Z_OK) { - TIFFErrorExt(tif->tif_clientdata, module, "%s", sp->stream.msg); + TIFFErrorExt(tif->tif_clientdata, module, "%s", sp->stream.msg ? sp->stream.msg : "(null)"); return (0); } else { sp->state |= PLSTATE_INIT; @@ -727,7 +729,7 @@ PixarLogPreDecode(TIFF* tif, uint16 s) assert(sizeof(sp->stream.avail_in)==4); /* if this assert gets raised, we need to simplify this code to reflect a ZLib that is likely updated to deal with 8byte memory sizes, though this code will respond - apropriately even before we simplify it */ + appropriately even before we simplify it */ sp->stream.avail_in = (uInt) tif->tif_rawcc; if ((tmsize_t)sp->stream.avail_in != tif->tif_rawcc) { @@ -776,7 +778,7 @@ PixarLogDecode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s) assert(sizeof(sp->stream.avail_out)==4); /* if this assert gets raised, we need to simplify this code to reflect a ZLib that is likely updated to deal with 8byte memory sizes, though this code will respond - apropriately even before we simplify it */ + appropriately even before we simplify it */ sp->stream.avail_out = (uInt) (nsamples * sizeof(uint16)); if (sp->stream.avail_out != nsamples * sizeof(uint16)) { @@ -797,14 +799,14 @@ PixarLogDecode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s) if (state == Z_DATA_ERROR) { TIFFErrorExt(tif->tif_clientdata, module, "Decoding error at scanline %lu, %s", - (unsigned long) tif->tif_row, sp->stream.msg); + (unsigned long) tif->tif_row, sp->stream.msg ? sp->stream.msg : "(null)"); if (inflateSync(&sp->stream) != Z_OK) return (0); continue; } if (state != Z_OK) { TIFFErrorExt(tif->tif_clientdata, module, "ZLib error: %s", - sp->stream.msg); + sp->stream.msg ? sp->stream.msg : "(null)"); return (0); } } while (sp->stream.avail_out > 0); @@ -906,7 +908,7 @@ PixarLogSetupEncode(TIFF* tif) } if (deflateInit(&sp->stream, sp->quality) != Z_OK) { - TIFFErrorExt(tif->tif_clientdata, module, "%s", sp->stream.msg); + TIFFErrorExt(tif->tif_clientdata, module, "%s", sp->stream.msg ? sp->stream.msg : "(null)"); return (0); } else { sp->state |= PLSTATE_INIT; @@ -929,8 +931,8 @@ PixarLogPreEncode(TIFF* tif, uint16 s) assert(sizeof(sp->stream.avail_out)==4); /* if this assert gets raised, we need to simplify this code to reflect a ZLib that is likely updated to deal with 8byte memory sizes, though this code will respond - apropriately even before we simplify it */ - sp->stream.avail_out = tif->tif_rawdatasize; + appropriately even before we simplify it */ + sp->stream.avail_out = (uInt)tif->tif_rawdatasize; if ((tmsize_t)sp->stream.avail_out != tif->tif_rawdatasize) { TIFFErrorExt(tif->tif_clientdata, module, "ZLib cannot deal with buffers this size"); @@ -961,9 +963,9 @@ horizontalDifferenceF(float *ip, int n, int stride, uint16 *wp, uint16 *FromLT2) n -= 3; wp += 3; ip += 3; - r1 = (int32) CLAMP(ip[0]); wp[0] = (r1-r2) & mask; r2 = r1; - g1 = (int32) CLAMP(ip[1]); wp[1] = (g1-g2) & mask; g2 = g1; - b1 = (int32) CLAMP(ip[2]); wp[2] = (b1-b2) & mask; b2 = b1; + r1 = (int32) CLAMP(ip[0]); wp[0] = (uint16)((r1-r2) & mask); r2 = r1; + g1 = (int32) CLAMP(ip[1]); wp[1] = (uint16)((g1-g2) & mask); g2 = g1; + b1 = (int32) CLAMP(ip[2]); wp[2] = (uint16)((b1-b2) & mask); b2 = b1; } } else if (stride == 4) { r2 = wp[0] = (uint16) CLAMP(ip[0]); @@ -975,23 +977,20 @@ horizontalDifferenceF(float *ip, int n, int stride, uint16 *wp, uint16 *FromLT2) n -= 4; wp += 4; ip += 4; - r1 = (int32) CLAMP(ip[0]); wp[0] = (r1-r2) & mask; r2 = r1; - g1 = (int32) CLAMP(ip[1]); wp[1] = (g1-g2) & mask; g2 = g1; - b1 = (int32) CLAMP(ip[2]); wp[2] = (b1-b2) & mask; b2 = b1; - a1 = (int32) CLAMP(ip[3]); wp[3] = (a1-a2) & mask; a2 = a1; + r1 = (int32) CLAMP(ip[0]); wp[0] = (uint16)((r1-r2) & mask); r2 = r1; + g1 = (int32) CLAMP(ip[1]); wp[1] = (uint16)((g1-g2) & mask); g2 = g1; + b1 = (int32) CLAMP(ip[2]); wp[2] = (uint16)((b1-b2) & mask); b2 = b1; + a1 = (int32) CLAMP(ip[3]); wp[3] = (uint16)((a1-a2) & mask); a2 = a1; } } else { - ip += n - 1; /* point to last one */ - wp += n - 1; /* point to last one */ - n -= stride; - while (n > 0) { - REPEAT(stride, wp[0] = (uint16) CLAMP(ip[0]); - wp[stride] -= wp[0]; - wp[stride] &= mask; - wp--; ip--) - n -= stride; - } - REPEAT(stride, wp[0] = (uint16) CLAMP(ip[0]); wp--; ip--) + REPEAT(stride, wp[0] = (uint16) CLAMP(ip[0]); wp++; ip++) + n -= stride; + while (n > 0) { + REPEAT(stride, + wp[0] = (uint16)(((int32)CLAMP(ip[0])-(int32)CLAMP(ip[-stride])) & mask); + wp++; ip++) + n -= stride; + } } } } @@ -1016,9 +1015,9 @@ horizontalDifference16(unsigned short *ip, int n, int stride, n -= 3; wp += 3; ip += 3; - r1 = CLAMP(ip[0]); wp[0] = (r1-r2) & mask; r2 = r1; - g1 = CLAMP(ip[1]); wp[1] = (g1-g2) & mask; g2 = g1; - b1 = CLAMP(ip[2]); wp[2] = (b1-b2) & mask; b2 = b1; + r1 = CLAMP(ip[0]); wp[0] = (uint16)((r1-r2) & mask); r2 = r1; + g1 = CLAMP(ip[1]); wp[1] = (uint16)((g1-g2) & mask); g2 = g1; + b1 = CLAMP(ip[2]); wp[2] = (uint16)((b1-b2) & mask); b2 = b1; } } else if (stride == 4) { r2 = wp[0] = CLAMP(ip[0]); g2 = wp[1] = CLAMP(ip[1]); @@ -1028,23 +1027,20 @@ horizontalDifference16(unsigned short *ip, int n, int stride, n -= 4; wp += 4; ip += 4; - r1 = CLAMP(ip[0]); wp[0] = (r1-r2) & mask; r2 = r1; - g1 = CLAMP(ip[1]); wp[1] = (g1-g2) & mask; g2 = g1; - b1 = CLAMP(ip[2]); wp[2] = (b1-b2) & mask; b2 = b1; - a1 = CLAMP(ip[3]); wp[3] = (a1-a2) & mask; a2 = a1; + r1 = CLAMP(ip[0]); wp[0] = (uint16)((r1-r2) & mask); r2 = r1; + g1 = CLAMP(ip[1]); wp[1] = (uint16)((g1-g2) & mask); g2 = g1; + b1 = CLAMP(ip[2]); wp[2] = (uint16)((b1-b2) & mask); b2 = b1; + a1 = CLAMP(ip[3]); wp[3] = (uint16)((a1-a2) & mask); a2 = a1; } } else { - ip += n - 1; /* point to last one */ - wp += n - 1; /* point to last one */ + REPEAT(stride, wp[0] = CLAMP(ip[0]); wp++; ip++) n -= stride; while (n > 0) { - REPEAT(stride, wp[0] = CLAMP(ip[0]); - wp[stride] -= wp[0]; - wp[stride] &= mask; - wp--; ip--) - n -= stride; - } - REPEAT(stride, wp[0] = CLAMP(ip[0]); wp--; ip--) + REPEAT(stride, + wp[0] = (uint16)((CLAMP(ip[0])-CLAMP(ip[-stride])) & mask); + wp++; ip++) + n -= stride; + } } } } @@ -1067,9 +1063,9 @@ horizontalDifference8(unsigned char *ip, int n, int stride, n -= 3; while (n > 0) { n -= 3; - r1 = CLAMP(ip[3]); wp[3] = (r1-r2) & mask; r2 = r1; - g1 = CLAMP(ip[4]); wp[4] = (g1-g2) & mask; g2 = g1; - b1 = CLAMP(ip[5]); wp[5] = (b1-b2) & mask; b2 = b1; + r1 = CLAMP(ip[3]); wp[3] = (uint16)((r1-r2) & mask); r2 = r1; + g1 = CLAMP(ip[4]); wp[4] = (uint16)((g1-g2) & mask); g2 = g1; + b1 = CLAMP(ip[5]); wp[5] = (uint16)((b1-b2) & mask); b2 = b1; wp += 3; ip += 3; } @@ -1079,26 +1075,23 @@ horizontalDifference8(unsigned char *ip, int n, int stride, n -= 4; while (n > 0) { n -= 4; - r1 = CLAMP(ip[4]); wp[4] = (r1-r2) & mask; r2 = r1; - g1 = CLAMP(ip[5]); wp[5] = (g1-g2) & mask; g2 = g1; - b1 = CLAMP(ip[6]); wp[6] = (b1-b2) & mask; b2 = b1; - a1 = CLAMP(ip[7]); wp[7] = (a1-a2) & mask; a2 = a1; + r1 = CLAMP(ip[4]); wp[4] = (uint16)((r1-r2) & mask); r2 = r1; + g1 = CLAMP(ip[5]); wp[5] = (uint16)((g1-g2) & mask); g2 = g1; + b1 = CLAMP(ip[6]); wp[6] = (uint16)((b1-b2) & mask); b2 = b1; + a1 = CLAMP(ip[7]); wp[7] = (uint16)((a1-a2) & mask); a2 = a1; wp += 4; ip += 4; } } else { - wp += n + stride - 1; /* point to last one */ - ip += n + stride - 1; /* point to last one */ - n -= stride; - while (n > 0) { - REPEAT(stride, wp[0] = CLAMP(ip[0]); - wp[stride] -= wp[0]; - wp[stride] &= mask; - wp--; ip--) - n -= stride; - } - REPEAT(stride, wp[0] = CLAMP(ip[0]); wp--; ip--) - } + REPEAT(stride, wp[0] = CLAMP(ip[0]); wp++; ip++) + n -= stride; + while (n > 0) { + REPEAT(stride, + wp[0] = (uint16)((CLAMP(ip[0])-CLAMP(ip[-stride])) & mask); + wp++; ip++) + n -= stride; + } + } } } @@ -1139,6 +1132,13 @@ PixarLogEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) } llen = sp->stride * td->td_imagewidth; + /* Check against the number of elements (of size uint16) of sp->tbuf */ + if( n > (tmsize_t)(td->td_rowsperstrip * llen) ) + { + TIFFErrorExt(tif->tif_clientdata, module, + "Too many input bytes provided"); + return 0; + } for (i = 0, up = sp->tbuf; i < n; i += llen, up += llen) { switch (sp->user_datafmt) { @@ -1169,7 +1169,7 @@ PixarLogEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) assert(sizeof(sp->stream.avail_in)==4); /* if this assert gets raised, we need to simplify this code to reflect a ZLib that is likely updated to deal with 8byte memory sizes, though this code will respond - apropriately even before we simplify it */ + appropriately even before we simplify it */ sp->stream.avail_in = (uInt) (n * sizeof(uint16)); if ((sp->stream.avail_in / sizeof(uint16)) != (uInt) n) { @@ -1181,7 +1181,7 @@ PixarLogEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) do { if (deflate(&sp->stream, Z_NO_FLUSH) != Z_OK) { TIFFErrorExt(tif->tif_clientdata, module, "Encoder error: %s", - sp->stream.msg); + sp->stream.msg ? sp->stream.msg : "(null)"); return (0); } if (sp->stream.avail_out == 0) { @@ -1223,7 +1223,7 @@ PixarLogPostEncode(TIFF* tif) break; default: TIFFErrorExt(tif->tif_clientdata, module, "ZLib error: %s", - sp->stream.msg); + sp->stream.msg ? sp->stream.msg : "(null)"); return (0); } } while (state != Z_STREAM_END); @@ -1235,7 +1235,7 @@ PixarLogClose(TIFF* tif) { TIFFDirectory *td = &tif->tif_dir; - /* In a really sneaky (and really incorrect, and untruthfull, and + /* In a really sneaky (and really incorrect, and untruthful, and * troublesome, and error-prone) maneuver that completely goes against * the spirit of TIFF, and breaks TIFF, on close, we covertly * modify both bitspersample and sampleformat in the directory to @@ -1293,7 +1293,7 @@ PixarLogVSetField(TIFF* tif, uint32 tag, va_list ap) if (deflateParams(&sp->stream, sp->quality, Z_DEFAULT_STRATEGY) != Z_OK) { TIFFErrorExt(tif->tif_clientdata, module, "ZLib error: %s", - sp->stream.msg); + sp->stream.msg ? sp->stream.msg : "(null)"); return (0); } } diff --git a/third_party/libtiff/tif_predict.c b/third_party/libtiff/tif_predict.c index 8975672aec..1bb78e2097 100644 --- a/third_party/libtiff/tif_predict.c +++ b/third_party/libtiff/tif_predict.c @@ -1,4 +1,4 @@ -/* $Id: tif_predict.c,v 1.35 2015-08-31 15:05:57 erouault Exp $ */ +/* $Id: tif_predict.c,v 1.40 2016-11-04 09:19:13 erouault Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -34,18 +34,18 @@ #define PredictorState(tif) ((TIFFPredictorState*) (tif)->tif_data) -static void horAcc8(TIFF* tif, uint8* cp0, tmsize_t cc); -static void horAcc16(TIFF* tif, uint8* cp0, tmsize_t cc); -static void horAcc32(TIFF* tif, uint8* cp0, tmsize_t cc); -static void swabHorAcc16(TIFF* tif, uint8* cp0, tmsize_t cc); -static void swabHorAcc32(TIFF* tif, uint8* cp0, tmsize_t cc); -static void horDiff8(TIFF* tif, uint8* cp0, tmsize_t cc); -static void horDiff16(TIFF* tif, uint8* cp0, tmsize_t cc); -static void horDiff32(TIFF* tif, uint8* cp0, tmsize_t cc); -static void swabHorDiff16(TIFF* tif, uint8* cp0, tmsize_t cc); -static void swabHorDiff32(TIFF* tif, uint8* cp0, tmsize_t cc); -static void fpAcc(TIFF* tif, uint8* cp0, tmsize_t cc); -static void fpDiff(TIFF* tif, uint8* cp0, tmsize_t cc); +static int horAcc8(TIFF* tif, uint8* cp0, tmsize_t cc); +static int horAcc16(TIFF* tif, uint8* cp0, tmsize_t cc); +static int horAcc32(TIFF* tif, uint8* cp0, tmsize_t cc); +static int swabHorAcc16(TIFF* tif, uint8* cp0, tmsize_t cc); +static int swabHorAcc32(TIFF* tif, uint8* cp0, tmsize_t cc); +static int horDiff8(TIFF* tif, uint8* cp0, tmsize_t cc); +static int horDiff16(TIFF* tif, uint8* cp0, tmsize_t cc); +static int horDiff32(TIFF* tif, uint8* cp0, tmsize_t cc); +static int swabHorDiff16(TIFF* tif, uint8* cp0, tmsize_t cc); +static int swabHorDiff32(TIFF* tif, uint8* cp0, tmsize_t cc); +static int fpAcc(TIFF* tif, uint8* cp0, tmsize_t cc); +static int fpDiff(TIFF* tif, uint8* cp0, tmsize_t cc); static int PredictorDecodeRow(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s); static int PredictorDecodeTile(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s); static int PredictorEncodeRow(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s); @@ -80,6 +80,15 @@ PredictorSetup(TIFF* tif) td->td_sampleformat); return 0; } + if (td->td_bitspersample != 16 + && td->td_bitspersample != 24 + && td->td_bitspersample != 32 + && td->td_bitspersample != 64) { /* Should 64 be allowed? */ + TIFFErrorExt(tif->tif_clientdata, module, + "Floating point \"Predictor\" not supported with %d-bit samples", + td->td_bitspersample); + return 0; + } break; default: TIFFErrorExt(tif->tif_clientdata, module, @@ -177,7 +186,7 @@ PredictorSetupDecode(TIFF* tif) } /* * Allocate buffer to keep the decoded bytes before - * rearranging in the ight order + * rearranging in the right order */ } @@ -216,7 +225,7 @@ PredictorSetupEncode(TIFF* tif) /* * If the data is horizontally differenced 16-bit data that * requires byte-swapping, then it must be byte swapped after - * the differenciation step. We do this with a special-purpose + * the differentiation step. We do this with a special-purpose * routine and override the normal post decoding logic that * the library setup when the directory was read. */ @@ -267,13 +276,19 @@ PredictorSetupEncode(TIFF* tif) /* - when storing into the byte stream, we explicitly mask with 0xff so */ /* as to make icc -check=conversions happy (not necessary by the standard) */ -static void +static int horAcc8(TIFF* tif, uint8* cp0, tmsize_t cc) { tmsize_t stride = PredictorState(tif)->stride; unsigned char* cp = (unsigned char*) cp0; - assert((cc%stride)==0); + if((cc%stride)!=0) + { + TIFFErrorExt(tif->tif_clientdata, "horAcc8", + "%s", "(cc%stride)!=0"); + return 0; + } + if (cc > stride) { /* * Pipeline the most common cases. @@ -315,26 +330,32 @@ horAcc8(TIFF* tif, uint8* cp0, tmsize_t cc) } while (cc>0); } } + return 1; } -static void +static int swabHorAcc16(TIFF* tif, uint8* cp0, tmsize_t cc) { uint16* wp = (uint16*) cp0; tmsize_t wc = cc / 2; TIFFSwabArrayOfShort(wp, wc); - horAcc16(tif, cp0, cc); + return horAcc16(tif, cp0, cc); } -static void +static int horAcc16(TIFF* tif, uint8* cp0, tmsize_t cc) { tmsize_t stride = PredictorState(tif)->stride; uint16* wp = (uint16*) cp0; tmsize_t wc = cc / 2; - assert((cc%(2*stride))==0); + if((cc%(2*stride))!=0) + { + TIFFErrorExt(tif->tif_clientdata, "horAcc16", + "%s", "cc%(2*stride))!=0"); + return 0; + } if (wc > stride) { wc -= stride; @@ -343,26 +364,32 @@ horAcc16(TIFF* tif, uint8* cp0, tmsize_t cc) wc -= stride; } while (wc > 0); } + return 1; } -static void +static int swabHorAcc32(TIFF* tif, uint8* cp0, tmsize_t cc) { uint32* wp = (uint32*) cp0; tmsize_t wc = cc / 4; TIFFSwabArrayOfLong(wp, wc); - horAcc32(tif, cp0, cc); + return horAcc32(tif, cp0, cc); } -static void +static int horAcc32(TIFF* tif, uint8* cp0, tmsize_t cc) { tmsize_t stride = PredictorState(tif)->stride; uint32* wp = (uint32*) cp0; tmsize_t wc = cc / 4; - assert((cc%(4*stride))==0); + if((cc%(4*stride))!=0) + { + TIFFErrorExt(tif->tif_clientdata, "horAcc32", + "%s", "cc%(4*stride))!=0"); + return 0; + } if (wc > stride) { wc -= stride; @@ -371,12 +398,13 @@ horAcc32(TIFF* tif, uint8* cp0, tmsize_t cc) wc -= stride; } while (wc > 0); } + return 1; } /* * Floating point predictor accumulation routine. */ -static void +static int fpAcc(TIFF* tif, uint8* cp0, tmsize_t cc) { tmsize_t stride = PredictorState(tif)->stride; @@ -384,12 +412,18 @@ fpAcc(TIFF* tif, uint8* cp0, tmsize_t cc) tmsize_t wc = cc / bps; tmsize_t count = cc; uint8 *cp = (uint8 *) cp0; - uint8 *tmp = (uint8 *)_TIFFmalloc(cc); + uint8 *tmp; - assert((cc%(bps*stride))==0); + if(cc%(bps*stride)!=0) + { + TIFFErrorExt(tif->tif_clientdata, "fpAcc", + "%s", "cc%(bps*stride))!=0"); + return 0; + } + tmp = (uint8 *)_TIFFmalloc(cc); if (!tmp) - return; + return 0; while (count > stride) { REPEAT4(stride, cp[stride] = @@ -411,6 +445,7 @@ fpAcc(TIFF* tif, uint8* cp0, tmsize_t cc) } } _TIFFfree(tmp); + return 1; } /* @@ -426,8 +461,7 @@ PredictorDecodeRow(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s) assert(sp->decodepfunc != NULL); if ((*sp->decoderow)(tif, op0, occ0, s)) { - (*sp->decodepfunc)(tif, op0, occ0); - return 1; + return (*sp->decodepfunc)(tif, op0, occ0); } else return 0; } @@ -450,10 +484,16 @@ PredictorDecodeTile(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s) if ((*sp->decodetile)(tif, op0, occ0, s)) { tmsize_t rowsize = sp->rowsize; assert(rowsize > 0); - assert((occ0%rowsize)==0); + if((occ0%rowsize) !=0) + { + TIFFErrorExt(tif->tif_clientdata, "PredictorDecodeTile", + "%s", "occ0%rowsize != 0"); + return 0; + } assert(sp->decodepfunc != NULL); while (occ0 > 0) { - (*sp->decodepfunc)(tif, op0, rowsize); + if( !(*sp->decodepfunc)(tif, op0, rowsize) ) + return 0; occ0 -= rowsize; op0 += rowsize; } @@ -462,14 +502,19 @@ PredictorDecodeTile(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s) return 0; } -static void +static int horDiff8(TIFF* tif, uint8* cp0, tmsize_t cc) { TIFFPredictorState* sp = PredictorState(tif); tmsize_t stride = sp->stride; unsigned char* cp = (unsigned char*) cp0; - assert((cc%stride)==0); + if((cc%stride)!=0) + { + TIFFErrorExt(tif->tif_clientdata, "horDiff8", + "%s", "(cc%stride)!=0"); + return 0; + } if (cc > stride) { cc -= stride; @@ -507,9 +552,10 @@ horDiff8(TIFF* tif, uint8* cp0, tmsize_t cc) } while ((cc -= stride) > 0); } } + return 1; } -static void +static int horDiff16(TIFF* tif, uint8* cp0, tmsize_t cc) { TIFFPredictorState* sp = PredictorState(tif); @@ -517,7 +563,12 @@ horDiff16(TIFF* tif, uint8* cp0, tmsize_t cc) uint16 *wp = (uint16*) cp0; tmsize_t wc = cc/2; - assert((cc%(2*stride))==0); + if((cc%(2*stride))!=0) + { + TIFFErrorExt(tif->tif_clientdata, "horDiff8", + "%s", "(cc%(2*stride))!=0"); + return 0; + } if (wc > stride) { wc -= stride; @@ -527,20 +578,23 @@ horDiff16(TIFF* tif, uint8* cp0, tmsize_t cc) wc -= stride; } while (wc > 0); } + return 1; } -static void +static int swabHorDiff16(TIFF* tif, uint8* cp0, tmsize_t cc) { uint16* wp = (uint16*) cp0; tmsize_t wc = cc / 2; - horDiff16(tif, cp0, cc); + if( !horDiff16(tif, cp0, cc) ) + return 0; TIFFSwabArrayOfShort(wp, wc); + return 1; } -static void +static int horDiff32(TIFF* tif, uint8* cp0, tmsize_t cc) { TIFFPredictorState* sp = PredictorState(tif); @@ -548,7 +602,12 @@ horDiff32(TIFF* tif, uint8* cp0, tmsize_t cc) uint32 *wp = (uint32*) cp0; tmsize_t wc = cc/4; - assert((cc%(4*stride))==0); + if((cc%(4*stride))!=0) + { + TIFFErrorExt(tif->tif_clientdata, "horDiff32", + "%s", "(cc%(4*stride))!=0"); + return 0; + } if (wc > stride) { wc -= stride; @@ -558,23 +617,26 @@ horDiff32(TIFF* tif, uint8* cp0, tmsize_t cc) wc -= stride; } while (wc > 0); } + return 1; } -static void +static int swabHorDiff32(TIFF* tif, uint8* cp0, tmsize_t cc) { uint32* wp = (uint32*) cp0; tmsize_t wc = cc / 4; - horDiff32(tif, cp0, cc); + if( !horDiff32(tif, cp0, cc) ) + return 0; TIFFSwabArrayOfLong(wp, wc); + return 1; } /* * Floating point predictor differencing routine. */ -static void +static int fpDiff(TIFF* tif, uint8* cp0, tmsize_t cc) { tmsize_t stride = PredictorState(tif)->stride; @@ -582,12 +644,18 @@ fpDiff(TIFF* tif, uint8* cp0, tmsize_t cc) tmsize_t wc = cc / bps; tmsize_t count; uint8 *cp = (uint8 *) cp0; - uint8 *tmp = (uint8 *)_TIFFmalloc(cc); + uint8 *tmp; - assert((cc%(bps*stride))==0); + if((cc%(bps*stride))!=0) + { + TIFFErrorExt(tif->tif_clientdata, "fpDiff", + "%s", "(cc%(bps*stride))!=0"); + return 0; + } + tmp = (uint8 *)_TIFFmalloc(cc); if (!tmp) - return; + return 0; _TIFFmemcpy(tmp, cp0, cc); for (count = 0; count < wc; count++) { @@ -607,6 +675,7 @@ fpDiff(TIFF* tif, uint8* cp0, tmsize_t cc) cp += cc - stride - 1; for (count = cc; count > stride; count -= stride) REPEAT4(stride, cp[stride] = (unsigned char)((cp[stride] - cp[0])&0xff); cp--) + return 1; } static int @@ -619,7 +688,8 @@ PredictorEncodeRow(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) assert(sp->encoderow != NULL); /* XXX horizontal differencing alters user's data XXX */ - (*sp->encodepfunc)(tif, bp, cc); + if( !(*sp->encodepfunc)(tif, bp, cc) ) + return 0; return (*sp->encoderow)(tif, bp, cc, s); } @@ -654,7 +724,13 @@ PredictorEncodeTile(TIFF* tif, uint8* bp0, tmsize_t cc0, uint16 s) rowsize = sp->rowsize; assert(rowsize > 0); - assert((cc0%rowsize)==0); + if((cc0%rowsize)!=0) + { + TIFFErrorExt(tif->tif_clientdata, "PredictorEncodeTile", + "%s", "(cc0%rowsize)!=0"); + _TIFFfree( working_copy ); + return 0; + } while (cc > 0) { (*sp->encodepfunc)(tif, bp, rowsize); cc -= rowsize; @@ -703,7 +779,7 @@ PredictorVGetField(TIFF* tif, uint32 tag, va_list ap) switch (tag) { case TIFFTAG_PREDICTOR: - *va_arg(ap, uint16*) = sp->predictor; + *va_arg(ap, uint16*) = (uint16)sp->predictor; break; default: return (*sp->vgetparent)(tif, tag, ap); diff --git a/third_party/libtiff/tif_predict.h b/third_party/libtiff/tif_predict.h index dc7144c69e..6c68e21acb 100644 --- a/third_party/libtiff/tif_predict.h +++ b/third_party/libtiff/tif_predict.h @@ -1,4 +1,4 @@ -/* $Id: tif_predict.h,v 1.8 2010-03-10 18:56:49 bfriesen Exp $ */ +/* $Id: tif_predict.h,v 1.9 2016-10-31 17:24:26 erouault Exp $ */ /* * Copyright (c) 1995-1997 Sam Leffler @@ -30,6 +30,8 @@ * ``Library-private'' Support for the Predictor Tag */ +typedef int (*TIFFEncodeDecodeMethod)(TIFF* tif, uint8* buf, tmsize_t size); + /* * Codecs that want to support the Predictor tag must place * this structure first in their private state block so that @@ -43,12 +45,12 @@ typedef struct { TIFFCodeMethod encoderow; /* parent codec encode/decode row */ TIFFCodeMethod encodestrip; /* parent codec encode/decode strip */ TIFFCodeMethod encodetile; /* parent codec encode/decode tile */ - TIFFPostMethod encodepfunc; /* horizontal differencer */ + TIFFEncodeDecodeMethod encodepfunc; /* horizontal differencer */ TIFFCodeMethod decoderow; /* parent codec encode/decode row */ TIFFCodeMethod decodestrip; /* parent codec encode/decode strip */ TIFFCodeMethod decodetile; /* parent codec encode/decode tile */ - TIFFPostMethod decodepfunc; /* horizontal accumulator */ + TIFFEncodeDecodeMethod decodepfunc; /* horizontal accumulator */ TIFFVGetMethod vgetparent; /* super-class method */ TIFFVSetMethod vsetparent; /* super-class method */ diff --git a/third_party/libtiff/tif_print.c b/third_party/libtiff/tif_print.c index 7b1a4222a3..186f2ee5c0 100644 --- a/third_party/libtiff/tif_print.c +++ b/third_party/libtiff/tif_print.c @@ -1,4 +1,4 @@ -/* $Id: tif_print.c,v 1.62 2015-08-19 02:31:04 bfriesen Exp $ */ +/* $Id: tif_print.c,v 1.64 2015-12-06 22:19:56 erouault Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -37,7 +37,7 @@ static void _TIFFprintAsciiBounded(FILE* fd, const char* cp, size_t max_chars); -static const char *photoNames[] = { +static const char * const photoNames[] = { "min-is-white", /* PHOTOMETRIC_MINISWHITE */ "min-is-black", /* PHOTOMETRIC_MINISBLACK */ "RGB color", /* PHOTOMETRIC_RGB */ @@ -52,7 +52,7 @@ static const char *photoNames[] = { }; #define NPHOTONAMES (sizeof (photoNames) / sizeof (photoNames[0])) -static const char *orientNames[] = { +static const char * const orientNames[] = { "0 (0x0)", "row 0 top, col 0 lhs", /* ORIENTATION_TOPLEFT */ "row 0 top, col 0 rhs", /* ORIENTATION_TOPRIGHT */ @@ -237,7 +237,6 @@ TIFFPrintDirectory(TIFF* tif, FILE* fd, long flags) { TIFFDirectory *td = &tif->tif_dir; char *sep; - uint16 i; long l, n; #if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) @@ -365,6 +364,7 @@ TIFFPrintDirectory(TIFF* tif, FILE* fd, long flags) } } if (TIFFFieldSet(tif,FIELD_EXTRASAMPLES) && td->td_extrasamples) { + uint16 i; fprintf(fd, " Extra Samples: %u<", td->td_extrasamples); sep = ""; for (i = 0; i < td->td_extrasamples; i++) { @@ -389,6 +389,7 @@ TIFFPrintDirectory(TIFF* tif, FILE* fd, long flags) } if (TIFFFieldSet(tif,FIELD_INKNAMES)) { char* cp; + uint16 i; fprintf(fd, " Ink Names: "); i = td->td_samplesperpixel; sep = ""; @@ -481,6 +482,7 @@ TIFFPrintDirectory(TIFF* tif, FILE* fd, long flags) if (TIFFFieldSet(tif,FIELD_MAXSAMPLEVALUE)) fprintf(fd, " Max Sample Value: %u\n", td->td_maxsamplevalue); if (TIFFFieldSet(tif,FIELD_SMINSAMPLEVALUE)) { + int i; int count = (tif->tif_flags & TIFF_PERSAMPLE) ? td->td_samplesperpixel : 1; fprintf(fd, " SMin Sample Value:"); for (i = 0; i < count; ++i) @@ -488,6 +490,7 @@ TIFFPrintDirectory(TIFF* tif, FILE* fd, long flags) fprintf(fd, "\n"); } if (TIFFFieldSet(tif,FIELD_SMAXSAMPLEVALUE)) { + int i; int count = (tif->tif_flags & TIFF_PERSAMPLE) ? td->td_samplesperpixel : 1; fprintf(fd, " SMax Sample Value:"); for (i = 0; i < count; ++i) @@ -527,6 +530,7 @@ TIFFPrintDirectory(TIFF* tif, FILE* fd, long flags) fprintf(fd, "(present)\n"); } if (TIFFFieldSet(tif,FIELD_REFBLACKWHITE)) { + int i; fprintf(fd, " Reference Black/White:\n"); for (i = 0; i < 3; i++) fprintf(fd, " %2d: %5g %5g\n", i, @@ -539,6 +543,7 @@ TIFFPrintDirectory(TIFF* tif, FILE* fd, long flags) fprintf(fd, "\n"); n = 1L<td_bitspersample; for (l = 0; l < n; l++) { + uint16 i; fprintf(fd, " %2lu: %5u", l, td->td_transferfunction[0][l]); for (i = 1; i < td->td_samplesperpixel; i++) @@ -550,6 +555,7 @@ TIFFPrintDirectory(TIFF* tif, FILE* fd, long flags) fprintf(fd, "(present)\n"); } if (TIFFFieldSet(tif, FIELD_SUBIFD) && (td->td_subifd)) { + uint16 i; fprintf(fd, " SubIFD Offsets:"); for (i = 0; i < td->td_nsubifd; i++) #if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__)) diff --git a/third_party/libtiff/tif_read.c b/third_party/libtiff/tif_read.c index 548b1f5ea6..795153bbfe 100644 --- a/third_party/libtiff/tif_read.c +++ b/third_party/libtiff/tif_read.c @@ -1,4 +1,4 @@ -/* $Id: tif_read.c,v 1.45 2015-06-07 22:35:40 bfriesen Exp $ */ +/* $Id: tif_read.c,v 1.49 2016-07-10 18:00:21 erouault Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -31,6 +31,9 @@ #include "tiffiop.h" #include +#define TIFF_SIZE_T_MAX ((size_t) ~ ((size_t)0)) +#define TIFF_TMSIZE_T_MAX (tmsize_t)(TIFF_SIZE_T_MAX >> 1) + int TIFFFillStrip(TIFF* tif, uint32 strip); int TIFFFillTile(TIFF* tif, uint32 tile); static int TIFFStartStrip(TIFF* tif, uint32 strip); @@ -38,6 +41,8 @@ static int TIFFStartTile(TIFF* tif, uint32 tile); static int TIFFCheckRead(TIFF*, int); static tmsize_t TIFFReadRawStrip1(TIFF* tif, uint32 strip, void* buf, tmsize_t size,const char* module); +static tmsize_t +TIFFReadRawTile1(TIFF* tif, uint32 tile, void* buf, tmsize_t size, const char* module); #define NOSTRIP ((uint32)(-1)) /* undefined state */ #define NOTILE ((uint32)(-1)) /* undefined state */ @@ -343,13 +348,31 @@ TIFFReadEncodedStrip(TIFF* tif, uint32 strip, void* buf, tmsize_t size) rowsperstrip=td->td_imagelength; stripsperplane=((td->td_imagelength+rowsperstrip-1)/rowsperstrip); stripinplane=(strip%stripsperplane); - plane=(strip/stripsperplane); + plane=(uint16)(strip/stripsperplane); rows=td->td_imagelength-stripinplane*rowsperstrip; if (rows>rowsperstrip) rows=rowsperstrip; stripsize=TIFFVStripSize(tif,rows); if (stripsize==0) return((tmsize_t)(-1)); + + /* shortcut to avoid an extra memcpy() */ + if( td->td_compression == COMPRESSION_NONE && + size!=(tmsize_t)(-1) && size >= stripsize && + !isMapped(tif) && + ((tif->tif_flags&TIFF_NOREADRAW)==0) ) + { + if (TIFFReadRawStrip1(tif, strip, buf, stripsize, module) != stripsize) + return ((tmsize_t)(-1)); + + if (!isFillOrder(tif, td->td_fillorder) && + (tif->tif_flags & TIFF_NOBITREV) == 0) + TIFFReverseBits(buf,stripsize); + + (*tif->tif_postdecode)(tif,buf,stripsize); + return (stripsize); + } + if ((size!=(tmsize_t)(-1))&&(sizetd_stripoffset[strip]; mb=ma+size; - if (((uint64)ma!=td->td_stripoffset[strip])||(ma>tif->tif_size)) + if ((td->td_stripoffset[strip] > (uint64)TIFF_TMSIZE_T_MAX)||(ma>tif->tif_size)) n=0; else if ((mbtif->tif_size)) n=tif->tif_size-ma; @@ -492,9 +515,9 @@ TIFFFillStrip(TIFF* tif, uint32 strip) static const char module[] = "TIFFFillStrip"; TIFFDirectory *td = &tif->tif_dir; - if (!_TIFFFillStriles( tif ) || !tif->tif_dir.td_stripbytecount) - return 0; - + if (!_TIFFFillStriles( tif ) || !tif->tif_dir.td_stripbytecount) + return 0; + if ((tif->tif_flags&TIFF_NOREADRAW)==0) { uint64 bytecount = td->td_stripbytecount[strip]; @@ -661,6 +684,24 @@ TIFFReadEncodedTile(TIFF* tif, uint32 tile, void* buf, tmsize_t size) (unsigned long) tile, (unsigned long) td->td_nstrips); return ((tmsize_t)(-1)); } + + /* shortcut to avoid an extra memcpy() */ + if( td->td_compression == COMPRESSION_NONE && + size!=(tmsize_t)(-1) && size >= tilesize && + !isMapped(tif) && + ((tif->tif_flags&TIFF_NOREADRAW)==0) ) + { + if (TIFFReadRawTile1(tif, tile, buf, tilesize, module) != tilesize) + return ((tmsize_t)(-1)); + + if (!isFillOrder(tif, td->td_fillorder) && + (tif->tif_flags & TIFF_NOBITREV) == 0) + TIFFReverseBits(buf,tilesize); + + (*tif->tif_postdecode)(tif,buf,tilesize); + return (tilesize); + } + if (size == (tmsize_t)(-1)) size = tilesize; else if (size > tilesize) @@ -717,7 +758,7 @@ TIFFReadRawTile1(TIFF* tif, uint32 tile, void* buf, tmsize_t size, const char* m tmsize_t n; ma=(tmsize_t)td->td_stripoffset[tile]; mb=ma+size; - if (((uint64)ma!=td->td_stripoffset[tile])||(ma>tif->tif_size)) + if ((td->td_stripoffset[tile] > (uint64)TIFF_TMSIZE_T_MAX)||(ma>tif->tif_size)) n=0; else if ((mbtif->tif_size)) n=tif->tif_size-ma; @@ -795,9 +836,9 @@ TIFFFillTile(TIFF* tif, uint32 tile) static const char module[] = "TIFFFillTile"; TIFFDirectory *td = &tif->tif_dir; - if (!_TIFFFillStriles( tif ) || !tif->tif_dir.td_stripbytecount) - return 0; - + if (!_TIFFFillStriles( tif ) || !tif->tif_dir.td_stripbytecount) + return 0; + if ((tif->tif_flags&TIFF_NOREADRAW)==0) { uint64 bytecount = td->td_stripbytecount[tile]; @@ -960,8 +1001,8 @@ TIFFStartStrip(TIFF* tif, uint32 strip) { TIFFDirectory *td = &tif->tif_dir; - if (!_TIFFFillStriles( tif ) || !tif->tif_dir.td_stripbytecount) - return 0; + if (!_TIFFFillStriles( tif ) || !tif->tif_dir.td_stripbytecount) + return 0; if ((tif->tif_flags & TIFF_CODERSETUP) == 0) { if (!(*tif->tif_setupdecode)(tif)) diff --git a/third_party/libtiff/tif_strip.c b/third_party/libtiff/tif_strip.c index 6cac71dd92..b6098dd312 100644 --- a/third_party/libtiff/tif_strip.c +++ b/third_party/libtiff/tif_strip.c @@ -1,4 +1,4 @@ -/* $Id: tif_strip.c,v 1.36 2015-06-07 22:35:40 bfriesen Exp $ */ +/* $Id: tif_strip.c,v 1.37 2016-11-09 23:00:49 erouault Exp $ */ /* * Copyright (c) 1991-1997 Sam Leffler @@ -63,6 +63,15 @@ TIFFNumberOfStrips(TIFF* tif) TIFFDirectory *td = &tif->tif_dir; uint32 nstrips; + /* If the value was already computed and store in td_nstrips, then return it, + since ChopUpSingleUncompressedStrip might have altered and resized the + since the td_stripbytecount and td_stripoffset arrays to the new value + after the initial affectation of td_nstrips = TIFFNumberOfStrips() in + tif_dirread.c ~line 3612. + See http://bugzilla.maptools.org/show_bug.cgi?id=2587 */ + if( td->td_nstrips ) + return td->td_nstrips; + nstrips = (td->td_rowsperstrip == (uint32) -1 ? 1 : TIFFhowmany_32(td->td_imagelength, td->td_rowsperstrip)); if (td->td_planarconfig == PLANARCONFIG_SEPARATE) diff --git a/third_party/libtiff/tif_swab.c b/third_party/libtiff/tif_swab.c index f37e33f1c9..211dc576eb 100644 --- a/third_party/libtiff/tif_swab.c +++ b/third_party/libtiff/tif_swab.c @@ -1,4 +1,4 @@ -/* $Id: tif_swab.c,v 1.13 2010-03-10 18:56:49 bfriesen Exp $ */ +/* $Id: tif_swab.c,v 1.14 2016-09-04 21:32:56 erouault Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -296,8 +296,10 @@ TIFFReverseBits(uint8* cp, tmsize_t n) cp[7] = TIFFBitRevTable[cp[7]]; cp += 8; } - while (n-- > 0) - *cp = TIFFBitRevTable[*cp], cp++; + while (n-- > 0) { + *cp = TIFFBitRevTable[*cp]; + cp++; + } } /* vim: set ts=8 sts=8 sw=8 noet: */ diff --git a/third_party/libtiff/tif_thunder.c b/third_party/libtiff/tif_thunder.c index 390891c98b..183199de76 100644 --- a/third_party/libtiff/tif_thunder.c +++ b/third_party/libtiff/tif_thunder.c @@ -1,4 +1,4 @@ -/* $Id: tif_thunder.c,v 1.12 2011-04-02 20:54:09 bfriesen Exp $ */ +/* $Id: tif_thunder.c,v 1.13 2016-09-04 21:32:56 erouault Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -100,7 +100,8 @@ ThunderDecode(TIFF* tif, uint8* op, tmsize_t maxpixels) while (cc > 0 && npixels < maxpixels) { int n, delta; - n = *bp++, cc--; + n = *bp++; + cc--; switch (n & THUNDER_CODE) { case THUNDER_RUN: /* pixel run */ /* diff --git a/third_party/libtiff/tif_write.c b/third_party/libtiff/tif_write.c index 7996c31e08..34c4d81a09 100644 --- a/third_party/libtiff/tif_write.c +++ b/third_party/libtiff/tif_write.c @@ -1,4 +1,4 @@ -/* $Id: tif_write.c,v 1.42 2015-06-07 23:00:23 bfriesen Exp $ */ +/* $Id: tif_write.c,v 1.45 2016-09-23 22:12:18 erouault Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -258,6 +258,23 @@ TIFFWriteEncodedStrip(TIFF* tif, uint32 strip, void* data, tmsize_t cc) tif->tif_rawcp = tif->tif_rawdata; tif->tif_flags &= ~TIFF_POSTENCODE; + + /* shortcut to avoid an extra memcpy() */ + if( td->td_compression == COMPRESSION_NONE ) + { + /* swab if needed - note that source buffer will be altered */ + tif->tif_postdecode( tif, (uint8*) data, cc ); + + if (!isFillOrder(tif, td->td_fillorder) && + (tif->tif_flags & TIFF_NOBITREV) == 0) + TIFFReverseBits((uint8*) data, cc); + + if (cc > 0 && + !TIFFAppendToStrip(tif, strip, (uint8*) data, cc)) + return ((tmsize_t) -1); + return (cc); + } + sample = (uint16)(strip / td->td_stripsperimage); if (!(*tif->tif_preencode)(tif, sample)) return ((tmsize_t) -1); @@ -266,7 +283,7 @@ TIFFWriteEncodedStrip(TIFF* tif, uint32 strip, void* data, tmsize_t cc) tif->tif_postdecode( tif, (uint8*) data, cc ); if (!(*tif->tif_encodestrip)(tif, (uint8*) data, cc, sample)) - return (0); + return ((tmsize_t) -1); if (!(*tif->tif_postencode)(tif)) return ((tmsize_t) -1); if (!isFillOrder(tif, td->td_fillorder) && @@ -431,9 +448,7 @@ TIFFWriteEncodedTile(TIFF* tif, uint32 tile, void* data, tmsize_t cc) tif->tif_flags |= TIFF_CODERSETUP; } tif->tif_flags &= ~TIFF_POSTENCODE; - sample = (uint16)(tile/td->td_stripsperimage); - if (!(*tif->tif_preencode)(tif, sample)) - return ((tmsize_t)(-1)); + /* * Clamp write amount to the tile size. This is mostly * done so that callers can pass in some large number @@ -442,11 +457,30 @@ TIFFWriteEncodedTile(TIFF* tif, uint32 tile, void* data, tmsize_t cc) if ( cc < 1 || cc > tif->tif_tilesize) cc = tif->tif_tilesize; + /* shortcut to avoid an extra memcpy() */ + if( td->td_compression == COMPRESSION_NONE ) + { + /* swab if needed - note that source buffer will be altered */ + tif->tif_postdecode( tif, (uint8*) data, cc ); + + if (!isFillOrder(tif, td->td_fillorder) && + (tif->tif_flags & TIFF_NOBITREV) == 0) + TIFFReverseBits((uint8*) data, cc); + + if (cc > 0 && + !TIFFAppendToStrip(tif, tile, (uint8*) data, cc)) + return ((tmsize_t) -1); + return (cc); + } + + sample = (uint16)(tile/td->td_stripsperimage); + if (!(*tif->tif_preencode)(tif, sample)) + return ((tmsize_t)(-1)); /* swab if needed - note that source buffer will be altered */ tif->tif_postdecode( tif, (uint8*) data, cc ); if (!(*tif->tif_encodetile)(tif, (uint8*) data, cc, sample)) - return (0); + return ((tmsize_t) -1); if (!(*tif->tif_postencode)(tif)) return ((tmsize_t)(-1)); if (!isFillOrder(tif, td->td_fillorder) && @@ -764,7 +798,14 @@ TIFFFlushData1(TIFF* tif) if (!TIFFAppendToStrip(tif, isTiled(tif) ? tif->tif_curtile : tif->tif_curstrip, tif->tif_rawdata, tif->tif_rawcc)) + { + /* We update those variables even in case of error since there's */ + /* code that doesn't really check the return code of this */ + /* function */ + tif->tif_rawcc = 0; + tif->tif_rawcp = tif->tif_rawdata; return (0); + } tif->tif_rawcc = 0; tif->tif_rawcp = tif->tif_rawdata; } diff --git a/third_party/libtiff/tif_zip.c b/third_party/libtiff/tif_zip.c index b3ac9b956e..92fd0ed463 100644 --- a/third_party/libtiff/tif_zip.c +++ b/third_party/libtiff/tif_zip.c @@ -1,4 +1,4 @@ -/* $Id: tif_zip.c,v 1.33 2014-12-25 18:29:11 erouault Exp $ */ +/* $Id: tif_zip.c,v 1.36 2016-11-12 16:48:28 erouault Exp $ */ /* * Copyright (c) 1995-1997 Sam Leffler @@ -135,7 +135,7 @@ ZIPPreDecode(TIFF* tif, uint16 s) assert(sizeof(sp->stream.avail_in)==4); /* if this assert gets raised, we need to simplify this code to reflect a ZLib that is likely updated to deal with 8byte memory sizes, though this code will respond - apropriately even before we simplify it */ + appropriately even before we simplify it */ sp->stream.avail_in = (uInt) tif->tif_rawcc; if ((tmsize_t)sp->stream.avail_in != tif->tif_rawcc) { @@ -162,7 +162,7 @@ ZIPDecode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s) assert(sizeof(sp->stream.avail_out)==4); /* if this assert gets raised, we need to simplify this code to reflect a ZLib that is likely updated to deal with 8byte memory sizes, though this code will respond - apropriately even before we simplify it */ + appropriately even before we simplify it */ sp->stream.avail_out = (uInt) occ; if ((tmsize_t)sp->stream.avail_out != occ) { @@ -239,8 +239,8 @@ ZIPPreEncode(TIFF* tif, uint16 s) assert(sizeof(sp->stream.avail_out)==4); /* if this assert gets raised, we need to simplify this code to reflect a ZLib that is likely updated to deal with 8byte memory sizes, though this code will respond - apropriately even before we simplify it */ - sp->stream.avail_out = tif->tif_rawdatasize; + appropriately even before we simplify it */ + sp->stream.avail_out = (uInt)tif->tif_rawdatasize; if ((tmsize_t)sp->stream.avail_out != tif->tif_rawdatasize) { TIFFErrorExt(tif->tif_clientdata, module, "ZLib cannot deal with buffers this size"); @@ -266,7 +266,7 @@ ZIPEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) assert(sizeof(sp->stream.avail_in)==4); /* if this assert gets raised, we need to simplify this code to reflect a ZLib that is likely updated to deal with 8byte memory sizes, though this code will respond - apropriately even before we simplify it */ + appropriately even before we simplify it */ sp->stream.avail_in = (uInt) cc; if ((tmsize_t)sp->stream.avail_in != cc) { @@ -460,7 +460,7 @@ bad: "No space for ZIP state block"); return (0); } -#endif /* ZIP_SUPORT */ +#endif /* ZIP_SUPPORT */ /* vim: set ts=8 sts=8 sw=8 noet: */ /* diff --git a/third_party/libtiff/tiff.h b/third_party/libtiff/tiff.h index bc46acd02b..fb39634c4b 100644 --- a/third_party/libtiff/tiff.h +++ b/third_party/libtiff/tiff.h @@ -1,4 +1,4 @@ -/* $Id: tiff.h,v 1.69 2014-04-02 17:23:06 fwarmerdam Exp $ */ +/* $Id: tiff.h,v 1.70 2016-01-23 21:20:34 erouault Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -279,7 +279,7 @@ typedef enum { #define PREDICTOR_FLOATINGPOINT 3 /* floating point predictor */ #define TIFFTAG_WHITEPOINT 318 /* image white point */ #define TIFFTAG_PRIMARYCHROMATICITIES 319 /* !primary chromaticities */ -#define TIFFTAG_COLORMAP 320 /* RGB map for pallette image */ +#define TIFFTAG_COLORMAP 320 /* RGB map for palette image */ #define TIFFTAG_HALFTONEHINTS 321 /* !highlight+shadow info */ #define TIFFTAG_TILEWIDTH 322 /* !tile width in pixels */ #define TIFFTAG_TILELENGTH 323 /* !tile height in pixels */ @@ -358,7 +358,7 @@ typedef enum { #define TIFFTAG_JPEGRESTARTINTERVAL 515 /* !restart interval length */ #define TIFFTAG_JPEGLOSSLESSPREDICTORS 517 /* !lossless proc predictor */ #define TIFFTAG_JPEGPOINTTRANSFORM 518 /* !lossless point transform */ -#define TIFFTAG_JPEGQTABLES 519 /* !Q matrice offsets */ +#define TIFFTAG_JPEGQTABLES 519 /* !Q matrix offsets */ #define TIFFTAG_JPEGDCTABLES 520 /* !DCT table offsets */ #define TIFFTAG_JPEGACTABLES 521 /* !AC coefficient offsets */ #define TIFFTAG_YCBCRCOEFFICIENTS 529 /* !RGB -> YCbCr transform */ diff --git a/third_party/libtiff/tiffio.h b/third_party/libtiff/tiffio.h index 056aed22f7..dd6c9a4294 100644 --- a/third_party/libtiff/tiffio.h +++ b/third_party/libtiff/tiffio.h @@ -1,4 +1,4 @@ -/* $Id: tiffio.h,v 1.91 2012-07-29 15:45:29 tgl Exp $ */ +/* $Id: tiffio.h,v 1.92 2016-01-23 21:20:34 erouault Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -208,7 +208,7 @@ struct _TIFFRGBAImage { uint16 orientation; /* image orientation */ uint16 req_orientation; /* requested orientation */ uint16 photometric; /* image photometric interp */ - uint16* redcmap; /* colormap pallete */ + uint16* redcmap; /* colormap palette */ uint16* greencmap; uint16* bluecmap; /* get image data routine */ @@ -225,7 +225,7 @@ struct _TIFFRGBAImage { TIFFYCbCrToRGB* ycbcr; /* YCbCr conversion state */ TIFFCIELabToRGB* cielab; /* CIE L*a*b conversion state */ - uint8* UaToAa; /* Unassociated alpha to associated alpha convertion LUT */ + uint8* UaToAa; /* Unassociated alpha to associated alpha conversion LUT */ uint8* Bitdepth16To8; /* LUT for conversion from 16bit to 8bit values */ int row_offset; diff --git a/third_party/libtiff/tiffiop.h b/third_party/libtiff/tiffiop.h index f4b2ea480a..b6db1e932c 100644 --- a/third_party/libtiff/tiffiop.h +++ b/third_party/libtiff/tiffiop.h @@ -1,4 +1,4 @@ -/* $Id: tiffiop.h,v 1.87 2015-08-23 17:49:01 bfriesen Exp $ */ +/* $Id: tiffiop.h,v 1.89 2016-01-23 21:20:34 erouault Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -85,7 +85,7 @@ typedef struct client_info { /* * Typedefs for ``method pointers'' used internally. - * these are depriciated and provided only for backwards compatibility + * these are deprecated and provided only for backwards compatibility. */ typedef unsigned char tidataval_t; /* internal image data value type */ typedef tidataval_t* tidata_t; /* reference to internal image data */ @@ -104,33 +104,33 @@ struct tiff { int tif_fd; /* open file descriptor */ int tif_mode; /* open mode (O_*) */ uint32 tif_flags; - #define TIFF_FILLORDER 0x00003 /* natural bit fill order for machine */ - #define TIFF_DIRTYHEADER 0x00004 /* header must be written on close */ - #define TIFF_DIRTYDIRECT 0x00008 /* current directory must be written */ - #define TIFF_BUFFERSETUP 0x00010 /* data buffers setup */ - #define TIFF_CODERSETUP 0x00020 /* encoder/decoder setup done */ - #define TIFF_BEENWRITING 0x00040 /* written 1+ scanlines to file */ - #define TIFF_SWAB 0x00080 /* byte swap file information */ - #define TIFF_NOBITREV 0x00100 /* inhibit bit reversal logic */ - #define TIFF_MYBUFFER 0x00200 /* my raw data buffer; free on close */ - #define TIFF_ISTILED 0x00400 /* file is tile, not strip- based */ - #define TIFF_MAPPED 0x00800 /* file is mapped into memory */ - #define TIFF_POSTENCODE 0x01000 /* need call to postencode routine */ - #define TIFF_INSUBIFD 0x02000 /* currently writing a subifd */ - #define TIFF_UPSAMPLED 0x04000 /* library is doing data up-sampling */ - #define TIFF_STRIPCHOP 0x08000 /* enable strip chopping support */ - #define TIFF_HEADERONLY 0x10000 /* read header only, do not process the first directory */ - #define TIFF_NOREADRAW 0x20000 /* skip reading of raw uncompressed image data */ - #define TIFF_INCUSTOMIFD 0x40000 /* currently writing a custom IFD */ - #define TIFF_BIGTIFF 0x80000 /* read/write bigtiff */ - #define TIFF_BUF4WRITE 0x100000 /* rawcc bytes are for writing */ - #define TIFF_DIRTYSTRIP 0x200000 /* stripoffsets/stripbytecount dirty*/ - #define TIFF_PERSAMPLE 0x400000 /* get/set per sample tags as arrays */ - #define TIFF_BUFFERMMAP 0x800000 /* read buffer (tif_rawdata) points into mmap() memory */ + #define TIFF_FILLORDER 0x00003U /* natural bit fill order for machine */ + #define TIFF_DIRTYHEADER 0x00004U /* header must be written on close */ + #define TIFF_DIRTYDIRECT 0x00008U /* current directory must be written */ + #define TIFF_BUFFERSETUP 0x00010U /* data buffers setup */ + #define TIFF_CODERSETUP 0x00020U /* encoder/decoder setup done */ + #define TIFF_BEENWRITING 0x00040U /* written 1+ scanlines to file */ + #define TIFF_SWAB 0x00080U /* byte swap file information */ + #define TIFF_NOBITREV 0x00100U /* inhibit bit reversal logic */ + #define TIFF_MYBUFFER 0x00200U /* my raw data buffer; free on close */ + #define TIFF_ISTILED 0x00400U /* file is tile, not strip- based */ + #define TIFF_MAPPED 0x00800U /* file is mapped into memory */ + #define TIFF_POSTENCODE 0x01000U /* need call to postencode routine */ + #define TIFF_INSUBIFD 0x02000U /* currently writing a subifd */ + #define TIFF_UPSAMPLED 0x04000U /* library is doing data up-sampling */ + #define TIFF_STRIPCHOP 0x08000U /* enable strip chopping support */ + #define TIFF_HEADERONLY 0x10000U /* read header only, do not process the first directory */ + #define TIFF_NOREADRAW 0x20000U /* skip reading of raw uncompressed image data */ + #define TIFF_INCUSTOMIFD 0x40000U /* currently writing a custom IFD */ + #define TIFF_BIGTIFF 0x80000U /* read/write bigtiff */ + #define TIFF_BUF4WRITE 0x100000U /* rawcc bytes are for writing */ + #define TIFF_DIRTYSTRIP 0x200000U /* stripoffsets/stripbytecount dirty*/ + #define TIFF_PERSAMPLE 0x400000U /* get/set per sample tags as arrays */ + #define TIFF_BUFFERMMAP 0x800000U /* read buffer (tif_rawdata) points into mmap() memory */ uint64 tif_diroff; /* file offset of current directory */ uint64 tif_nextdiroff; /* file offset of following directory */ uint64* tif_dirlist; /* list of offsets to already seen directories to prevent IFD looping */ - uint16 tif_dirlistsize; /* number of entires in offset list */ + uint16 tif_dirlistsize; /* number of entries in offset list */ uint16 tif_dirnumber; /* number of already seen directories */ TIFFDirectory tif_dir; /* internal rep of current directory */ TIFFDirectory tif_customdir; /* custom IFDs are separated from the main ones */ diff --git a/third_party/libtiff/tiffvers.h b/third_party/libtiff/tiffvers.h index e965814b3d..fe55c726cb 100644 --- a/third_party/libtiff/tiffvers.h +++ b/third_party/libtiff/tiffvers.h @@ -1,4 +1,4 @@ -#define TIFFLIB_VERSION_STR "LIBTIFF, Version 4.0.6\nCopyright (c) 1988-1996 Sam Leffler\nCopyright (c) 1991-1996 Silicon Graphics, Inc." +#define TIFFLIB_VERSION_STR "LIBTIFF, Version 4.0.7\nCopyright (c) 1988-1996 Sam Leffler\nCopyright (c) 1991-1996 Silicon Graphics, Inc." /* * This define can be used in code that requires * compilation-related definitions specific to a @@ -6,4 +6,4 @@ * version checking should be done based on the * string returned by TIFFGetVersion. */ -#define TIFFLIB_VERSION 20150912 +#define TIFFLIB_VERSION 20161119 diff --git a/third_party/libtiff/uvcode.h b/third_party/libtiff/uvcode.h index 50f11d7e0a..6286cfbb0c 100644 --- a/third_party/libtiff/uvcode.h +++ b/third_party/libtiff/uvcode.h @@ -3,7 +3,7 @@ #define UV_NDIVS 16289 #define UV_VSTART (float)0.016940 #define UV_NVS 163 -static struct { +static const struct { float ustart; short nus, ncum; } uv_row[UV_NVS] = { -- cgit v1.2.3