https://github.com/libsdl-org/libtiff/commit/5eb5ed11bfa1f41101aa485228df7a8b6406bc94
From 5eb5ed11bfa1f41101aa485228df7a8b6406bc94 Mon Sep 17 00:00:00 2001
From: Bob Friesenhahn <[EMAIL REDACTED]>
Date: Thu, 10 Jun 2010 22:52:45 +0000
Subject: [PATCH] * libtiff/tiffiop.h (TIFFSafeMultiply): Work properly if
multiplier is zero.
---
ChangeLog | 5 +++
build/Makefile.in | 2 +-
contrib/dbs/xtiff/Makefile.in | 2 +-
html/Makefile.in | 2 +-
libtiff/tiffiop.h | 4 +-
m4/argz.m4 | 79 -----------------------------------
test/short_tag.c | 3 +-
tools/tiffcp.c | 22 +++++++++-
8 files changed, 32 insertions(+), 87 deletions(-)
delete mode 100644 m4/argz.m4
diff --git a/ChangeLog b/ChangeLog
index 5342c7bf..c2982c95 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2010-06-10 Bob Friesenhahn <bfriesen@simple.dallas.tx.us>
+
+ * libtiff/tiffiop.h (TIFFSafeMultiply): Work properly if
+ multiplier is zero.
+
2010-06-09 Bob Friesenhahn <bfriesen@simple.dallas.tx.us>
* libtiff/tif_dir.h: Restore ReferenceBlackWhite as a non-custom
diff --git a/build/Makefile.in b/build/Makefile.in
index c235065b..dc89e5e5 100644
--- a/build/Makefile.in
+++ b/build/Makefile.in
@@ -15,7 +15,7 @@
@SET_MAKE@
-# $Id: Makefile.in,v 1.1.2.12 2010-06-08 23:29:50 bfriesen Exp $
+# $Id: Makefile.in,v 1.1.2.13 2010-06-10 22:52:45 bfriesen Exp $
#
# Tag Image File Format (TIFF) Software
#
diff --git a/contrib/dbs/xtiff/Makefile.in b/contrib/dbs/xtiff/Makefile.in
index 819f1509..72d3f9aa 100644
--- a/contrib/dbs/xtiff/Makefile.in
+++ b/contrib/dbs/xtiff/Makefile.in
@@ -15,7 +15,7 @@
@SET_MAKE@
-# $Id: Makefile.in,v 1.36.2.12 2010-06-08 23:29:50 bfriesen Exp $
+# $Id: Makefile.in,v 1.36.2.13 2010-06-10 22:52:45 bfriesen Exp $
#
# Tag Image File Format (TIFF) Software
#
diff --git a/html/Makefile.in b/html/Makefile.in
index 572dc878..4f63d946 100644
--- a/html/Makefile.in
+++ b/html/Makefile.in
@@ -15,7 +15,7 @@
@SET_MAKE@
-# $Id: Makefile.in,v 1.49.2.12 2010-06-08 23:29:50 bfriesen Exp $
+# $Id: Makefile.in,v 1.49.2.13 2010-06-10 22:52:45 bfriesen Exp $
#
# Tag Image File Format (TIFF) Software
#
diff --git a/libtiff/tiffiop.h b/libtiff/tiffiop.h
index fcffcca8..1883507b 100644
--- a/libtiff/tiffiop.h
+++ b/libtiff/tiffiop.h
@@ -1,4 +1,4 @@
-/* $Id: tiffiop.h,v 1.51.2.4 2010-06-09 17:16:58 bfriesen Exp $ */
+/* $Id: tiffiop.h,v 1.51.2.5 2010-06-10 22:52:45 bfriesen Exp $ */
/*
* Copyright (c) 1988-1997 Sam Leffler
@@ -243,7 +243,7 @@ struct tiff {
#define TIFFroundup(x, y) (TIFFhowmany(x,y)*(y))
/* Safe multiply which returns zero if there is an integer overflow */
-#define TIFFSafeMultiply(t,v,m) ((((t)v*m)/(t)m == (t)v) ? (t)v*m : (t)0)
+#define TIFFSafeMultiply(t,v,m) ((((t)m != (t)0) && (((t)v*m)/(t)m == (t)v)) ? (t)v*m : (t)0)
#define TIFFmax(A,B) ((A)>(B)?(A):(B))
#define TIFFmin(A,B) ((A)<(B)?(A):(B))
diff --git a/m4/argz.m4 b/m4/argz.m4
deleted file mode 100644
index 1f8d67d0..00000000
--- a/m4/argz.m4
+++ /dev/null
@@ -1,79 +0,0 @@
-# Portability macros for glibc argz. -*- Autoconf -*-
-#
-# Copyright (C) 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
-# Written by Gary V. Vaughan <gary@gnu.org>
-#
-# This file is free software; the Free Software Foundation gives
-# unlimited permission to copy and/or distribute it, with or without
-# modifications, as long as this notice is preserved.
-
-# serial 5 argz.m4
-
-AC_DEFUN([gl_FUNC_ARGZ],
-[gl_PREREQ_ARGZ
-
-AC_CHECK_HEADERS([argz.h], [], [], [AC_INCLUDES_DEFAULT])
-
-AC_CHECK_TYPES([error_t],
- [],
- [AC_DEFINE([error_t], [int],
- [Define to a type to use for `error_t' if it is not otherwise available.])
- AC_DEFINE([__error_t_defined], [1], [Define so that glibc/gnulib argp.h
- does not typedef error_t.])],
- [#if defined(HAVE_ARGZ_H)
-# include <argz.h>
-#endif])
-
-ARGZ_H=
-AC_CHECK_FUNCS([argz_append argz_create_sep argz_insert argz_next \
- argz_stringify], [], [ARGZ_H=argz.h; AC_LIBOBJ([argz])])
-
-dnl if have system argz functions, allow forced use of
-dnl libltdl-supplied implementation (and default to do so
-dnl on "known bad" systems). Could use a runtime check, but
-dnl (a) detecting malloc issues is notoriously unreliable
-dnl (b) only known system that declares argz functions,
-dnl provides them, yet they are broken, is cygwin
-dnl releases prior to 16-Mar-2007 (1.5.24 and earlier)
-dnl So, it's more straightforward simply to special case
-dnl this for known bad systems.
-AS_IF([test -z "$ARGZ_H"],
- [AC_CACHE_CHECK(
- [if argz actually works],
- [lt_cv_sys_argz_works],
- [[case $host_os in #(
- *cygwin*)
- lt_cv_sys_argz_works=no
- if test "$cross_compiling" != no; then
- lt_cv_sys_argz_works="guessing no"
- else
- lt_sed_extract_leading_digits='s/^\([0-9\.]*\).*/\1/'
- save_IFS=$IFS
- IFS=-.
- set x `uname -r | sed -e "$lt_sed_extract_leading_digits"`
- IFS=$save_IFS
- lt_os_major=${2-0}
- lt_os_minor=${3-0}
- lt_os_micro=${4-0}
- if test "$lt_os_major" -gt 1 \
- || { test "$lt_os_major" -eq 1 \
- && { test "$lt_os_minor" -gt 5 \
- || { test "$lt_os_minor" -eq 5 \
- && test "$lt_os_micro" -gt 24; }; }; }; then
- lt_cv_sys_argz_works=yes
- fi
- fi
- ;; #(
- *) lt_cv_sys_argz_works=yes ;;
- esac]])
- AS_IF([test $lt_cv_sys_argz_works = yes],
- [AC_DEFINE([HAVE_WORKING_ARGZ], 1,
- [This value is set to 1 to indicate that the system argz facility works])],
- [ARGZ_H=argz.h
- AC_LIBOBJ([argz])])])
-
-AC_SUBST([ARGZ_H])
-])
-
-# Prerequisites of lib/argz.c.
-AC_DEFUN([gl_PREREQ_ARGZ], [:])
diff --git a/test/short_tag.c b/test/short_tag.c
index 21bcb415..45214e1d 100644
--- a/test/short_tag.c
+++ b/test/short_tag.c
@@ -1,4 +1,4 @@
-/* $Id: short_tag.c,v 1.6.2.1 2010-06-08 18:50:43 bfriesen Exp $ */
+/* $Id: short_tag.c,v 1.6.2.2 2010-06-10 22:52:45 bfriesen Exp $ */
/*
* Copyright (c) 2004, Andrey Kiselev <dron@ak4719.spb.edu>
@@ -39,6 +39,7 @@
#include "tiffio.h"
+extern int CheckLongField(TIFF *, ttag_t, uint32);
extern int CheckShortField(TIFF *, ttag_t, uint16);
const char *filename = "short_test.tiff";
diff --git a/tools/tiffcp.c b/tools/tiffcp.c
index 5e58a6d0..f8230cbe 100644
--- a/tools/tiffcp.c
+++ b/tools/tiffcp.c
@@ -1,4 +1,4 @@
-/* $Id: tiffcp.c,v 1.37.2.5 2010-06-09 17:16:58 bfriesen Exp $ */
+/* $Id: tiffcp.c,v 1.37.2.6 2010-06-10 22:52:45 bfriesen Exp $ */
/*
* Copyright (c) 1988-1997 Sam Leffler
@@ -558,17 +558,34 @@ tiffcp(TIFF* in, TIFF* out)
copyFunc cf;
uint32 width, length;
struct cpTag* p;
+ uint16 input_compression, input_photometric;
CopyField(TIFFTAG_IMAGEWIDTH, width);
CopyField(TIFFTAG_IMAGELENGTH, length);
CopyField(TIFFTAG_BITSPERSAMPLE, bitspersample);
CopyField(TIFFTAG_SAMPLESPERPIXEL, samplesperpixel);
+
+ /*
+ For OJPEG we need to read the subsampled YCbCr data as upsampled
+ RGB. Since we don't write OJPEG format, automatically convert OJPEG
+ format to modern JPEG format.
+ */
+#if 1
+ if (TIFFGetField(in, TIFFTAG_COMPRESSION, &input_compression)
+ && input_compression == COMPRESSION_OJPEG) {
+ TIFFSetField(in, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB);
+
+ if (compression == (uint16)-1)
+ compression=COMPRESSION_JPEG;
+ }
+#endif
+
if (compression != (uint16)-1)
TIFFSetField(out, TIFFTAG_COMPRESSION, compression);
else
CopyField(TIFFTAG_COMPRESSION, compression);
+
if (compression == COMPRESSION_JPEG) {
- uint16 input_compression, input_photometric;
if (TIFFGetField(in, TIFFTAG_COMPRESSION, &input_compression)
&& input_compression == COMPRESSION_JPEG) {
@@ -594,6 +611,7 @@ tiffcp(TIFF* in, TIFF* out)
PHOTOMETRIC_LOGL : PHOTOMETRIC_LOGLUV);
else
CopyTag(TIFFTAG_PHOTOMETRIC, 1, TIFF_SHORT);
+
if (fillorder != 0)
TIFFSetField(out, TIFFTAG_FILLORDER, fillorder);
else