Index: tiff-3.8.2/libtiff/tif_getimage.c
===================================================================
--- tiff-3.8.2.orig/libtiff/tif_getimage.c
+++ tiff-3.8.2/libtiff/tif_getimage.c
@@ -849,12 +849,21 @@ gtStripContig(TIFFRGBAImage* img, uint32
     fromskew = (w < imagewidth ? imagewidth - w : 0);
     for (row = 0; row < h; row += nrow) 
     {
+        uint32 temp;
         rowstoread = rowsperstrip - (row + img->row_offset) % rowsperstrip;
         nrow = (row + rowstoread > h ? h - row : rowstoread);
+
+	temp = (row + img->row_offset)%rowsperstrip + nrow;
+	if( scanline > 0 && temp > (size_t)(TIFF_TMSIZE_T_MAX / scanline) )
+	{
+		TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "Integer overflow in gtStripContig");
+		return 0;
+	}
+
         if (TIFFReadEncodedStrip(tif,
                                  TIFFComputeStrip(tif,row+img->row_offset, 0),
                                  buf, 
-                                 ((row + img->row_offset)%rowsperstrip + nrow) * scanline) < 0
+				 temp * scanline)==(tmsize_t)(-1)
             && img->stoponerr)
         {
             ret = 0;
@@ -943,25 +952,35 @@ gtStripSeparate(TIFFRGBAImage* img, uint
     fromskew = (w < imagewidth ? imagewidth - w : 0);
     for (row = 0; row < h; row += nrow) 
     {
+        uint32 temp;
         rowstoread = rowsperstrip - (row + img->row_offset) % rowsperstrip;    	
         nrow = (row + rowstoread > h ? h - row : rowstoread);
         offset_row = row + img->row_offset;
+
+	temp = (row + img->row_offset)%rowsperstrip + nrow;
+	if( scanline > 0 && temp > (size_t)(TIFF_TMSIZE_T_MAX / scanline) )
+	{
+		TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "Integer overflow in gtStripSeparate");
+		return 0;
+	}
+
+
     	if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, offset_row, 0),
-                                 r, ((row + img->row_offset)%rowsperstrip + nrow) * scanline) < 0 
+                                 r, temp * scanline) == (tmsize_t)(-1)
             && img->stoponerr)
         {
             ret = 0;
             break;
         }
         if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, offset_row, 1),
-                                 g, ((row + img->row_offset)%rowsperstrip + nrow) * scanline) < 0 
+                                 g, temp * scanline) == (tmsize_t)(-1)
             && img->stoponerr)
         {
             ret = 0;
             break;
         }
         if (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, offset_row, 2),
-                                 b, ((row + img->row_offset)%rowsperstrip + nrow) * scanline) < 0 
+                                 b, temp * scanline) == (tmsize_t)(-1)
             && img->stoponerr)
         {
             ret = 0;
@@ -969,7 +988,7 @@ gtStripSeparate(TIFFRGBAImage* img, uint
         }
         if (alpha &&
             (TIFFReadEncodedStrip(tif, TIFFComputeStrip(tif, offset_row, 3),
-                                  a, ((row + img->row_offset)%rowsperstrip + nrow) * scanline) < 0 
+                                  a, temp * scanline) == (tmsize_t)(-1)
              && img->stoponerr))
         {
             ret = 0;
Index: tiff-3.8.2/libtiff/tiffio.h
===================================================================
--- tiff-3.8.2.orig/libtiff/tiffio.h
+++ tiff-3.8.2/libtiff/tiffio.h
@@ -32,6 +32,7 @@
  */
 #include "tiff.h"
 #include "tiffvers.h"
+#include "tif_config.h"
 
 /*
  * TIFF is defined as an incomplete type to hide the
@@ -58,6 +59,13 @@ typedef	struct tiff TIFF;
  *     32-bit file offsets being the most important, and to ensure
  *     that it is unsigned, rather than signed.
  */
+
+/*
+ * this is the machine addressing size type, only it's signed, so make it
+ * int32 on 32bit machines, int64 on 64bit machines
+ */
+typedef TIFF_SSIZE_T tmsize_t;
+
 typedef	uint32 ttag_t;		/* directory tag */
 typedef	uint16 tdir_t;		/* directory index */
 typedef	uint16 tsample_t;	/* sample number */
Index: tiff-3.8.2/configure.ac
===================================================================
--- tiff-3.8.2.orig/configure.ac
+++ tiff-3.8.2/configure.ac
@@ -113,6 +113,36 @@ AC_CHECK_TYPES([int8, int16, int32],,,
 #endif
 ])
 
