summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.vc3
-rw-r--r--html/libtiff.html28
-rw-r--r--libtiff/tif_config.vc.h21
-rw-r--r--libtiff/tif_dirread.c64
-rw-r--r--libtiff/tif_ojpeg.c2
-rw-r--r--libtiff/tif_win32.c50
-rw-r--r--libtiff/tif_write.c7
-rw-r--r--nmake.opt10
-rw-r--r--port/Makefile.vc44
-rw-r--r--port/libport.h12
-rw-r--r--test/CMakeLists.txt6
-rw-r--r--test/Makefile.am6
-rw-r--r--test/images/ojpeg_single_strip_no_rowsperstrip.tiffbin0 -> 8258 bytes
-rwxr-xr-xtest/tiff2rgba-ojpeg_single_strip_no_rowsperstrip.sh7
-rw-r--r--tools/raw2tiff.c25
-rw-r--r--tools/tiff2pdf.c5
-rw-r--r--tools/tiff2ps.c12
-rw-r--r--tools/tiffcrop.c4
-rw-r--r--tools/tiffset.c4
19 files changed, 241 insertions, 69 deletions
diff --git a/Makefile.vc b/Makefile.vc
index 6e66c730..eeb5d04d 100644
--- a/Makefile.vc
+++ b/Makefile.vc
@@ -31,6 +31,9 @@
all: port lib tools
port::
+ cd libtiff
+ $(MAKE) /f Makefile.vc tif_config.h
+ cd..
cd port
$(MAKE) /f Makefile.vc
cd..
diff --git a/html/libtiff.html b/html/libtiff.html
index 56535d97..d6b5eab3 100644
--- a/html/libtiff.html
+++ b/html/libtiff.html
@@ -518,9 +518,9 @@
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &amp;imagelength);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;buf = _TIFFmalloc(TIFFScanlineSize(tif));<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (row = 0; row &lt; imagelength; row++)<br>
- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tiffreadscanline(tif, buf, row);<br>
- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_tifffree(buf);<br>
- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tiffclose(tif);<br>
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TIFFReadScanline(tif, buf, row, 0);<br>
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_TIFFfree(buf);<br>
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TIFFClose(tif);<br>
&nbsp;&nbsp;&nbsp;&nbsp;}<br>
}</tt>
</p>
@@ -547,17 +547,17 @@
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;buf = _TIFFmalloc(TIFFScanlineSize(tif));<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (config == PLANARCONFIG_CONTIG) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (row = 0; row &lt; imagelength; row++)<br>
- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tiffreadscanline(tif, buf, row);<br>
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TIFFReadScanline(tif, buf, row, 0);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} else if (config == planarconfig_separate) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;uint16 s, nsamples;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tiffgetfield(tif, tifftag_samplesperpixel, &amp;nsamples);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (s = 0; s &lt; nsamples; s++)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (row = 0; row &lt; imagelength; row++)<br>
- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tiffreadscanline(tif, buf, row, s);<br>
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TIFFReadScanline(tif, buf, row, s);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>
- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_tifffree(buf);<br>
- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tiffclose(tif);<br>
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_TIFFfree(buf);<br>
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TIFFClose(tif);<br>
&nbsp;&nbsp;&nbsp;&nbsp;}<br>
}</tt>
</p>
@@ -568,7 +568,7 @@
<p style="margin-left: 40px">
<tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (row = 0; row &lt; imagelength; row++)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (s = 0; s &lt; nsamples; s++)<br>
- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tiffreadscanline(tif, buf, row, s);</tt>
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TIFFReadScanline(tif, buf, row, s);</tt>
</p>
<p>
...then problems would arise if <tt>RowsPerStrip</tt> was not one
@@ -601,8 +601,8 @@
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;buf = _TIFFmalloc(TIFFStripSize(tif));<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (strip = 0; strip &lt; tiffnumberofstrips(tif); strip++)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tiffreadencodedstrip(tif, strip, buf, (tsize_t) -1);<br>
- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_tifffree(buf);<br>
- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tiffclose(tif);<br>
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_TIFFfree(buf);<br>
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TIFFClose(tif);<br>
&nbsp;&nbsp;&nbsp;&nbsp;}<br>
}</tt>
</p>
@@ -702,8 +702,8 @@
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (y = 0; y &lt; imagelength; y += tilelength)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (x = 0; x &lt; imagewidth; x += tilewidth)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tiffreadtile(tif, buf, x, y, 0);<br>
- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_tifffree(buf);<br>
- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tiffclose(tif);<br>
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_TIFFfree(buf);<br>
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TIFFClose(tif);<br>
&nbsp;&nbsp;&nbsp;&nbsp;}<br>
}</tt>
</p>
@@ -729,8 +729,8 @@
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;buf = _TIFFmalloc(TIFFTileSize(tif));<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (tile = 0; tile &lt; tiffnumberoftiles(tif); tile++)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tiffreadencodedtile(tif, tile, buf, (tsize_t) -1);<br>
- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_tifffree(buf);<br>
- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tiffclose(tif);<br>
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_TIFFfree(buf);<br>
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TIFFClose(tif);<br>
&nbsp;&nbsp;&nbsp;&nbsp;}<br>
}</tt>
</p>
diff --git a/libtiff/tif_config.vc.h b/libtiff/tif_config.vc.h
index 5cebfa02..939594f8 100644
--- a/libtiff/tif_config.vc.h
+++ b/libtiff/tif_config.vc.h
@@ -104,11 +104,24 @@
/* Set the native cpu bit order */
#define HOST_FILLORDER FILLORDER_LSB2MSB
+/*
+ Please see associated settings in "nmake.opt" which configure porting
+ settings. It should not be necessary to edit the following pre-processor
+ logic.
+*/
+#if defined(_MSC_VER)
/* Visual Studio 2015 / VC 14 / MSVC 19.00 finally has snprintf() */
-#if defined(_MSC_VER) && _MSC_VER < 1900
-#define snprintf _snprintf
-#else
-#define HAVE_SNPRINTF 1
+# if _MSC_VER < 1900 /* Visual C++ 2015 */
+# define snprintf _snprintf
+# else
+# define HAVE_SNPRINTF 1
+# endif
+# define HAVE_STRTOL 1
+# define HAVE_STRTOUL 1
+# if _MSC_VER >= 1900 /* Visual Studio 2015 added strtoll/strtoull */
+# define HAVE_STRTOLL 1
+# define HAVE_STRTOULL 1
+# endif
#endif
/* Define to 1 if your processor stores words with the most significant byte
diff --git a/libtiff/tif_dirread.c b/libtiff/tif_dirread.c
index 6f909413..58f2eb53 100644
--- a/libtiff/tif_dirread.c
+++ b/libtiff/tif_dirread.c
@@ -3902,11 +3902,51 @@ TIFFReadDirectory(TIFF* tif)
break;
case TIFFTAG_STRIPOFFSETS:
case TIFFTAG_TILEOFFSETS:
+ switch( dp->tdir_type )
+ {
+ case TIFF_SHORT:
+ case TIFF_LONG:
+ case TIFF_LONG8:
+ break;
+ default:
+ /* Warn except if directory typically created with TIFFDeferStrileArrayWriting() */
+ if( !(tif->tif_mode == O_RDWR &&
+ dp->tdir_count == 0 &&
+ dp->tdir_type == 0 &&
+ dp->tdir_offset.toff_long8 == 0) )
+ {
+ fip = TIFFFieldWithTag(tif,dp->tdir_tag);
+ TIFFWarningExt(tif->tif_clientdata,module,
+ "Invalid data type for tag %s",
+ fip ? fip->field_name : "unknown tagname");
+ }
+ break;
+ }
_TIFFmemcpy( &(tif->tif_dir.td_stripoffset_entry),
dp, sizeof(TIFFDirEntry) );
break;
case TIFFTAG_STRIPBYTECOUNTS:
case TIFFTAG_TILEBYTECOUNTS:
+ switch( dp->tdir_type )
+ {
+ case TIFF_SHORT:
+ case TIFF_LONG:
+ case TIFF_LONG8:
+ break;
+ default:
+ /* Warn except if directory typically created with TIFFDeferStrileArrayWriting() */
+ if( !(tif->tif_mode == O_RDWR &&
+ dp->tdir_count == 0 &&
+ dp->tdir_type == 0 &&
+ dp->tdir_offset.toff_long8 == 0) )
+ {
+ fip = TIFFFieldWithTag(tif,dp->tdir_tag);
+ TIFFWarningExt(tif->tif_clientdata,module,
+ "Invalid data type for tag %s",
+ fip ? fip->field_name : "unknown tagname");
+ }
+ break;
+ }
_TIFFmemcpy( &(tif->tif_dir.td_stripbytecount_entry),
dp, sizeof(TIFFDirEntry) );
break;
@@ -5140,6 +5180,7 @@ TIFFFetchNormalTag(TIFF* tif, TIFFDirEntry* dp, int recover)
if (err==TIFFReadDirEntryErrOk)
{
int m;
+ assert(data); /* avoid CLang static Analyzer false positive */
m=TIFFSetField(tif,dp->tdir_tag,data[0],data[1]);
_TIFFfree(data);
if (!m)
@@ -6034,6 +6075,12 @@ int _TIFFPartialReadStripArray( TIFF* tif, TIFFDirEntry* dirent,
{
sizeofval = sizeof(uint64);
}
+ else if( dirent->tdir_type == TIFF_SLONG8 )
+ {
+ /* Non conformant but used by some images as in */
+ /* https://github.com/OSGeo/gdal/issues/2165 */
+ sizeofval = sizeof(int64);
+ }
else
{
TIFFErrorExt(tif->tif_clientdata, module,
@@ -6106,7 +6153,7 @@ int _TIFFPartialReadStripArray( TIFF* tif, TIFFDirEntry* dirent,
_TIFFUnsanitizedAddUInt64AndInt(nOffset, (i + 1) * sizeofvalint) <= nOffsetEndPage;
++i )
{
- if( sizeofval == sizeof(uint16) )
+ if( dirent->tdir_type == TIFF_SHORT )
{
uint16 val;
memcpy(&val,
@@ -6116,7 +6163,7 @@ int _TIFFPartialReadStripArray( TIFF* tif, TIFFDirEntry* dirent,
TIFFSwabShort(&val);
panVals[strile + i] = val;
}
- else if( sizeofval == sizeof(uint32) )
+ else if( dirent->tdir_type == TIFF_LONG )
{
uint32 val;
memcpy(&val,
@@ -6126,7 +6173,7 @@ int _TIFFPartialReadStripArray( TIFF* tif, TIFFDirEntry* dirent,
TIFFSwabLong(&val);
panVals[strile + i] = val;
}
- else
+ else if( dirent->tdir_type == TIFF_LONG8 )
{
uint64 val;
memcpy(&val,
@@ -6136,6 +6183,17 @@ int _TIFFPartialReadStripArray( TIFF* tif, TIFFDirEntry* dirent,
TIFFSwabLong8(&val);
panVals[strile + i] = val;
}
+ else /* if( dirent->tdir_type == TIFF_SLONG8 ) */
+ {
+ /* Non conformant data type */
+ int64 val;
+ memcpy(&val,
+ buffer + (nOffset - nOffsetStartPage) + i * sizeofvalint,
+ sizeof(val));
+ if( bSwab )
+ TIFFSwabLong8((uint64*) &val);
+ panVals[strile + i] = (uint64) val;
+ }
}
return 1;
}
diff --git a/libtiff/tif_ojpeg.c b/libtiff/tif_ojpeg.c
index d6f7d97e..aa5ff5e2 100644
--- a/libtiff/tif_ojpeg.c
+++ b/libtiff/tif_ojpeg.c
@@ -1064,6 +1064,8 @@ OJPEGReadHeaderInfo(TIFF* tif)
{
sp->strile_width=sp->image_width;
sp->strile_length=tif->tif_dir.td_rowsperstrip;
+ if( sp->strile_length == (uint32)-1 )
+ sp->strile_length = sp->image_length;
sp->strile_length_total=sp->image_length;
}
if (tif->tif_dir.td_samplesperpixel==1)
diff --git a/libtiff/tif_win32.c b/libtiff/tif_win32.c
index 088880e7..bf5fbfb3 100644
--- a/libtiff/tif_win32.c
+++ b/libtiff/tif_win32.c
@@ -27,33 +27,37 @@
* Scott Wagner (wagner@itek.com), Itek Graphix, Rochester, NY USA
*/
-/*
- CreateFileA/CreateFileW return type 'HANDLE'.
-
- thandle_t is declared like
-
- DECLARE_HANDLE(thandle_t);
+#include "tiffiop.h"
- in tiffio.h.
+#include <windows.h>
- Windows (from winnt.h) DECLARE_HANDLE logic looks like
+/*
+ CreateFileA/CreateFileW return type 'HANDLE' while TIFFFdOpen() takes 'int',
+ which is formally incompatible and can even seemingly be of different size:
+ HANDLE is 64 bit under Win64, while int is still 32 bits there.
- #ifdef STRICT
- typedef void *HANDLE;
- #define DECLARE_HANDLE(name) struct name##__ { int unused; }; typedef struct name##__ *name
- #else
- typedef PVOID HANDLE;
- #define DECLARE_HANDLE(name) typedef HANDLE name
- #endif
+ However, only the lower 32 bits of a HANDLE are significant under Win64 as,
+ for interoperability reasons, they must have the same values in 32- and
+ 64-bit programs running on the same system, see
- See http://bugzilla.maptools.org/show_bug.cgi?id=1941 for problems in WIN64
- builds resulting from this. Unfortunately, the proposed patch was lost.
+ https://docs.microsoft.com/en-us/windows/win32/winprog64/interprocess-communication
+ Because of this, it is safe to define the following trivial functions for
+ casting between ints and HANDLEs, which are only really needed to avoid
+ compiler warnings (and, perhaps, to make the code slightly more clear).
+ Note that using the intermediate cast to "intptr_t" is crucial for warning
+ avoidance, as this integer type has the same size as HANDLE in all builds.
*/
-
-#include "tiffiop.h"
-#include <windows.h>
+static inline thandle_t thandle_from_int(int ifd)
+{
+ return (thandle_t)(intptr_t)ifd;
+}
+
+static inline int thandle_to_int(thandle_t fd)
+{
+ return (int)(intptr_t)fd;
+}
static tmsize_t
_tiffReadProc(thandle_t fd, void* buf, tmsize_t size)
@@ -237,7 +241,7 @@ TIFFFdOpen(int ifd, const char* name, const char* mode)
break;
}
}
- tif = TIFFClientOpen(name, mode, (thandle_t)ifd, /* FIXME: WIN64 cast to pointer warning */
+ tif = TIFFClientOpen(name, mode, thandle_from_int(ifd),
_tiffReadProc, _tiffWriteProc,
_tiffSeekProc, _tiffCloseProc, _tiffSizeProc,
fSuppressMap ? _tiffDummyMapProc : _tiffMapProc,
@@ -282,7 +286,7 @@ TIFFOpen(const char* name, const char* mode)
return ((TIFF *)0);
}
- tif = TIFFFdOpen((int)fd, name, mode); /* FIXME: WIN64 cast from pointer to int warning */
+ tif = TIFFFdOpen(thandle_to_int(fd), name, mode);
if(!tif)
CloseHandle(fd);
return tif;
@@ -337,7 +341,7 @@ TIFFOpenW(const wchar_t* name, const char* mode)
NULL, NULL);
}
- tif = TIFFFdOpen((int)fd, /* FIXME: WIN64 cast from pointer to int warning */
+ tif = TIFFFdOpen(thandle_to_int(fd),
(mbname != NULL) ? mbname : "<unknown>", mode);
if(!tif)
CloseHandle(fd);
diff --git a/libtiff/tif_write.c b/libtiff/tif_write.c
index 33e803c1..f79330e9 100644
--- a/libtiff/tif_write.c
+++ b/libtiff/tif_write.c
@@ -533,6 +533,13 @@ TIFFSetupStrips(TIFF* tif)
isUnspecified(tif, FIELD_ROWSPERSTRIP) ?
td->td_samplesperpixel : TIFFNumberOfStrips(tif);
td->td_nstrips = td->td_stripsperimage;
+ /* TIFFWriteDirectoryTagData has a limitation to 0x80000000U bytes */
+ if( td->td_nstrips >= 0x80000000U / ((tif->tif_flags&TIFF_BIGTIFF)?0x8U:0x4U) )
+ {
+ TIFFErrorExt(tif->tif_clientdata, "TIFFSetupStrips",
+ "Too large Strip/Tile Offsets/ByteCounts arrays");
+ return 0;
+ }
if (td->td_planarconfig == PLANARCONFIG_SEPARATE)
td->td_stripsperimage /= td->td_samplesperpixel;
td->td_stripoffset_p = (uint64 *)
diff --git a/nmake.opt b/nmake.opt
index ae544670..d9bf15f1 100644
--- a/nmake.opt
+++ b/nmake.opt
@@ -29,6 +29,7 @@
# Usage examples (see details below):
# nmake -f makefile.vc
# nmake -f makefile.vc DEBUG=1
+# nmake -f makefile.vc clean
#
#
###### Edit the following lines to choose a feature set you need. #######
@@ -108,6 +109,11 @@ CHECK_JPEG_YCBCR_SUBSAMPLING = 1
####################### Compiler related options. #######################
#
+
+# Indicate if the compiler provides strtoll/strtoull (default 1)
+# Users of MSVC++ 14.0 ("Visual Studio 2015") and later should set this to 1
+HAVE_STRTOLL = 1
+
#
# Pick debug or optimized build flags. We default to an optimized build
# with no debugging information.
@@ -118,7 +124,7 @@ OPTFLAGS = /MDd /EHsc /W3 /D_CRT_SECURE_NO_DEPRECATE
!ELSE
OPTFLAGS = /Ox /MD /EHsc /W3 /D_CRT_SECURE_NO_DEPRECATE
!ENDIF
-#OPTFLAGS = /Zi
+#OPTFLAGS = /Zi
#
# Uncomment following line to enable using Windows Common RunTime Library
@@ -139,7 +145,7 @@ LD = link /nologo
CFLAGS = $(OPTFLAGS) $(INCL) $(EXTRAFLAGS)
CXXFLAGS = $(OPTFLAGS) $(INCL) $(EXTRAFLAGS)
-EXTRAFLAGS =
+EXTRAFLAGS = -DHAVE_CONFIG_H
LIBS =
# Name of the output shared library
diff --git a/port/Makefile.vc b/port/Makefile.vc
index 992d2696..e4471af5 100644
--- a/port/Makefile.vc
+++ b/port/Makefile.vc
@@ -23,13 +23,53 @@
# Makefile for MS Visual C and Watcom C compilers.
#
# To build:
-# C:\libtiff\port> nmake /f makefile.vc
+# C:\libtiff\port> nmake /f makefile.vc
!INCLUDE ..\nmake.opt
+HAVE_STRTOL = 1
+HAVE_STRTOUL = 1
+
+# strtoul()/strtoull() are provided together
+!IF $(HAVE_STRTOLL)
+HAVE_STRTOULL = 1
+!ELSE
+HAVE_STRTOULL = 0
+!endif
+
+!IF $(HAVE_STRTOL)
+STRTOL_OBJ =
+!ELSE
+STRTOL_OBJ = strtol.obj
+!ENDIF
+
+!IF $(HAVE_STRTOUL)
+STRTOUL_OBJ =
+!ELSE
+STRTOUL_OBJ = strtoul.obj
+!ENDIF
+
+!IF $(HAVE_STRTOLL)
+STRTOLL_OBJ =
+!ELSE
+STRTOLL_OBJ = strtoll.obj
+!ENDIF
+
+!IF $(HAVE_STRTOULL)
+STRTOULL_OBJ =
+!ELSE
+STRTOULL_OBJ = strtoull.obj
+!ENDIF
+
+INCL = -I..\libtiff
+
OBJ = \
- snprintf.obj \
+ snprintf.obj \
strcasecmp.obj \
+ $(STRTOL_OBJ) \
+ $(STRTOUL_OBJ) \
+ $(STRTOLL_OBJ) \
+ $(STRTOULL_OBJ) \
getopt.obj
all: libport.lib
diff --git a/port/libport.h b/port/libport.h
index ff262638..9f2dace1 100644
--- a/port/libport.h
+++ b/port/libport.h
@@ -24,6 +24,10 @@
#ifndef _LIBPORT_
#define _LIBPORT_
+#if defined(HAVE_CONFIG_H)
+# include <tif_config.h>
+#endif
+
int getopt(int argc, char * const argv[], const char *optstring);
extern char *optarg;
extern int opterr;
@@ -36,16 +40,16 @@ int strcasecmp(const char *s1, const char *s2);
# define HAVE_GETOPT 1
#endif
-#if HAVE_STRTOL
+#if !defined(HAVE_STRTOL)
long strtol(const char *nptr, char **endptr, int base);
#endif
-#if HAVE_STRTOLL
+#if !defined(HAVE_STRTOLL)
long long strtoll(const char *nptr, char **endptr, int base);
#endif
-#if HAVE_STRTOUL
+#if !defined(HAVE_STRTOUL)
unsigned long strtoul(const char *nptr, char **endptr, int base);
#endif
-#if HAVE_STRTOULL
+#if !defined(HAVE_STRTOULL)
unsigned long long strtoull(const char *nptr, char **endptr, int base);
#endif
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index c89bb824..23b678cf 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -107,7 +107,8 @@ set(TESTSCRIPTS
tiff2rgba-rgb-3c-8b.sh
tiff2rgba-quad-tile.jpg.sh
tiff2rgba-ojpeg_zackthecat_subsamp22_single_strip.sh
- tiff2rgba-ojpeg_chewey_subsamp21_multi_strip.sh)
+ tiff2rgba-ojpeg_chewey_subsamp21_multi_strip.sh
+ tiff2rgba-ojpeg_single_strip_no_rowsperstrip.sh)
# This list should contain all of the TIFF files in the 'images'
# subdirectory which are intended to be used as input images for
@@ -127,7 +128,8 @@ set(TIFFIMAGES
images/quad-lzw-compat.tiff
images/lzw-single-strip.tiff
images/ojpeg_zackthecat_subsamp22_single_strip.tiff
- images/ojpeg_chewey_subsamp21_multi_strip.tiff)
+ images/ojpeg_chewey_subsamp21_multi_strip.tiff
+ images/ojpeg_single_strip_no_rowsperstrip.tiff)
set(BMPIMAGES
images/palette-1c-8b.bmp
diff --git a/test/Makefile.am b/test/Makefile.am
index 420d7523..e7d239bd 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -57,7 +57,8 @@ JPEG_DEPENDENT_CHECK_PROG=raw_decode
JPEG_DEPENDENT_TESTSCRIPTS=\
tiff2rgba-quad-tile.jpg.sh \
tiff2rgba-ojpeg_zackthecat_subsamp22_single_strip.sh \
- tiff2rgba-ojpeg_chewey_subsamp21_multi_strip.sh
+ tiff2rgba-ojpeg_chewey_subsamp21_multi_strip.sh \
+ tiff2rgba-ojpeg_single_strip_no_rowsperstrip.sh
else
JPEG_DEPENDENT_CHECK_PROG=
@@ -176,7 +177,8 @@ TIFFIMAGES = \
images/quad-lzw-compat.tiff \
images/lzw-single-strip.tiff \
images/ojpeg_zackthecat_subsamp22_single_strip.tiff \
- images/ojpeg_chewey_subsamp21_multi_strip.tiff
+ images/ojpeg_chewey_subsamp21_multi_strip.tiff \
+ images/ojpeg_single_strip_no_rowsperstrip.tiff
PNMIMAGES = \
images/minisblack-1c-8b.pgm \
diff --git a/test/images/ojpeg_single_strip_no_rowsperstrip.tiff b/test/images/ojpeg_single_strip_no_rowsperstrip.tiff
new file mode 100644
index 00000000..61611b9d
--- /dev/null
+++ b/test/images/ojpeg_single_strip_no_rowsperstrip.tiff
Binary files differ
diff --git a/test/tiff2rgba-ojpeg_single_strip_no_rowsperstrip.sh b/test/tiff2rgba-ojpeg_single_strip_no_rowsperstrip.sh
new file mode 100755
index 00000000..d69c99dc
--- /dev/null
+++ b/test/tiff2rgba-ojpeg_single_strip_no_rowsperstrip.sh
@@ -0,0 +1,7 @@
+#!/bin/sh
+# Generated file, master is Makefile.am
+. ${srcdir:-.}/common.sh
+infile="$srcdir/images/ojpeg_single_strip_no_rowsperstrip.tiff"
+outfile="o-tiff2rgba-ojpeg_single_strip_no_rowsperstrip.tiff"
+f_test_convert "$TIFF2RGBA" $infile $outfile
+f_tiffinfo_validate $outfile
diff --git a/tools/raw2tiff.c b/tools/raw2tiff.c
index ab36ff4e..f00142cf 100644
--- a/tools/raw2tiff.c
+++ b/tools/raw2tiff.c
@@ -372,7 +372,7 @@ guessSize(int fd, TIFFDataType dtype, _TIFF_off_t hdr_size, uint32 nbands,
_TIFF_stat_s filestat;
uint32 w, h, scanlinesize, imagesize;
uint32 depth = TIFFDataWidth(dtype);
- float cor_coef = 0, tmp;
+ double cor_coef = 0, tmp;
if (_TIFF_fstat_f(fd, &filestat) == -1) {
fprintf(stderr, "Failed to obtain file size.\n");
@@ -419,22 +419,28 @@ guessSize(int fd, TIFFDataType dtype, _TIFF_off_t hdr_size, uint32 nbands,
w++) {
if (imagesize % w == 0) {
scanlinesize = w * depth;
+ h = imagesize / w;
+ if (h < 2)
+ continue;
+ /* reads 2 lines at the middle of the image and calculate their correlation.
+ * it works for h >= 2. (in this case it will compare line 0 and line 1 */
buf1 = _TIFFmalloc(scanlinesize);
buf2 = _TIFFmalloc(scanlinesize);
- h = imagesize / w;
do {
- if (_TIFF_lseek_f(fd, hdr_size + (int)(h/2)*scanlinesize,
+ if (_TIFF_lseek_f(fd, hdr_size + (int)((h - 1)/2)*scanlinesize,
SEEK_SET) == (_TIFF_off_t)-1) {
fprintf(stderr, "seek error.\n");
fail=1;
break;
}
+ /* read line (h-1)/2 */
if (read(fd, buf1, scanlinesize) !=
(long) scanlinesize) {
fprintf(stderr, "read error.\n");
fail=1;
break;
}
+ /* read line ((h-1)/2)+1 */
if (read(fd, buf2, scanlinesize) !=
(long) scanlinesize) {
fprintf(stderr, "read error.\n");
@@ -445,11 +451,15 @@ guessSize(int fd, TIFFDataType dtype, _TIFF_off_t hdr_size, uint32 nbands,
swapBytesInScanline(buf1, w, dtype);
swapBytesInScanline(buf2, w, dtype);
}
- tmp = (float) fabs(correlation(buf1, buf2,
- w, dtype));
- if (tmp > cor_coef) {
- cor_coef = tmp;
+ if (0 == memcmp(buf1, buf2, scanlinesize)) {
*width = w, *length = h;
+ } else {
+ tmp = fabs(correlation(buf1, buf2,
+ w, dtype));
+ if (tmp > cor_coef) {
+ cor_coef = tmp;
+ *width = w, *length = h;
+ }
}
} while (0);
@@ -564,6 +574,7 @@ correlation(void *buf1, void *buf2, uint32 n_elem, TIFFDataType dtype)
M2 /= n_elem;
D1 -= M1 * M1 * n_elem;
D2 -= M2 * M2 * n_elem;
+ if (D1 * D2 == 0.0) return 0.0; /* avoid divide by zero */
K = (K - M1 * M2 * n_elem) / sqrt(D1 * D2);
return K;
diff --git a/tools/tiff2pdf.c b/tools/tiff2pdf.c
index 779c1662..bca54d53 100644
--- a/tools/tiff2pdf.c
+++ b/tools/tiff2pdf.c
@@ -3731,6 +3731,11 @@ tsize_t t2p_sample_realize_palette(T2P* t2p, unsigned char* buffer){
for(i=sample_count;i>0;i--){
palette_offset=buffer[i-1] * component_count;
sample_offset= (i-1) * component_count;
+ if(palette_offset + component_count > t2p->pdf_palettesize){
+ TIFFError(TIFF2PDF_MODULE,
+ "Error: palette_offset + component_count > t2p->pdf_palettesize");
+ return 1;
+ }
for(j=0;j<component_count;j++){
buffer[sample_offset+j]=t2p->pdf_palette[palette_offset+j];
}
diff --git a/tools/tiff2ps.c b/tools/tiff2ps.c
index 5874aba6..31a318a8 100644
--- a/tools/tiff2ps.c
+++ b/tools/tiff2ps.c
@@ -2467,8 +2467,10 @@ PSDataColorContig(FILE* fd, TIFF* tif, uint32 w, uint32 h, int nc)
}
if (alpha) {
int adjust;
- cc = 0;
- for (; (cc + nc) <= tf_bytesperrow; cc += samplesperpixel) {
+ /*
+ * the code inside this loop reads nc bytes + 1 extra byte (for adjust)
+ */
+ for (cc = 0; (cc + nc) < tf_bytesperrow; cc += samplesperpixel) {
DOBREAK(breaklen, nc, fd);
/*
* For images with alpha, matte against
@@ -2486,8 +2488,10 @@ PSDataColorContig(FILE* fd, TIFF* tif, uint32 w, uint32 h, int nc)
cp += es;
}
} else {
- cc = 0;
- for (; (cc + nc) <= tf_bytesperrow; cc += samplesperpixel) {
+ /*
+ * the code inside this loop reads nc bytes per iteration
+ */
+ for (cc = 0; (cc + nc) <= tf_bytesperrow; cc += samplesperpixel) {
DOBREAK(breaklen, nc, fd);
switch (nc) {
case 4: c = *cp++; PUTHEX(c,fd);
diff --git a/tools/tiffcrop.c b/tools/tiffcrop.c
index 29c19a2f..6cc5a2ce 100644
--- a/tools/tiffcrop.c
+++ b/tools/tiffcrop.c
@@ -4024,9 +4024,9 @@ combineSeparateSamples24bits (uint8 *in[], uint8 *out, uint32 cols,
{
src = in[s] + src_offset + src_byte;
if (little_endian)
- buff1 = (src[0] << 24) | (src[1] << 16) | (src[2] << 8) | src[3];
+ buff1 = ((uint32)src[0] << 24) | ((uint32)src[1] << 16) | ((uint32)src[2] << 8) | (uint32)src[3];
else
- buff1 = (src[3] << 24) | (src[2] << 16) | (src[1] << 8) | src[0];
+ buff1 = ((uint32)src[3] << 24) | ((uint32)src[2] << 16) | ((uint32)src[1] << 8) | (uint32)src[0];
buff1 = (buff1 & matchbits) << (src_bit);
/* If we have a full buffer's worth, write it out */
diff --git a/tools/tiffset.c b/tools/tiffset.c
index 7ecc401b..fdfdf3cc 100644
--- a/tools/tiffset.c
+++ b/tools/tiffset.c
@@ -35,6 +35,10 @@
#include "tiffio.h"
+#ifdef NEED_LIBPORT
+# include "libport.h"
+#endif
+
static char* usageMsg[] = {
"usage: tiffset [options] filename",
"where options are:",