2023-09-12  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/tif_jpeg.c (JPEGCleanup, JPEGPrintDir):  Assertion did not
	hold true, resulting in the client application calling abort().







diff -aprNU5 tiff-4.6.0.orig/contrib/iptcutil/iptcutil.c tiff-4.6.0/contrib/iptcutil/iptcutil.c
--- tiff-4.6.0.orig/contrib/iptcutil/iptcutil.c	2023-05-22 13:49:02 +0000
+++ tiff-4.6.0/contrib/iptcutil/iptcutil.c	2023-09-12 20:24:40 +0000
@@ -9,10 +9,59 @@
 #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() */
+#if 0
+#  include <sys/exceptn.h>  /* declares __djgpp_set_ctrl_c() */
+#  include <go32.h>         /* declares _go32_want_ctrl_break() */
+#endif
+   /* 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))                             \
+          setmode(file_descriptor, O_TEXT);                      \
+/*                                                               \
+        {                                                        \
+          __djgpp_set_ctrl_c(1);                                 \
+          _go32_want_ctrl_break(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
@@ -384,21 +433,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.6.0.orig/libtiff/tif_jpeg.c tiff-4.6.0/libtiff/tif_jpeg.c
--- tiff-4.6.0.orig/libtiff/tif_jpeg.c	2023-05-22 13:49:02 +0000
+++ tiff-4.6.0/libtiff/tif_jpeg.c	2023-09-11 21:08:44 +0000
@@ -2517,11 +2517,11 @@ static int JPEGPostEncode(TIFF *tif)
 
 static void JPEGCleanup(TIFF *tif)
 {
     JPEGState *sp = JState(tif);
 
-    assert(sp != 0);
+    /* assert(sp != 0); */
 
     tif->tif_tagmethods.vgetfield = sp->otherSettings.vgetparent;
     tif->tif_tagmethods.vsetfield = sp->otherSettings.vsetparent;
     tif->tif_tagmethods.printdir = sp->otherSettings.printdir;
     if (sp->cinfo_initialized)
@@ -2661,11 +2661,16 @@ static int JPEGVGetField(TIFF *tif, uint
 
 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))




2023-09-12  Juan Manuel Guerrero  <juan.guerrero@gmx.de>

	Applied all patches taken from tiff_4.4.0-6.debian.tar.xz available at
	https://packages.debian.org/unstable/libs/libtiff5/.
	See the ChangeLog file for changes.










diff -aprNU5 tiff-4.6.0.orig/libtiff/tif_lzw.c tiff-4.6.0/libtiff/tif_lzw.c
--- tiff-4.6.0.orig/libtiff/tif_lzw.c	2023-05-22 14:03:40 +0000
+++ tiff-4.6.0/libtiff/tif_lzw.c	2023-09-12 20:41:50 +0000
@@ -345,12 +345,21 @@ static int LZWPreDecode(TIFF *tif, uint1
                (((uint64_t)bp[4]) << 24) | (((uint64_t)bp[5]) << 16) |         \
                (((uint64_t)bp[6]) << 8) | (((uint64_t)bp[7]))
 #endif
 #elif SIZEOF_WORDTYPE == 4
 #if defined(__GNUC__) && defined(__i386__)
+#if defined(__DJGPP__) && (__GNUC__ - 3) == 0 && (__GNUC_MINOR__ - 4) == 0
+/* gcc 3.4.6 seems not to provide __builtin_bswap32.  */
+#define __bswap_constant_32(x)                                                 \
+  ((((x) & 0xff000000u) >> 24) | (((x) & 0x00ff0000u) >> 8)                    \
+   | (((x) & 0x0000ff00u) << 8) | (((x) & 0x000000ffu) << 24))
+#define GetNextData(nextdata, bp)                                              \
+    nextdata = __bswap_constant_32(*(uint32_t *)(bp))
+#else
 #define GetNextData(nextdata, bp)                                              \
     nextdata = __builtin_bswap32(*(uint32_t *)(bp))
+#endif
 #elif defined(_M_X86)
 #define GetNextData(nextdata, bp)                                              \
     nextdata = _byteswap_ulong(*(unsigned long *)(bp))
 #elif defined(__GNUC__)
 #define GetNextData(nextdata, bp)                                              \




2022-12-25  Juan Manuel Guerrero  <juan.guerrero@gmx.de>

	Applied all patches taken from tiff_4.5.0-1.debian.tar.xz available at
	https://ftp.de.debian.org/debian/pool/main/t/tiff/.
	See the ChangeLog file for changes.