+# Determine TIFF equivalent of ssize_t
+AC_MSG_CHECKING(for signed size type)
+SSIZE_T='unknown'
+SSIZE_FORMAT='unknown'
+if test $ac_cv_sizeof_signed_int -eq $ac_cv_sizeof_size_t
+then
+  SSIZE_T='signed int'
+  SSIZE_FORMAT='"%d"'
+elif test $ac_cv_sizeof_signed_long -eq $ac_cv_sizeof_size_t
+then
+  SSIZE_T='signed long'
+  SSIZE_FORMAT='"%ld"'
+elif test $ac_cv_sizeof_signed_long_long -eq $ac_cv_sizeof_size_t
+then
+  SSIZE_T='signed long long'
+  case "${host_os}" in
+    mingw32*)
+      # MinGW32 understands 'long long', but uses printf from WIN32 CRT
+      SSIZE_FORMAT='"%I64d"'
+      ;;
+    *)
+      SSIZE_FORMAT='"%lld"'
+      ;;
+  esac
+fi
+AC_MSG_RESULT($SSIZE_T)
+AC_DEFINE_UNQUOTED(TIFF_SSIZE_T,$SSIZE_T,[Signed size type])
+AC_DEFINE_UNQUOTED(TIFF_SSIZE_FORMAT,$SSIZE_FORMAT,[Signed size type formatter])
+
+
 dnl Checks for library functions.
 AC_CHECK_FUNCS([floor isascii memmove memset mmap pow sqrt strchr strrchr strstr strtol])
 
Index: tiff-3.8.2/libtiff/tiffiop.h
===================================================================
--- tiff-3.8.2.orig/libtiff/tiffiop.h
+++ tiff-3.8.2/libtiff/tiffiop.h
@@ -71,6 +71,9 @@ extern void *lfind(const void *, const v
 #define	FALSE	0
 #endif
 
+#define TIFF_SIZE_T_MAX ((size_t) ~ ((size_t)0))
+#define TIFF_TMSIZE_T_MAX (tmsize_t)(TIFF_SIZE_T_MAX >> 1)
+
 typedef struct client_info {
     struct client_info *next;
     void      *data;
Index: tiff-3.8.2/tools/tiff2pdf.c
===================================================================
--- tiff-3.8.2.orig/tools/tiff2pdf.c
+++ tiff-3.8.2/tools/tiff2pdf.c
@@ -69,7 +69,6 @@ extern int getopt(int, char**, char*);
 
 #define PS_UNIT_SIZE	72.0F
 
-typedef tsize_t tmsize_t;
 typedef toff_t uint64;
 #define _TIFF_fseek_f(stream,offset,whence) fseek(stream,offset,whence)
 #define _TIFF_off_t off_t
Index: tiff-3.8.2/tools/tiff2rgba.c
===================================================================
--- tiff-3.8.2.orig/tools/tiff2rgba.c
+++ tiff-3.8.2/tools/tiff2rgba.c
@@ -53,7 +53,6 @@ int     no_alpha = 0;
 #define DEFAULT_MAX_MALLOC (256 * 1024 * 1024)
 /* malloc size limit (in bytes)
  * disabled when set to 0 */
-typedef tsize_t tmsize_t;
 static tmsize_t maxMalloc = DEFAULT_MAX_MALLOC;
 
 
