2020-01-17  Juan Manuel Guerrero  <juan.guerrero@gmx.de>

	* contrib/iptcutil/iptcutil.c [_O_BINARY]:  Define _O_BINARY as O_BINARY,
	_fileno as _fileno and _setmode as setmode.
	[__DJGPP__]:  Include <sys/exceptn.h> for __djgpp_set_ctrl_c declaration
	and <unistd.h> for isatty declaration.
	Define SET_BINARY macro.  For POSIX like OS this is a no-op.  For Win32
	it calls setmode.
	(main):  For DJGPP, call SET_BINARY to reenable SIGINT and SIGQUIT
	signals if stdin and/or stdout is connected to console and has been
	switched to binary mode.

	* libtiff/tiffiop.h [HAVE_SEARCH_H]:  New guard HAVE_LFIND added.
	Do not assume that <search.h> provides lfind().

	* libtiff/tif_jpeg.c (JPEGCleanup, JPEGPrintDir):  Assertion did not
	hold true, resulting in the client application calling abort().

	* tools/fax2ps.c [_O_BINARY]:  Define _O_BINARY as O_BINARY, _fileno as
	_fileno and _setmode as setmode.
	[__DJGPP__]:  Define SET_BINARY to have interruptible terminal reads
	and writes; include <unistd.h> for isatty declaration and
	<sys/exceptn.h> for __djgpp_set_ctrl_c declaration.  For POSIX like OS
	this is a no-op.  For Win32 it calls setmode.
	(main):  Use SET_BINARY instead of setmode() to reenable SIGINT and
	SIGQUIT if stdin and/or stdout is connected to console and has been
	switched to binary mode.

	* tools/ppm2tiff.c [_O_BINARY]:  Define _O_BINARY as O_BINARY, _fileno as
	_fileno and _setmode as setmode.
	[__DJGPP__]: Define SET_BINARY to have interruptible terminale reads
	and writes; include <unistd.h> for isatty declaration and
	<sys/exceptn.h> for __djgpp_set_ctrl_c declaration.  For POSIX like OS
	this is a no-op.  For Win32 it calls setmode.
	(main):  Use SET_BINARY instead of setmode() to reenable SIGINT and
	SIGQUIT if stdin and/or stdout is connected to console and has been
	switched to binary mode.





diff -aprNU5 tiff-4.1.0.orig/contrib/iptcutil/iptcutil.c tiff-4.1.0/contrib/iptcutil/iptcutil.c
--- tiff-4.1.0.orig/contrib/iptcutil/iptcutil.c	2018-04-23 03:43:22 +0000
+++ tiff-4.1.0/contrib/iptcutil/iptcutil.c	2020-01-17 21:32:34 +0000
@@ -9,10 +9,50 @@
 # include <strings.h>
 #endif
 
 #ifdef HAVE_IO_H
 # include <io.h>
+# ifdef _O_BINARY
+#  define _O_BINARY       O_BINARY
+#  define _fileno(f)      fileno(f)
+#  define _setmode(f, m)  setmode(f, m)
+# endif /* __O_BINARY */
+
+# ifdef __DJGPP__
+#  if defined (__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
+#    define __gnuc_extension__  __extension__
+#  else
+#    define __gnuc_extension__
+#  endif
+
+#  include <unistd.h>       /* to declare isatty() */
+#  include <sys/exceptn.h>  /* to declare __djgpp_set_ctrl_c() */
+   /* This is DJGPP-specific.  By default, switching console
+      to binary mode disables SIGINT and SIGQUIT.  But it
+      is preferable to have terminal reads and writes to
+      be interruptible.  */
+#  define SET_BINARY(f)                                          \
+   (__gnuc_extension__                                           \
+     ({                                                          \
+        int file_descriptor = fileno(f);                         \
+        int previous_mode = setmode(file_descriptor, O_BINARY);  \
+        if (isatty(file_descriptor))                             \
+          __djgpp_set_ctrl_c(1);                                 \
+        previous_mode;                                           \
+     })                                                          \
+   )
+# endif /* __DJGPP__ */
+# ifdef WIN32
+#  define SET_BINARY(f)   (setmode(fileno(f), O_BINARY))
+# endif
+# ifdef __CYGWIN__
+#  define SET_BINARY(f)   /* */
+# endif
+#endif
+
+#ifndef SET_BINARY
+# define SET_BINARY(f)   /* */
 #endif
 
 #ifdef HAVE_FCNTL_H
 # include <fcntl.h>
 #endif
@@ -412,21 +452,17 @@ int main(int argc, char *argv[])
           c = argv[i][1];
           switch( c )
             {
             case 't':
               mode = 1;
-#ifdef WIN32
               /* Set "stdout" to binary mode: */
-              _setmode( _fileno( ofile ), _O_BINARY );
-#endif
+              SET_BINARY(ofile);
               break;
             case 'b':
               mode = 0;
-#ifdef WIN32
               /* Set "stdin" to binary mode: */
-              _setmode( _fileno( ifile ), _O_BINARY );
-#endif
+              SET_BINARY(ifile);
               break;
             case 'i':
               if (mode == 0)
                 ifile = fopen(argv[++i], "rb");
               else
diff -aprNU5 tiff-4.1.0.orig/libtiff/tiffiop.h tiff-4.1.0/libtiff/tiffiop.h
--- tiff-4.1.0.orig/libtiff/tiffiop.h	2019-08-17 02:51:58 +0000
+++ tiff-4.1.0/libtiff/tiffiop.h	2020-01-17 21:32:34 +0000
@@ -46,11 +46,11 @@
 # include <assert.h>
 #else
 # define assert(x) 
 #endif
 
-#ifdef HAVE_SEARCH_H
+#if defined HAVE_SEARCH_H && defined HAVE_LFIND
 # include <search.h>
 #else
 extern void *lfind(const void *, const void *, size_t *, size_t,
 		   int (*)(const void *, const void *));
 #endif
diff -aprNU5 tiff-4.1.0.orig/libtiff/tif_jpeg.c tiff-4.1.0/libtiff/tif_jpeg.c
--- tiff-4.1.0.orig/libtiff/tif_jpeg.c	2019-10-21 03:46:40 +0000
+++ tiff-4.1.0/libtiff/tif_jpeg.c	2020-01-17 21:32:34 +0000
@@ -2227,11 +2227,11 @@ JPEGPostEncode(TIFF* tif)
 static void
 JPEGCleanup(TIFF* tif)
 {
 	JPEGState *sp = JState(tif);
 	
-	assert(sp != 0);
+	/* assert(sp != 0); */
 
 	tif->tif_tagmethods.vgetfield = sp->vgetparent;
 	tif->tif_tagmethods.vsetfield = sp->vsetparent;
 	tif->tif_tagmethods.printdir = sp->printdir;
         if( sp->cinfo_initialized )
@@ -2364,11 +2364,15 @@ JPEGVGetField(TIFF* tif, uint32 tag, va_
 static void
 JPEGPrintDir(TIFF* tif, FILE* fd, long flags)
 {
 	JPEGState* sp = JState(tif);
 
-	assert(sp != NULL);
+	/* assert(sp != NULL); */
+	if (sp == NULL) {
+		TIFFWarningExt(tif->tif_clientdata, "JPEGPrintDir", "Unknown JPEGState");
+		return;
+	}
 	(void) flags;
 
         if( sp != NULL ) {
 		if (TIFFFieldSet(tif,FIELD_JPEGTABLES))
 			fprintf(fd, "  JPEG Tables: (%lu bytes)\n",
diff -aprNU5 tiff-4.1.0.orig/tools/fax2ps.c tiff-4.1.0/tools/fax2ps.c
--- tiff-4.1.0.orig/tools/fax2ps.c	2017-11-20 05:14:38 +0000
+++ tiff-4.1.0/tools/fax2ps.c	2020-01-17 21:32:34 +0000
@@ -37,10 +37,50 @@
 # include <fcntl.h>
 #endif
 
 #ifdef HAVE_IO_H
 # include <io.h>
+# ifdef _O_BINARY
+#  define _O_BINARY       O_BINARY
+#  define _fileno(f)      fileno(f)
+#  define _setmode(f, m)  setmode(f, m)
+# endif /* __O_BINARY */
+
+# ifdef __DJGPP__
+#  if defined (__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
+#    define __gnuc_extension__  __extension__
+#  else
+#    define __gnuc_extension__
+#  endif
+
+#  include <unistd.h>       /* to declare isatty() */
+#  include <sys/exceptn.h>  /* to declare __djgpp_set_ctrl_c() */
+   /* This is DJGPP-specific.  By default, switching console
+      to binary mode disables SIGINT and SIGQUIT.  But it
+      is preferable to have terminal reads and writes to
+      be interruptible.  */
+#  define SET_BINARY(f)                                          \
+   (__gnuc_extension__                                           \
+     ({                                                          \
+        int file_descriptor = fileno(f);                         \
+        int previous_mode = setmode(file_descriptor, O_BINARY);  \
+        if (isatty(file_descriptor))                             \
+          __djgpp_set_ctrl_c(1);                                 \
+        previous_mode;                                           \
+     })                                                          \
+   )
+# endif /* __DJGPP__ */
+# ifdef WIN32
+#  define SET_BINARY(f)   (setmode(fileno(f), O_BINARY))
+# endif
+# ifdef __CYGWIN__
+#  define SET_BINARY(f)   /* */
+# endif
+#endif
+
+#ifndef SET_BINARY
+# define SET_BINARY(f)   /* */
 #endif
 
 #ifdef NEED_LIBPORT
 # include "libport.h"
 #endif
@@ -391,13 +431,11 @@ main(int argc, char** argv)
 	fd = tmpfile();
 	if (fd == NULL) {
 	    fprintf(stderr, "Could not obtain temporary file.\n");
 	    exit(-2);
 	}
-#if defined(HAVE_SETMODE) && defined(O_BINARY)
-	setmode(fileno(stdin), O_BINARY);
-#endif
+	SET_BINARY(stdin);
 	while ((n = read(fileno(stdin), buf, sizeof (buf))) > 0) {
                 if (write(fileno(fd), buf, n) != n) {
                         fclose(fd);
                         fprintf(stderr,
                                 "Could not copy stdin to temporary file.\n");
diff -aprNU5 tiff-4.1.0.orig/tools/ppm2tiff.c tiff-4.1.0/tools/ppm2tiff.c
--- tiff-4.1.0.orig/tools/ppm2tiff.c	2019-10-22 07:06:32 +0000
+++ tiff-4.1.0/tools/ppm2tiff.c	2020-01-17 21:32:34 +0000
@@ -37,10 +37,50 @@
 # include <fcntl.h>
 #endif
 
 #ifdef HAVE_IO_H
 # include <io.h>
+# ifdef _O_BINARY
+#  define _O_BINARY       O_BINARY
+#  define _fileno(f)      fileno(f)
+#  define _setmode(f, m)  setmode(f, m)
+# endif /* __O_BINARY */
+
+# ifdef __DJGPP__
+#  if defined (__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
+#    define __gnuc_extension__  __extension__
+#  else
+#    define __gnuc_extension__
+#  endif
+
+#  include <unistd.h>       /* to declare isatty() */
+#  include <sys/exceptn.h>  /* to declare __djgpp_set_ctrl_c() */
+   /* This is DJGPP-specific.  By default, switching console
+      to binary mode disables SIGINT and SIGQUIT.  But it
+      is preferable to have terminal reads and writes to
+      be interruptible.  */
+#  define SET_BINARY(f)                                          \
+   (__gnuc_extension__                                           \
+     ({                                                          \
+        int file_descriptor = fileno(f);                         \
+        int previous_mode = setmode(file_descriptor, O_BINARY);  \
+        if (isatty(file_descriptor))                             \
+          __djgpp_set_ctrl_c(1);                                 \
+        previous_mode;                                           \
+     })                                                          \
+   )
+# endif /* __DJGPP__ */
+# ifdef WIN32
+#  define SET_BINARY(f)   (setmode(fileno(f), O_BINARY))
+# endif
+# ifdef __CYGWIN__
+#  define SET_BINARY(f)   /* */
+# endif
+#endif
+
+#ifndef SET_BINARY
+# define SET_BINARY(f)   /* */
 #endif
 
 #ifdef NEED_LIBPORT
 # include "libport.h"
 #endif
@@ -141,13 +181,11 @@ main(int argc, char* argv[])
 			return (-1);
 		}
 	} else {
 		infile = "<stdin>";
 		in = stdin;
-#if defined(HAVE_SETMODE) && defined(O_BINARY)
-		setmode(fileno(stdin), O_BINARY);
-#endif
+		SET_BINARY(stdin);
 	}
 
 	if (fgetc(in) != 'P')
 		BadPPM(infile);
 	switch (fgetc(in)) {




2020-01-17  Juan Manuel Guerrero  <juan.guerrero@gmx.de>

	Applied all patches taken from tiff_4.1.0+git191117-2.debian.tar.xz available at
	http://ftp.de.debian.org/debian/pool/main/t/tiff/.
	See the ChangeLog file for changes.








diff -aprNU5 tiff-4.1.0.orig/html/man/RdRawStrip_3tiff.html tiff-4.1.0/html/man/RdRawStrip_3tiff.html
--- tiff-4.1.0.orig/html/man/RdRawStrip_3tiff.html	2017-11-20 05:14:32 +0000
+++ tiff-4.1.0/html/man/RdRawStrip_3tiff.html	2020-01-17 22:32:58 +0000
@@ -69,11 +69,11 @@ typically be at least as large as the nu
        cols="2" cellspacing="0" cellpadding="0">
 <tr valign="top" align="left">
 <td width="8%"></td>
 <td width="91%">
 <p>The actual number of bytes of data that were placed in
-<i>buf</i> is returned; <i>TIFFReadEncodedStrip</i> returns
+<i>buf</i> is returned; <i>TIFFReadRawStrip</i> returns
 &minus;1 if an error was encountered.</p>
 </td>
 </table>
 <a name="DIAGNOSTICS"></a>
 <h2>DIAGNOSTICS</h2>
diff -aprNU5 tiff-4.1.0.orig/libtiff/tif_ojpeg.c tiff-4.1.0/libtiff/tif_ojpeg.c
--- tiff-4.1.0.orig/libtiff/tif_ojpeg.c	2019-09-17 03:51:16 +0000
+++ tiff-4.1.0/libtiff/tif_ojpeg.c	2020-01-17 22:39:30 +0000
@@ -1092,10 +1092,12 @@ OJPEGReadHeaderInfo(TIFF* tif)
 	}
 	else
 	{
 		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)
 	{
 		sp->samples_per_pixel=1;
diff -aprNU5 tiff-4.1.0.orig/man/RdRawStrip.3tiff tiff-4.1.0/man/RdRawStrip.3tiff
--- tiff-4.1.0.orig/man/RdRawStrip.3tiff	2017-11-20 05:14:36 +0000
+++ tiff-4.1.0/man/RdRawStrip.3tiff	2020-01-17 22:32:58 +0000
@@ -44,11 +44,11 @@ large as the number returned by
 .IR TIFFStripSize .
 .SH "RETURN VALUES"
 The actual number of bytes of data that were placed in
 .I buf
 is returned;
-.IR TIFFReadEncodedStrip
+.IR TIFFReadRawStrip
 returns \-1 if an error was encountered.
 .SH DIAGNOSTICS
 All error messages are directed to the
 .BR TIFFError (3TIFF)
 routine.
