From 62b9df5d2af68262fa6fcfb66086bf128f7d67c3 Mon Sep 17 00:00:00 2001
From: Even Rouault
Date: Thu, 21 Dec 2017 13:32:02 +0100
Subject: [PATCH 01/66] Add ZSTD compression codec
From https://github.com/facebook/zstd
"Zstandard, or zstd as short version, is a fast lossless compression
algorithm, targeting real-time compression scenarios at zlib-level
and better compression ratios. It's backed by a very fast entropy stage,
provided by Huff0 and FSE library."
We require libzstd >= 1.0.0 so as to be able to use streaming compression
and decompression methods.
The default compression level we have selected is 9 (range goes from 1 to 22),
which experimentally offers equivalent or better compression ratio than
the default deflate/ZIP level of 6, and much faster compression.
For example on a 6600x4400 16bit image, tiffcp -c zip runs in 10.7 seconds,
while tiffcp -c zstd runs in 5.3 seconds. Decompression time for zip is
840 ms, and for zstd 650 ms. File size is 42735936 for zip, and
42586822 for zstd. Similar findings on other images.
On a 25894x16701 16bit image,
Compression time Decompression time File size
ZSTD 35 s 3.2 s 399 700 498
ZIP/Deflate 1m 20 s 4.9 s 419 622 336
---
CMakeLists.txt | 28 +++
configure.ac | 55 +++++
libtiff/CMakeLists.txt | 3 +-
libtiff/Makefile.am | 3 +-
libtiff/tif_codec.c | 4 +
libtiff/tif_config.h.cmake.in | 3 +
libtiff/tif_config.h.in | 3 +
libtiff/tif_dirinfo.c | 4 +
libtiff/tif_zstd.c | 442 ++++++++++++++++++++++++++++++++++
libtiff/tiff.h | 2 +
libtiff/tiffiop.h | 3 +
tools/tiffcp.c | 9 +-
12 files changed, 556 insertions(+), 3 deletions(-)
create mode 100644 libtiff/tif_zstd.c
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 52b5ae99..2e1229ce 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -578,6 +578,27 @@ if(LIBLZMA_FOUND)
set(LZMA_SUPPORT 1)
endif()
+# libzstd
+option(zstd "use libzstd (required for ZSTD compression)" ON)
+if (zstd)
+ find_path(ZSTD_INCLUDE_DIR zstd.h)
+ find_library(ZSTD_LIBRARY NAMES zstd)
+ if (ZSTD_INCLUDE_DIR AND ZSTD_LIBRARY)
+ check_library_exists ("${ZSTD_LIBRARY}" ZSTD_decompressStream "" ZSTD_RECENT_ENOUGH)
+ if (ZSTD_RECENT_ENOUGH)
+ set(ZSTD_FOUND TRUE)
+ set(ZSTD_LIBRARIES ${ZSTD_LIBRARY})
+ message(STATUS "Found ZSTD library: ${ZSTD_LIBRARY}")
+ else ()
+ message(WARNING "Found ZSTD library, but not recent enough. Use zstd >= 1.0")
+ endif ()
+ endif ()
+endif()
+set(ZSTD_SUPPORT 0)
+if(ZSTD_FOUND)
+ set(ZSTD_SUPPORT 1)
+endif()
+
# 8/12-bit jpeg mode
option(jpeg12 "enable libjpeg 8/12-bit dual mode (requires separate
12-bit libjpeg build)" ON)
@@ -692,6 +713,9 @@ endif()
if(LIBLZMA_INCLUDE_DIRS)
list(APPEND TIFF_INCLUDES ${LIBLZMA_INCLUDE_DIRS})
endif()
+if(ZSTD_INCLUDE_DIR)
+ list(APPEND TIFF_INCLUDES ${ZSTD_INCLUDE_DIR})
+endif()
# Libraries required by libtiff
set(TIFF_LIBRARY_DEPS)
@@ -713,6 +737,9 @@ endif()
if(LIBLZMA_LIBRARIES)
list(APPEND TIFF_LIBRARY_DEPS ${LIBLZMA_LIBRARIES})
endif()
+if(ZSTD_LIBRARIES)
+ list(APPEND TIFF_LIBRARY_DEPS ${ZSTD_LIBRARIES})
+endif()
#report_values(TIFF_INCLUDES TIFF_LIBRARY_DEPS)
@@ -756,6 +783,7 @@ message(STATUS " Old JPEG support: ${old-jpeg} (requested) ${
message(STATUS " JPEG 8/12 bit dual mode: ${jpeg12} (requested) ${JPEG12_FOUND} (availability)")
message(STATUS " ISO JBIG support: ${jbig} (requested) ${JBIG_FOUND} (availability)")
message(STATUS " LZMA2 support: ${lzma} (requested) ${LIBLZMA_FOUND} (availability)")
+message(STATUS " ZSTD support: ${zstd} (requested) ${ZSTD_FOUND} (availability)")
message(STATUS "")
message(STATUS " C++ support: ${cxx} (requested) ${CXX_SUPPORT} (availability)")
message(STATUS "")
diff --git a/configure.ac b/configure.ac
index 0dd32b75..6a8e6e47 100644
--- a/configure.ac
+++ b/configure.ac
@@ -826,6 +826,60 @@ fi
AM_CONDITIONAL(HAVE_LZMA, test "$HAVE_LZMA" = 'yes')
+dnl ---------------------------------------------------------------------------
+dnl Check for libzstd.
+dnl ---------------------------------------------------------------------------
+
+HAVE_ZSTD=no
+
+AC_ARG_ENABLE(zstd,
+ AS_HELP_STRING([--disable-zstd],
+ [disable libzstd usage (required for zstd compression, enabled by default)]),,)
+AC_ARG_WITH(zstd-include-dir,
+ AS_HELP_STRING([--with-zstd-include-dir=DIR],
+ [location of libzstd headers]),,)
+AC_ARG_WITH(zstd-lib-dir,
+ AS_HELP_STRING([--with-zstd-lib-dir=DIR],
+ [location of libzstd library binary]),,)
+
+if test "x$enable_zstd" != "xno" ; then
+
+ if test "x$with_zstd_lib_dir" != "x" ; then
+ LDFLAGS="-L$with_zstd_lib_dir $LDFLAGS"
+ fi
+
+ AC_CHECK_LIB(zstd, ZSTD_decompressStream, [zstd_lib=yes], [zstd_lib=no],)
+ if test "$zstd_lib" = "no" -a "x$with_zstd_lib_dir" != "x"; then
+ AC_MSG_ERROR([zstd library not found at $with_zstd_lib_dir])
+ fi
+
+ if test "x$with_zstd_include_dir" != "x" ; then
+ CPPFLAGS="-I$with_zstd_include_dir $CPPFLAGS"
+ fi
+ AC_CHECK_HEADER(zstd.h, [zstd_h=yes], [zstd_h=no])
+ if test "$zstd_h" = "no" -a "x$with_zstd_include_dir" != "x" ; then
+ AC_MSG_ERROR([Libzstd headers not found at $with_zstd_include_dir])
+ fi
+
+ if test "$zstd_lib" = "yes" -a "$zstd_h" = "yes" ; then
+ HAVE_ZSTD=yes
+ fi
+
+fi
+
+if test "$HAVE_ZSTD" = "yes" ; then
+ AC_DEFINE(ZSTD_SUPPORT,1,[Support zstd compression])
+ LIBS="-lzstd $LIBS"
+ tiff_libs_private="-lzstd ${tiff_libs_private}"
+
+ if test "$HAVE_RPATH" = "yes" -a "x$with_zstd_lib_dir" != "x" ; then
+ LIBDIR="-R $with_zstd_lib_dir $LIBDIR"
+ fi
+
+fi
+
+AM_CONDITIONAL(HAVE_ZSTD, test "$HAVE_ZSTD" = 'yes')
+
dnl ---------------------------------------------------------------------------
dnl Should 8/12 bit jpeg mode be enabled?
dnl ---------------------------------------------------------------------------
@@ -1103,6 +1157,7 @@ LOC_MSG([ Old JPEG support: ${HAVE_OJPEG}])
LOC_MSG([ JPEG 8/12 bit dual mode: ${HAVE_JPEG12}])
LOC_MSG([ ISO JBIG support: ${HAVE_JBIG}])
LOC_MSG([ LZMA2 support: ${HAVE_LZMA}])
+LOC_MSG([ ZSTD support: ${HAVE_ZSTD}])
LOC_MSG()
LOC_MSG([ C++ support: ${HAVE_CXX}])
LOC_MSG()
diff --git a/libtiff/CMakeLists.txt b/libtiff/CMakeLists.txt
index 087dfa9e..34107efb 100644
--- a/libtiff/CMakeLists.txt
+++ b/libtiff/CMakeLists.txt
@@ -94,7 +94,8 @@ set(tiff_SOURCES
tif_version.c
tif_warning.c
tif_write.c
- tif_zip.c)
+ tif_zip.c
+ tif_zstd.c)
set(tiffxx_HEADERS
tiffio.hxx)
diff --git a/libtiff/Makefile.am b/libtiff/Makefile.am
index 9cbc5b1d..53271e9e 100644
--- a/libtiff/Makefile.am
+++ b/libtiff/Makefile.am
@@ -99,7 +99,8 @@ libtiff_la_SOURCES = \
tif_version.c \
tif_warning.c \
tif_write.c \
- tif_zip.c
+ tif_zip.c \
+ tif_zstd.c
libtiffxx_la_SOURCES = \
tif_stream.cxx
diff --git a/libtiff/tif_codec.c b/libtiff/tif_codec.c
index e0aaacff..ac7bad85 100644
--- a/libtiff/tif_codec.c
+++ b/libtiff/tif_codec.c
@@ -70,6 +70,9 @@ static int NotConfigured(TIFF*, int);
#ifndef LZMA_SUPPORT
#define TIFFInitLZMA NotConfigured
#endif
+#ifndef ZSTD_SUPPORT
+#define TIFFInitZSTD NotConfigured
+#endif
/*
* Compression schemes statically built into the library.
@@ -97,6 +100,7 @@ TIFFCodec _TIFFBuiltinCODECS[] = {
{ "SGILog", COMPRESSION_SGILOG, TIFFInitSGILog },
{ "SGILog24", COMPRESSION_SGILOG24, TIFFInitSGILog },
{ "LZMA", COMPRESSION_LZMA, TIFFInitLZMA },
+ { "ZSTD", COMPRESSION_ZSTD, TIFFInitZSTD },
{ NULL, 0, NULL }
};
diff --git a/libtiff/tif_config.h.cmake.in b/libtiff/tif_config.h.cmake.in
index de0f3a3c..1e19483c 100644
--- a/libtiff/tif_config.h.cmake.in
+++ b/libtiff/tif_config.h.cmake.in
@@ -146,6 +146,9 @@
/* Support LZMA2 compression */
#cmakedefine LZMA_SUPPORT 1
+/* Support ZSTD compression */
+#cmakedefine ZSTD_SUPPORT 1
+
/* Name of package */
#define PACKAGE "@PACKAGE_NAME@"
diff --git a/libtiff/tif_config.h.in b/libtiff/tif_config.h.in
index a4b2e60a..f8af9ed4 100644
--- a/libtiff/tif_config.h.in
+++ b/libtiff/tif_config.h.in
@@ -380,6 +380,9 @@
/* Support Deflate compression */
#undef ZIP_SUPPORT
+/* Support zstd compression */
+#undef ZSTD_SUPPORT
+
/* Enable large inode numbers on Mac OS X 10.5. */
#ifndef _DARWIN_USE_64_BIT_INODE
# define _DARWIN_USE_64_BIT_INODE 1
diff --git a/libtiff/tif_dirinfo.c b/libtiff/tif_dirinfo.c
index d26fd120..fd12b737 100644
--- a/libtiff/tif_dirinfo.c
+++ b/libtiff/tif_dirinfo.c
@@ -1052,6 +1052,10 @@ _TIFFCheckFieldIsValidForCodec(TIFF *tif, ttag_t tag)
if (tag == TIFFTAG_PREDICTOR)
return 1;
break;
+ case COMPRESSION_ZSTD:
+ if (tag == TIFFTAG_PREDICTOR)
+ return 1;
+ break;
}
return 0;
diff --git a/libtiff/tif_zstd.c b/libtiff/tif_zstd.c
new file mode 100644
index 00000000..2bdf1129
--- /dev/null
+++ b/libtiff/tif_zstd.c
@@ -0,0 +1,442 @@
+/*
+* Copyright (c) 2017, Planet Labs
+* Author:
+*
+* Permission to use, copy, modify, distribute, and sell this software and
+* its documentation for any purpose is hereby granted without fee, provided
+* that (i) the above copyright notices and this permission notice appear in
+* all copies of the software and related documentation, and (ii) the names of
+* Sam Leffler and Silicon Graphics may not be used in any advertising or
+* publicity relating to the software without the specific, prior written
+* permission of Sam Leffler and Silicon Graphics.
+*
+* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
+* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
+* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
+*
+* IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
+* ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
+* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
+* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+* OF THIS SOFTWARE.
+*/
+
+#include "tiffiop.h"
+#ifdef ZSTD_SUPPORT
+/*
+* TIFF Library.
+*
+* ZSTD Compression Support
+*
+*/
+
+#include "tif_predict.h"
+#include "zstd.h"
+
+#include
+
+/*
+* State block for each open TIFF file using ZSTD compression/decompression.
+*/
+typedef struct {
+ TIFFPredictorState predict;
+ ZSTD_DStream* dstream;
+ ZSTD_CStream* cstream;
+ int compression_level; /* compression level */
+ ZSTD_outBuffer out_buffer;
+ int state; /* state flags */
+#define LSTATE_INIT_DECODE 0x01
+#define LSTATE_INIT_ENCODE 0x02
+
+ TIFFVGetMethod vgetparent; /* super-class method */
+ TIFFVSetMethod vsetparent; /* super-class method */
+} ZSTDState;
+
+#define LState(tif) ((ZSTDState*) (tif)->tif_data)
+#define DecoderState(tif) LState(tif)
+#define EncoderState(tif) LState(tif)
+
+static int ZSTDEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s);
+static int ZSTDDecode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s);
+
+static int
+ZSTDFixupTags(TIFF* tif)
+{
+ (void) tif;
+ return 1;
+}
+
+static int
+ZSTDSetupDecode(TIFF* tif)
+{
+ ZSTDState* sp = DecoderState(tif);
+
+ assert(sp != NULL);
+
+ /* if we were last encoding, terminate this mode */
+ if (sp->state & LSTATE_INIT_ENCODE) {
+ ZSTD_freeCStream(sp->cstream);
+ sp->cstream = NULL;
+ sp->state = 0;
+ }
+
+ sp->state |= LSTATE_INIT_DECODE;
+ return 1;
+}
+
+/*
+* Setup state for decoding a strip.
+*/
+static int
+ZSTDPreDecode(TIFF* tif, uint16 s)
+{
+ static const char module[] = "ZSTDPreDecode";
+ ZSTDState* sp = DecoderState(tif);
+ size_t zstd_ret;
+
+ (void) s;
+ assert(sp != NULL);
+
+ if( (sp->state & LSTATE_INIT_DECODE) == 0 )
+ tif->tif_setupdecode(tif);
+
+ if( sp->dstream )
+ {
+ ZSTD_freeDStream(sp->dstream);
+ sp->dstream = NULL;
+ }
+
+ sp->dstream = ZSTD_createDStream();
+ if( sp->dstream == NULL ) {
+ TIFFErrorExt(tif->tif_clientdata, module,
+ "Cannot allocate decompression stream");
+ return 0;
+ }
+ zstd_ret = ZSTD_initDStream(sp->dstream);
+ if( ZSTD_isError(zstd_ret) ) {
+ TIFFErrorExt(tif->tif_clientdata, module,
+ "Error in ZSTD_initDStream(): %s",
+ ZSTD_getErrorName(zstd_ret));
+ return 0;
+ }
+
+ return 1;
+}
+
+static int
+ZSTDDecode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s)
+{
+ static const char module[] = "ZSTDDecode";
+ ZSTDState* sp = DecoderState(tif);
+ ZSTD_inBuffer in_buffer;
+ ZSTD_outBuffer out_buffer;
+ size_t zstd_ret;
+
+ (void) s;
+ assert(sp != NULL);
+ assert(sp->state == LSTATE_INIT_DECODE);
+
+ in_buffer.src = tif->tif_rawcp;
+ in_buffer.size = (size_t) tif->tif_rawcc;
+ in_buffer.pos = 0;
+
+ out_buffer.dst = op;
+ out_buffer.size = (size_t) occ;
+ out_buffer.pos = 0;
+
+ do {
+ zstd_ret = ZSTD_decompressStream(sp->dstream, &out_buffer,
+ &in_buffer);
+ if( ZSTD_isError(zstd_ret) ) {
+ TIFFErrorExt(tif->tif_clientdata, module,
+ "Error in ZSTD_decompressStream(): %s",
+ ZSTD_getErrorName(zstd_ret));
+ return 0;
+ }
+ } while( zstd_ret != 0 &&
+ in_buffer.pos < in_buffer.size &&
+ out_buffer.pos < out_buffer.size );
+
+ if (out_buffer.pos < (size_t)occ) {
+ TIFFErrorExt(tif->tif_clientdata, module,
+ "Not enough data at scanline %lu (short %lu bytes)",
+ (unsigned long) tif->tif_row,
+ (unsigned long) (size_t)occ - out_buffer.pos);
+ return 0;
+ }
+
+ tif->tif_rawcp += in_buffer.pos;
+ tif->tif_rawcc -= in_buffer.pos;
+
+ return 1;
+}
+
+static int
+ZSTDSetupEncode(TIFF* tif)
+{
+ ZSTDState* sp = EncoderState(tif);
+
+ assert(sp != NULL);
+ if (sp->state & LSTATE_INIT_DECODE) {
+ ZSTD_freeDStream(sp->dstream);
+ sp->dstream = NULL;
+ sp->state = 0;
+ }
+
+ sp->state |= LSTATE_INIT_ENCODE;
+ return 1;
+}
+
+/*
+* Reset encoding state at the start of a strip.
+*/
+static int
+ZSTDPreEncode(TIFF* tif, uint16 s)
+{
+ static const char module[] = "ZSTDPreEncode";
+ ZSTDState *sp = EncoderState(tif);
+ size_t zstd_ret;
+
+ (void) s;
+ assert(sp != NULL);
+ if( sp->state != LSTATE_INIT_ENCODE )
+ tif->tif_setupencode(tif);
+
+ if (sp->cstream) {
+ ZSTD_freeCStream(sp->cstream);
+ sp->cstream = NULL;
+ }
+ sp->cstream = ZSTD_createCStream();
+ if( sp->cstream == NULL ) {
+ TIFFErrorExt(tif->tif_clientdata, module,
+ "Cannot allocate compression stream");
+ return 0;
+ }
+
+ zstd_ret = ZSTD_initCStream(sp->cstream, sp->compression_level);
+ if( ZSTD_isError(zstd_ret) ) {
+ TIFFErrorExt(tif->tif_clientdata, module,
+ "Error in ZSTD_initCStream(): %s",
+ ZSTD_getErrorName(zstd_ret));
+ return 0;
+ }
+
+ sp->out_buffer.dst = tif->tif_rawdata;
+ sp->out_buffer.size = (size_t)tif->tif_rawdatasize;
+ sp->out_buffer.pos = 0;
+
+ return 1;
+}
+
+/*
+* Encode a chunk of pixels.
+*/
+static int
+ZSTDEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
+{
+ static const char module[] = "ZSTDEncode";
+ ZSTDState *sp = EncoderState(tif);
+ ZSTD_inBuffer in_buffer;
+ size_t zstd_ret;
+
+ assert(sp != NULL);
+ assert(sp->state == LSTATE_INIT_ENCODE);
+
+ (void) s;
+
+ in_buffer.src = bp;
+ in_buffer.size = (size_t)cc;
+ in_buffer.pos = 0;
+
+ do {
+ zstd_ret = ZSTD_compressStream(sp->cstream, &sp->out_buffer,
+ &in_buffer);
+ if( ZSTD_isError(zstd_ret) ) {
+ TIFFErrorExt(tif->tif_clientdata, module,
+ "Error in ZSTD_compressStream(): %s",
+ ZSTD_getErrorName(zstd_ret));
+ return 0;
+ }
+ if( sp->out_buffer.pos == sp->out_buffer.size ) {
+ tif->tif_rawcc = tif->tif_rawdatasize;
+ TIFFFlushData1(tif);
+ sp->out_buffer.dst = tif->tif_rawcp;
+ sp->out_buffer.size = (size_t) tif->tif_rawcc;
+ sp->out_buffer.pos = 0;
+ }
+ } while( in_buffer.pos < in_buffer.size );
+
+ return 1;
+}
+
+/*
+* Finish off an encoded strip by flushing it.
+*/
+static int
+ZSTDPostEncode(TIFF* tif)
+{
+ static const char module[] = "ZSTDPostEncode";
+ ZSTDState *sp = EncoderState(tif);
+ size_t zstd_ret;
+
+ do {
+ zstd_ret = ZSTD_endStream(sp->cstream, &sp->out_buffer);
+ if( ZSTD_isError(zstd_ret) ) {
+ TIFFErrorExt(tif->tif_clientdata, module,
+ "Error in ZSTD_endStream(): %s",
+ ZSTD_getErrorName(zstd_ret));
+ return 0;
+ }
+ if( sp->out_buffer.pos > 0 ) {
+ tif->tif_rawcc = sp->out_buffer.pos;
+ TIFFFlushData1(tif);
+ sp->out_buffer.dst = tif->tif_rawcp;
+ sp->out_buffer.size = (size_t) tif->tif_rawcc;
+ sp->out_buffer.pos = 0;
+ }
+ } while (zstd_ret != 0);
+ return 1;
+}
+
+static void
+ZSTDCleanup(TIFF* tif)
+{
+ ZSTDState* sp = LState(tif);
+
+ assert(sp != 0);
+
+ (void)TIFFPredictorCleanup(tif);
+
+ tif->tif_tagmethods.vgetfield = sp->vgetparent;
+ tif->tif_tagmethods.vsetfield = sp->vsetparent;
+
+ if (sp->dstream) {
+ ZSTD_freeDStream(sp->dstream);
+ sp->dstream = NULL;
+ }
+ if (sp->cstream) {
+ ZSTD_freeCStream(sp->cstream);
+ sp->cstream = NULL;
+ }
+ _TIFFfree(sp);
+ tif->tif_data = NULL;
+
+ _TIFFSetDefaultCompressionState(tif);
+}
+
+static int
+ZSTDVSetField(TIFF* tif, uint32 tag, va_list ap)
+{
+ static const char module[] = "ZSTDVSetField";
+ ZSTDState* sp = LState(tif);
+
+ switch (tag) {
+ case TIFFTAG_ZSTD_LEVEL:
+ sp->compression_level = (int) va_arg(ap, int);
+ if( sp->compression_level <= 0 ||
+ sp->compression_level > ZSTD_maxCLevel() )
+ {
+ TIFFWarningExt(tif->tif_clientdata, module,
+ "ZSTD_LEVEL should be between 1 and %d",
+ ZSTD_maxCLevel());
+ }
+ return 1;
+ default:
+ return (*sp->vsetparent)(tif, tag, ap);
+ }
+ /*NOTREACHED*/
+}
+
+static int
+ZSTDVGetField(TIFF* tif, uint32 tag, va_list ap)
+{
+ ZSTDState* sp = LState(tif);
+
+ switch (tag) {
+ case TIFFTAG_ZSTD_LEVEL:
+ *va_arg(ap, int*) = sp->compression_level;
+ break;
+ default:
+ return (*sp->vgetparent)(tif, tag, ap);
+ }
+ return 1;
+}
+
+static const TIFFField ZSTDFields[] = {
+ { TIFFTAG_ZSTD_LEVEL, 0, 0, TIFF_ANY, 0, TIFF_SETGET_INT,
+ TIFF_SETGET_UNDEFINED,
+ FIELD_PSEUDO, TRUE, FALSE, "ZSTD compression_level", NULL },
+};
+
+int
+TIFFInitZSTD(TIFF* tif, int scheme)
+{
+ static const char module[] = "TIFFInitZSTD";
+ ZSTDState* sp;
+
+ assert( scheme == COMPRESSION_ZSTD );
+
+ /*
+ * Merge codec-specific tag information.
+ */
+ if (!_TIFFMergeFields(tif, ZSTDFields, TIFFArrayCount(ZSTDFields))) {
+ TIFFErrorExt(tif->tif_clientdata, module,
+ "Merging ZSTD codec-specific tags failed");
+ return 0;
+ }
+
+ /*
+ * Allocate state block so tag methods have storage to record values.
+ */
+ tif->tif_data = (uint8*) _TIFFmalloc(sizeof(ZSTDState));
+ if (tif->tif_data == NULL)
+ goto bad;
+ sp = LState(tif);
+
+ /*
+ * Override parent get/set field methods.
+ */
+ sp->vgetparent = tif->tif_tagmethods.vgetfield;
+ tif->tif_tagmethods.vgetfield = ZSTDVGetField; /* hook for codec tags */
+ sp->vsetparent = tif->tif_tagmethods.vsetfield;
+ tif->tif_tagmethods.vsetfield = ZSTDVSetField; /* hook for codec tags */
+
+ /* Default values for codec-specific fields */
+ sp->compression_level = 9; /* default comp. level */
+ sp->state = 0;
+ sp->dstream = 0;
+ sp->cstream = 0;
+ sp->out_buffer.dst = NULL;
+ sp->out_buffer.size = 0;
+ sp->out_buffer.pos = 0;
+
+ /*
+ * Install codec methods.
+ */
+ tif->tif_fixuptags = ZSTDFixupTags;
+ tif->tif_setupdecode = ZSTDSetupDecode;
+ tif->tif_predecode = ZSTDPreDecode;
+ tif->tif_decoderow = ZSTDDecode;
+ tif->tif_decodestrip = ZSTDDecode;
+ tif->tif_decodetile = ZSTDDecode;
+ tif->tif_setupencode = ZSTDSetupEncode;
+ tif->tif_preencode = ZSTDPreEncode;
+ tif->tif_postencode = ZSTDPostEncode;
+ tif->tif_encoderow = ZSTDEncode;
+ tif->tif_encodestrip = ZSTDEncode;
+ tif->tif_encodetile = ZSTDEncode;
+ tif->tif_cleanup = ZSTDCleanup;
+ /*
+ * Setup predictor setup.
+ */
+ (void) TIFFPredictorInit(tif);
+ return 1;
+bad:
+ TIFFErrorExt(tif->tif_clientdata, module,
+ "No space for ZSTD state block");
+ return 0;
+}
+#endif /* ZSTD_SUPPORT */
+
+/* vim: set ts=8 sts=8 sw=8 noet: */
diff --git a/libtiff/tiff.h b/libtiff/tiff.h
index 51c0a44c..b0d49220 100644
--- a/libtiff/tiff.h
+++ b/libtiff/tiff.h
@@ -188,6 +188,7 @@ typedef enum {
#define COMPRESSION_SGILOG24 34677 /* SGI Log 24-bit packed */
#define COMPRESSION_JP2000 34712 /* Leadtools JPEG2000 */
#define COMPRESSION_LZMA 34925 /* LZMA2 */
+#define COMPRESSION_ZSTD 34926 /* ZSTD */
#define TIFFTAG_PHOTOMETRIC 262 /* photometric interpretation */
#define PHOTOMETRIC_MINISWHITE 0 /* min value is white */
#define PHOTOMETRIC_MINISBLACK 1 /* min value is black */
@@ -601,6 +602,7 @@ typedef enum {
#define TIFFTAG_PERSAMPLE 65563 /* interface for per sample tags */
#define PERSAMPLE_MERGED 0 /* present as a single value */
#define PERSAMPLE_MULTI 1 /* present as multiple values */
+#define TIFFTAG_ZSTD_LEVEL 65534 /* ZSTD compression level */
/*
* EXIF tags
diff --git a/libtiff/tiffiop.h b/libtiff/tiffiop.h
index 0f59a705..d44e76a5 100644
--- a/libtiff/tiffiop.h
+++ b/libtiff/tiffiop.h
@@ -422,6 +422,9 @@ extern int TIFFInitSGILog(TIFF*, int);
#ifdef LZMA_SUPPORT
extern int TIFFInitLZMA(TIFF*, int);
#endif
+#ifdef ZSTD_SUPPORT
+extern int TIFFInitZSTD(TIFF*, int);
+#endif
#ifdef VMS
extern const TIFFCodec _TIFFBuiltinCODECS[];
#else
diff --git a/tools/tiffcp.c b/tools/tiffcp.c
index 08df56d5..482f5f4f 100644
--- a/tools/tiffcp.c
+++ b/tools/tiffcp.c
@@ -389,6 +389,9 @@ processCompressOptions(char* opt)
} else if (strneq(opt, "lzma", 4)) {
processZIPOptions(opt);
defcompression = COMPRESSION_LZMA;
+ } else if (strneq(opt, "zstd", 4)) {
+ processZIPOptions(opt);
+ defcompression = COMPRESSION_ZSTD;
} else if (strneq(opt, "jbig", 4)) {
defcompression = COMPRESSION_JBIG;
} else if (strneq(opt, "sgilog", 6)) {
@@ -427,6 +430,7 @@ char* stuff[] = {
" -c lzw[:opts] compress output with Lempel-Ziv & Welch encoding",
" -c zip[:opts] compress output with deflate encoding",
" -c lzma[:opts] compress output with LZMA2 encoding",
+" -c zstd[:opts] compress output with ZSTD encoding",
" -c jpeg[:opts] compress output with JPEG encoding",
" -c jbig compress output with ISO JBIG encoding",
" -c packbits compress output with packbits encoding",
@@ -446,7 +450,7 @@ char* stuff[] = {
" r output color image as RGB rather than YCbCr",
"For example, -c jpeg:r:50 to get JPEG-encoded RGB data with 50% comp. quality",
"",
-"LZW, Deflate (ZIP) and LZMA2 options:",
+"LZW, Deflate (ZIP), LZMA2 and ZSTD options:",
" # set predictor value",
" p# set compression level (preset)",
"For example, -c lzw:2 to get LZW-encoded data with horizontal differencing,",
@@ -731,6 +735,7 @@ tiffcp(TIFF* in, TIFF* out)
case COMPRESSION_ADOBE_DEFLATE:
case COMPRESSION_DEFLATE:
case COMPRESSION_LZMA:
+ case COMPRESSION_ZSTD:
if (predictor != (uint16)-1)
TIFFSetField(out, TIFFTAG_PREDICTOR, predictor);
else
@@ -741,6 +746,8 @@ tiffcp(TIFF* in, TIFF* out)
TIFFSetField(out, TIFFTAG_ZIPQUALITY, preset);
else if (compression == COMPRESSION_LZMA)
TIFFSetField(out, TIFFTAG_LZMAPRESET, preset);
+ else if (compression == COMPRESSION_ZSTD)
+ TIFFSetField(out, TIFFTAG_ZSTD_LEVEL, preset);
}
break;
case COMPRESSION_CCITTFAX3:
From 25c14f84a8880e7af3322446744a8fd546cd52be Mon Sep 17 00:00:00 2001
From: Even Rouault
Date: Thu, 21 Dec 2017 13:53:44 +0100
Subject: [PATCH 02/66] Add libzstd to gitlab-ci
---
.gitlab-ci.yml | 2 +-
build/gitlab-ci | 17 ++++++++++++++---
2 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 606948e4..b80f8bed 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,6 +1,6 @@
image: ubuntu:16.04
before_script:
- - apt-get update -qq && apt-get install -y -qq autoconf automake build-essential cmake libtool libjpeg8-dev libjbig-dev liblzma-dev ninja-build zlib1g-dev zip
+ - apt-get update -qq && apt-get install -y -qq autoconf automake build-essential cmake libtool libjpeg8-dev libjbig-dev liblzma-dev ninja-build zlib1g-dev zip wget
stages:
- build
diff --git a/build/gitlab-ci b/build/gitlab-ci
index 1370caec..a562f10f 100644
--- a/build/gitlab-ci
+++ b/build/gitlab-ci
@@ -13,7 +13,7 @@ autoconf_build()
mkdir autoconf-build
cd autoconf-build
echo "Running ../configure --prefix=$(pwd)/../autoconf-install) ${opts}"
- ../configure --prefix=$(pwd)/../autoconf-install ${opts}
+ ../configure --prefix=$(pwd)/../autoconf-install --with-zstd-include-dir=/tmp/include --with-zstd-lib-dir=/tmp/lib ${opts}
make
make install
make check
@@ -29,8 +29,8 @@ cmake_build()
fi
mkdir cmake-build
cd cmake-build
- echo "Running cmake -G "$1" -DCMAKE_BUILD_TYPE="$2" -DCMAKE_INSTALL_PREFIX=../autoconf-install ${opts} .."
- cmake -G "$1" -DCMAKE_BUILD_TYPE="$2" -DCMAKE_INSTALL_PREFIX=../autoconf-install ${opts} ..
+ echo "Running cmake -G "$1" -DCMAKE_BUILD_TYPE="$2" -DCMAKE_INSTALL_PREFIX=../autoconf-install -DZSTD_INCLUDE_DIR=/tmp/include -DZSTD_LIBRARY=/tmp/lib/libzstd.so ${opts} .."
+ cmake -G "$1" -DCMAKE_BUILD_TYPE="$2" -DCMAKE_INSTALL_PREFIX=../autoconf-install -DZSTD_INCLUDE_DIR=/tmp/include -DZSTD_LIBRARY=/tmp/lib/libzstd.so ${opts} ..
cmake --build .
cmake --build . --target install
ctest -V
@@ -39,6 +39,17 @@ cmake_build()
build=$1
shift
+# Build zstd
+wget https://github.com/facebook/zstd/archive/v1.3.3.tar.gz
+tar xvzf v1.3.3.tar.gz
+cd zstd-1.3.3/lib
+# Faster build
+make -j3 PREFIX=/tmp ZSTD_LEGACY_SUPPORT=0 CFLAGS=-O1
+make install PREFIX=/tmp ZSTD_LEGACY_SUPPORT=0 CFLAGS=-O1
+cd ../..
+rm -rf zstd-1.3.3
+export LD_LIBRARY_PATH=/tmp/lib
+
case $build in
autoconf)
echo "Testing Autoconf build"
From 0b05f432098266093ce80573845eb50e4f486176 Mon Sep 17 00:00:00 2001
From: Kevin Funk
Date: Fri, 12 Jan 2018 12:15:02 +0100
Subject: [PATCH 03/66] Prefer target_include_directories
When libtiff is included in a super project via a simple
`add_subdirectory(libtiff)`, this way the `tiff` library target has all
the necessary information to build against it.
Note: The BUILD_INTERFACE generator expression feature requires at least
CMake v2.8.11 if I'm correct.
---
libtiff/CMakeLists.txt | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/libtiff/CMakeLists.txt b/libtiff/CMakeLists.txt
index 087dfa9e..2e4ef3cf 100644
--- a/libtiff/CMakeLists.txt
+++ b/libtiff/CMakeLists.txt
@@ -110,12 +110,14 @@ else()
list(APPEND tiff_SOURCES tif_unix.c)
endif()
-include_directories(${CMAKE_CURRENT_SOURCE_DIR}
- ${CMAKE_CURRENT_BINARY_DIR}
- ${TIFF_INCLUDES})
-
add_library(tiff ${tiff_SOURCES} ${tiff_HEADERS} ${nodist_tiff_HEADERS}
${tiff_port_SOURCES} libtiff.def)
+target_include_directories(tiff
+ PUBLIC
+ $
+ $
+ ${TIFF_INCLUDES}
+)
target_link_libraries(tiff ${TIFF_LIBRARY_DEPS})
set_target_properties(tiff PROPERTIES SOVERSION ${SO_COMPATVERSION})
if(NOT CYGWIN)
From f5b23ab1bf72ac2cdaae0b2c394daf035e95d934 Mon Sep 17 00:00:00 2001
From: Ben Boeckel
Date: Thu, 28 Dec 2017 17:22:45 -0500
Subject: [PATCH 04/66] cmake: remove unused configure checks
---
CMakeLists.txt | 29 ---------
configure.ac | 21 +-----
libtiff/tif_config.h.cmake.in | 45 -------------
libtiff/tif_config.h.in | 60 ------------------
libtiff/tiffconf.h-vms | 9 ---
libtiff/tiffconf.h.cmake.in | 9 ---
libtiff/tiffconf.h.in | 9 ---
libtiff/tiffconf.vc.h | 9 ---
libtiff/tiffconf.wince.h | 9 ---
port/CMakeLists.txt | 6 +-
port/strtoull.c | 116 ----------------------------------
11 files changed, 4 insertions(+), 318 deletions(-)
delete mode 100644 port/strtoull.c
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 52b5ae99..d2ed0566 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -213,9 +213,6 @@ check_include_file(dlfcn.h HAVE_DLFCN_H)
check_include_file(fcntl.h HAVE_FCNTL_H)
check_include_file(inttypes.h HAVE_INTTYPES_H)
check_include_file(io.h HAVE_IO_H)
-check_include_file(limits.h HAVE_LIMITS_H)
-check_include_file(malloc.h HAVE_MALLOC_H)
-check_include_file(memory.h HAVE_MEMORY_H)
check_include_file(search.h HAVE_SEARCH_H)
check_include_file(stdint.h HAVE_STDINT_H)
check_include_file(string.h HAVE_STRING_H)
@@ -271,8 +268,6 @@ int main(void){
# Check type sizes
# NOTE: Could be replaced with C99
-check_type_size("signed short" SIZEOF_SIGNED_SHORT)
-check_type_size("unsigned short" SIZEOF_UNSIGNED_SHORT)
check_type_size("signed int" SIZEOF_SIGNED_INT)
check_type_size("unsigned int" SIZEOF_UNSIGNED_INT)
check_type_size("signed long" SIZEOF_SIGNED_LONG)
@@ -388,34 +383,10 @@ endif()
# TIFF_SSIZE_T TIFF_SSIZE_FORMAT
# TIFF_PTRDIFF_T TIFF_PTRDIFF_FORMAT)
-# Nonstandard int types
-check_type_size(INT8 int8)
-set(HAVE_INT8 ${INT8})
-check_type_size(INT16 int16)
-set(HAVE_INT16 ${INT16})
-check_type_size(INT32 int32)
-set(HAVE_INT32 ${INT32})
-
-# Check functions
-set(CMAKE_REQUIRED_LIBRARIES_SAVE ${CMAKE_REQUIRED_LIBRARIES})
-set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${M_LIBRARY})
-check_function_exists(floor HAVE_FLOOR)
-check_function_exists(pow HAVE_POW)
-check_function_exists(sqrt HAVE_SQRT)
-set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES_SAVE})
-
-check_function_exists(isascii HAVE_ISASCII)
-check_function_exists(memmove HAVE_MEMMOVE)
-check_function_exists(memset HAVE_MEMSET)
check_function_exists(mmap HAVE_MMAP)
check_function_exists(setmode HAVE_SETMODE)
check_function_exists(strcasecmp HAVE_STRCASECMP)
-check_function_exists(strchr HAVE_STRCHR)
-check_function_exists(strrchr HAVE_STRRCHR)
-check_function_exists(strstr HAVE_STRSTR)
-check_function_exists(strtol HAVE_STRTOL)
check_function_exists(strtol HAVE_STRTOUL)
-check_function_exists(strtoull HAVE_STRTOULL)
check_function_exists(getopt HAVE_GETOPT)
check_function_exists(lfind HAVE_LFIND)
diff --git a/configure.ac b/configure.ac
index 0dd32b75..e35be778 100644
--- a/configure.ac
+++ b/configure.ac
@@ -174,7 +174,7 @@ case "${host_os}" in
esac
dnl Checks for header files.
-AC_CHECK_HEADERS([assert.h fcntl.h io.h limits.h malloc.h search.h sys/time.h unistd.h])
+AC_CHECK_HEADERS([assert.h fcntl.h io.h search.h unistd.h])
dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
@@ -196,12 +196,6 @@ dnl ---------------------------------------------------------------------------
dnl Compute sized types for current CPU and compiler options
dnl ---------------------------------------------------------------------------
-# Obtain size of an 'signed short' and define as SIZEOF_SIGNED_SHORT
-AC_CHECK_SIZEOF(signed short)
-
-# Obtain size of an 'unsigned short' and define as SIZEOF_UNSIGNED_SHORT
-AC_CHECK_SIZEOF(unsigned short)
-
# Obtain size of an 'signed int' and define as SIZEOF_SIGNED_INT
AC_CHECK_SIZEOF(signed int)
@@ -412,24 +406,15 @@ AC_MSG_RESULT($PTRDIFF_T)
AC_DEFINE_UNQUOTED(TIFF_PTRDIFF_T,$PTRDIFF_T,[Pointer difference type])
AC_DEFINE_UNQUOTED(TIFF_PTRDIFF_FORMAT,$PTRDIFF_FORMAT,[Pointer difference type formatter])
-dnl Some compilers (IBM VisualAge) has these types defined, so check it here:
-AC_CHECK_TYPES([int8, int16, int32],,,
-[
-#if HAVE_INTTYPES_H
-# include
-#endif
-])
-
dnl Checks for library functions.
-AC_CHECK_FUNCS([floor isascii memmove memset mmap pow setmode snprintf sqrt \
-strchr strrchr strstr strtol strtoul strtoull])
+AC_CHECK_FUNCS([mmap setmode snprintf \
+strtoul])
dnl Will use local replacements for unavailable functions
AC_REPLACE_FUNCS(getopt)
AC_REPLACE_FUNCS(snprintf)
AC_REPLACE_FUNCS(strcasecmp)
AC_REPLACE_FUNCS(strtoul)
-AC_REPLACE_FUNCS(strtoull)
AC_REPLACE_FUNCS(lfind)
dnl ---------------------------------------------------------------------------
diff --git a/libtiff/tif_config.h.cmake.in b/libtiff/tif_config.h.cmake.in
index de0f3a3c..e54fda88 100644
--- a/libtiff/tif_config.h.cmake.in
+++ b/libtiff/tif_config.h.cmake.in
@@ -26,9 +26,6 @@
/* Define to 1 if you have the header file. */
#cmakedefine HAVE_FCNTL_H 1
-/* Define to 1 if you have the `floor' function. */
-#cmakedefine HAVE_FLOOR 1
-
/* Define to 1 if you have the `getopt' function. */
#cmakedefine HAVE_GETOPT 1
@@ -50,30 +47,12 @@
/* Define to 1 if you have the header file. */
#cmakedefine HAVE_IO_H 1
-/* Define to 1 if you have the `isascii' function. */
-#cmakedefine HAVE_ISASCII 1
-
/* Define to 1 if you have the `jbg_newlen' function. */
#cmakedefine HAVE_JBG_NEWLEN 1
/* Define to 1 if you have the `lfind' function. */
#cmakedefine HAVE_LFIND 1
-/* Define to 1 if you have the header file. */
-#cmakedefine HAVE_LIMITS_H 1
-
-/* Define to 1 if you have the header file. */
-#cmakedefine HAVE_MALLOC_H 1
-
-/* Define to 1 if you have the `memmove' function. */
-#cmakedefine HAVE_MEMMOVE 1
-
-/* Define to 1 if you have the header file. */
-#cmakedefine HAVE_MEMORY_H 1
-
-/* Define to 1 if you have the `memset' function. */
-#cmakedefine HAVE_MEMSET 1
-
/* Define to 1 if you have the `mmap' function. */
#cmakedefine HAVE_MMAP 1
@@ -83,9 +62,6 @@
/* Define to 1 if you have the header file. */
#cmakedefine HAVE_OPENGL_GL_H 1
-/* Define to 1 if you have the `pow' function. */
-#cmakedefine HAVE_POW 1
-
/* Define to 1 if you have the header file. */
#cmakedefine HAVE_SEARCH_H 1
@@ -95,39 +71,21 @@
/* Define to 1 if you have the `snprintf' function. */
#cmakedefine HAVE_SNPRINTF 1
-/* Define to 1 if you have the `sqrt' function. */
-#cmakedefine HAVE_SQRT 1
-
/* Define to 1 if you have the header file. */
#cmakedefine HAVE_STDINT_H 1
/* Define to 1 if you have the `strcasecmp' function. */
#cmakedefine HAVE_STRCASECMP 1
-/* Define to 1 if you have the `strchr' function. */
-#cmakedefine HAVE_STRCHR 1
-
/* Define to 1 if you have the header file. */
#cmakedefine HAVE_STRINGS_H 1
/* Define to 1 if you have the header file. */
#cmakedefine HAVE_STRING_H 1
-/* Define to 1 if you have the `strrchr' function. */
-#cmakedefine HAVE_STRRCHR 1
-
-/* Define to 1 if you have the `strstr' function. */
-#cmakedefine HAVE_STRSTR 1
-
-/* Define to 1 if you have the `strtol' function. */
-#cmakedefine HAVE_STRTOL 1
-
/* Define to 1 if you have the `strtoul' function. */
#cmakedefine HAVE_STRTOUL 1
-/* Define to 1 if you have the `strtoull' function. */
-#cmakedefine HAVE_STRTOULL 1
-
/* Define to 1 if you have the header file. */
#cmakedefine HAVE_SYS_TIME_H 1
@@ -176,9 +134,6 @@
/* The size of `signed long long', as computed by sizeof. */
#define SIZEOF_SIGNED_LONG_LONG @SIZEOF_SIGNED_LONG_LONG@
-/* The size of `signed short', as computed by sizeof. */
-#define SIZEOF_SIGNED_SHORT @SIZEOF_SIGNED_SHORT@
-
/* The size of `unsigned char *', as computed by sizeof. */
#define SIZEOF_UNSIGNED_CHAR_P @SIZEOF_UNSIGNED_CHAR_P@
diff --git a/libtiff/tif_config.h.in b/libtiff/tif_config.h.in
index a4b2e60a..3db8077f 100644
--- a/libtiff/tif_config.h.in
+++ b/libtiff/tif_config.h.in
@@ -37,9 +37,6 @@
/* Define to 1 if you have the header file. */
#undef HAVE_FCNTL_H
-/* Define to 1 if you have the `floor' function. */
-#undef HAVE_FLOOR
-
/* Define to 1 if fseeko (and presumably ftello) exists and is declared. */
#undef HAVE_FSEEKO
@@ -62,45 +59,18 @@
machine */
#undef HAVE_IEEEFP
-/* Define to 1 if the system has the type `int16'. */
-#undef HAVE_INT16
-
-/* Define to 1 if the system has the type `int32'. */
-#undef HAVE_INT32
-
-/* Define to 1 if the system has the type `int8'. */
-#undef HAVE_INT8
-
/* Define to 1 if you have the header file. */
#undef HAVE_INTTYPES_H
/* Define to 1 if you have the header file. */
#undef HAVE_IO_H
-/* Define to 1 if you have the `isascii' function. */
-#undef HAVE_ISASCII
-
/* Define to 1 if you have the `jbg_newlen' function. */
#undef HAVE_JBG_NEWLEN
/* Define to 1 if you have the `lfind' function. */
#undef HAVE_LFIND
-/* Define to 1 if you have the header file. */
-#undef HAVE_LIMITS_H
-
-/* Define to 1 if you have the header file. */
-#undef HAVE_MALLOC_H
-
-/* Define to 1 if you have the `memmove' function. */
-#undef HAVE_MEMMOVE
-
-/* Define to 1 if you have the header file. */
-#undef HAVE_MEMORY_H
-
-/* Define to 1 if you have the `memset' function. */
-#undef HAVE_MEMSET
-
/* Define to 1 if you have the `mmap' function. */
#undef HAVE_MMAP
@@ -110,9 +80,6 @@
/* Define to 1 if you have the header file. */
#undef HAVE_OPENGL_GL_H
-/* Define to 1 if you have the `pow' function. */
-#undef HAVE_POW
-
/* Define if you have POSIX threads libraries and header files. */
#undef HAVE_PTHREAD
@@ -125,9 +92,6 @@
/* Define to 1 if you have the `snprintf' function. */
#undef HAVE_SNPRINTF
-/* Define to 1 if you have the `sqrt' function. */
-#undef HAVE_SQRT
-
/* Define to 1 if you have the header file. */
#undef HAVE_STDINT_H
@@ -137,36 +101,18 @@
/* Define to 1 if you have the `strcasecmp' function. */
#undef HAVE_STRCASECMP
-/* Define to 1 if you have the `strchr' function. */
-#undef HAVE_STRCHR
-
/* Define to 1 if you have the header file. */
#undef HAVE_STRINGS_H
/* Define to 1 if you have the header file. */
#undef HAVE_STRING_H
-/* Define to 1 if you have the `strrchr' function. */
-#undef HAVE_STRRCHR
-
-/* Define to 1 if you have the `strstr' function. */
-#undef HAVE_STRSTR
-
-/* Define to 1 if you have the `strtol' function. */
-#undef HAVE_STRTOL
-
/* Define to 1 if you have the `strtoul' function. */
#undef HAVE_STRTOUL
-/* Define to 1 if you have the `strtoull' function. */
-#undef HAVE_STRTOULL
-
/* Define to 1 if you have the header file. */
#undef HAVE_SYS_STAT_H
-/* Define to 1 if you have the header file. */
-#undef HAVE_SYS_TIME_H
-
/* Define to 1 if you have the header file. */
#undef HAVE_SYS_TYPES_H
@@ -259,9 +205,6 @@
/* The size of `signed long long', as computed by sizeof. */
#undef SIZEOF_SIGNED_LONG_LONG
-/* The size of `signed short', as computed by sizeof. */
-#undef SIZEOF_SIGNED_SHORT
-
/* The size of `size_t', as computed by sizeof. */
#undef SIZEOF_SIZE_T
@@ -277,9 +220,6 @@
/* The size of `unsigned long long', as computed by sizeof. */
#undef SIZEOF_UNSIGNED_LONG_LONG
-/* The size of `unsigned short', as computed by sizeof. */
-#undef SIZEOF_UNSIGNED_SHORT
-
/* Define to 1 if you have the ANSI C header files. */
#undef STDC_HEADERS
diff --git a/libtiff/tiffconf.h-vms b/libtiff/tiffconf.h-vms
index 8d52893e..72b03390 100644
--- a/libtiff/tiffconf.h-vms
+++ b/libtiff/tiffconf.h-vms
@@ -7,15 +7,6 @@
#ifndef _TIFFCONF_
#define _TIFFCONF_
-/* Define to 1 if the system has the type `int16'. */
-//#define HAVE_INT16
-
-/* Define to 1 if the system has the type `int32'. */
-//#define HAVE_INT32
-
-/* Define to 1 if the system has the type `int8'. */
-//#define HAVE_INT8
-
/* The size of a `int', as computed by sizeof. */
#define SIZEOF_INT 4
diff --git a/libtiff/tiffconf.h.cmake.in b/libtiff/tiffconf.h.cmake.in
index de8a807e..59542f1e 100644
--- a/libtiff/tiffconf.h.cmake.in
+++ b/libtiff/tiffconf.h.cmake.in
@@ -40,15 +40,6 @@
/* Pointer difference type */
#define TIFF_PTRDIFF_T @TIFF_PTRDIFF_T@
-/* Define to 1 if the system has the type `int16'. */
-#cmakedefine HAVE_INT16 1
-
-/* Define to 1 if the system has the type `int32'. */
-#cmakedefine HAVE_INT32 1
-
-/* Define to 1 if the system has the type `int8'. */
-#cmakedefine HAVE_INT8 1
-
/* Compatibility stuff. */
/* Define as 0 or 1 according to the floating point format suported by the
diff --git a/libtiff/tiffconf.h.in b/libtiff/tiffconf.h.in
index 6da9c5a6..5de30c9b 100644
--- a/libtiff/tiffconf.h.in
+++ b/libtiff/tiffconf.h.in
@@ -37,15 +37,6 @@
/* Pointer difference type */
#undef TIFF_PTRDIFF_T
-/* Define to 1 if the system has the type `int16'. */
-#undef HAVE_INT16
-
-/* Define to 1 if the system has the type `int32'. */
-#undef HAVE_INT32
-
-/* Define to 1 if the system has the type `int8'. */
-#undef HAVE_INT8
-
/* Compatibility stuff. */
/* Define as 0 or 1 according to the floating point format suported by the
diff --git a/libtiff/tiffconf.vc.h b/libtiff/tiffconf.vc.h
index c8c6c656..fb37a755 100644
--- a/libtiff/tiffconf.vc.h
+++ b/libtiff/tiffconf.vc.h
@@ -7,15 +7,6 @@
#ifndef _TIFFCONF_
#define _TIFFCONF_
-/* Define to 1 if the system has the type `int16'. */
-/* #undef HAVE_INT16 */
-
-/* Define to 1 if the system has the type `int32'. */
-/* #undef HAVE_INT32 */
-
-/* Define to 1 if the system has the type `int8'. */
-/* #undef HAVE_INT8 */
-
/* The size of a `int', as computed by sizeof. */
#define SIZEOF_INT 4
diff --git a/libtiff/tiffconf.wince.h b/libtiff/tiffconf.wince.h
index 30ff2d7a..013b0960 100644
--- a/libtiff/tiffconf.wince.h
+++ b/libtiff/tiffconf.wince.h
@@ -25,15 +25,6 @@
#ifndef _TIFFCONF_
#define _TIFFCONF_
-/* Define to 1 if the system has the type `int16'. */
-/* #undef HAVE_INT16 */
-
-/* Define to 1 if the system has the type `int32'. */
-/* #undef HAVE_INT32 */
-
-/* Define to 1 if the system has the type `int8'. */
-/* #undef HAVE_INT8 */
-
/* The size of a `int', as computed by sizeof. */
#define SIZEOF_INT 4
diff --git a/port/CMakeLists.txt b/port/CMakeLists.txt
index 8b221d1d..439fb3d7 100644
--- a/port/CMakeLists.txt
+++ b/port/CMakeLists.txt
@@ -28,8 +28,7 @@ set(port_optional_SOURCES
getopt.c
lfind.c
strcasecmp.c
- strtoul.c
- strtoull.c)
+ strtoul.c)
set(port_USED_FILES ${port_SOURCES} ${port_HEADERS})
@@ -48,9 +47,6 @@ endif()
if(NOT HAVE_STRTOUL)
list(APPEND port_USED_FILES strtoul.c)
endif()
-if(NOT HAVE_STRTOULL)
- list(APPEND port_USED_FILES strtoull.c)
-endif()
add_library(port STATIC ${port_USED_FILES})
diff --git a/port/strtoull.c b/port/strtoull.c
deleted file mode 100644
index fb7739cc..00000000
--- a/port/strtoull.c
+++ /dev/null
@@ -1,116 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include
-#include
-#include
-#include
-
-/*
- * Convert a string to an unsigned long long integer.
- *
- * Assumes that the upper and lower case
- * alphabets and digits are each contiguous.
- */
-unsigned long long
-strtoull(const char *nptr, char **endptr, int base)
-{
- const char *s;
- unsigned long long acc;
- char c;
- unsigned long long cutoff;
- int neg, any, cutlim;
-
- /*
- * See strtoq for comments as to the logic used.
- */
- s = nptr;
- do {
- c = *s++;
- } while (isspace((unsigned char)c));
- if (c == '-') {
- neg = 1;
- c = *s++;
- } else {
- neg = 0;
- if (c == '+')
- c = *s++;
- }
- if ((base == 0 || base == 16) &&
- c == '0' && (*s == 'x' || *s == 'X') &&
- ((s[1] >= '0' && s[1] <= '9') ||
- (s[1] >= 'A' && s[1] <= 'F') ||
- (s[1] >= 'a' && s[1] <= 'f'))) {
- c = s[1];
- s += 2;
- base = 16;
- }
- if (base == 0)
- base = c == '0' ? 8 : 10;
- acc = any = 0;
- if (base < 2 || base > 36)
- goto noconv;
-
- cutoff = ULLONG_MAX / base;
- cutlim = ULLONG_MAX % base;
- for ( ; ; c = *s++) {
- if (c >= '0' && c <= '9')
- c -= '0';
- else if (c >= 'A' && c <= 'Z')
- c -= 'A' - 10;
- else if (c >= 'a' && c <= 'z')
- c -= 'a' - 10;
- else
- break;
- if (c >= base)
- break;
- if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
- any = -1;
- else {
- any = 1;
- acc *= base;
- acc += c;
- }
- }
- if (any < 0) {
- acc = ULLONG_MAX;
- errno = ERANGE;
- } else if (!any) {
-noconv:
- errno = EINVAL;
- } else if (neg)
- acc = -acc;
- if (endptr != NULL)
- *endptr = (char *)(any ? s - 1 : nptr);
- return (acc);
-}
From fc3b73530009b0ac4e4ea13627a341a5d75bd045 Mon Sep 17 00:00:00 2001
From: Ben Boeckel
Date: Thu, 28 Dec 2017 17:23:45 -0500
Subject: [PATCH 05/66] cmake: use check_symbol_exists
This accounts for symbols being provided by macros.
---
CMakeLists.txt | 30 +++++++++---------------------
1 file changed, 9 insertions(+), 21 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d2ed0566..ad6b4e49 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -93,7 +93,7 @@ include(CheckCCompilerFlag)
include(CheckCSourceCompiles)
include(CheckIncludeFile)
include(CheckTypeSize)
-include(CheckFunctionExists)
+include(CheckSymbolExists)
enable_testing()
macro(current_date var)
@@ -383,22 +383,13 @@ endif()
# TIFF_SSIZE_T TIFF_SSIZE_FORMAT
# TIFF_PTRDIFF_T TIFF_PTRDIFF_FORMAT)
-check_function_exists(mmap HAVE_MMAP)
-check_function_exists(setmode HAVE_SETMODE)
-check_function_exists(strcasecmp HAVE_STRCASECMP)
-check_function_exists(strtol HAVE_STRTOUL)
-check_function_exists(getopt HAVE_GETOPT)
-check_function_exists(lfind HAVE_LFIND)
-
-# May be inlined, so check it compiles:
-check_c_source_compiles("
-#include
-int main(void) {
- char buf[10];
- snprintf(buf, 10, \"Test %d\", 1);
- return 0;
-}"
- HAVE_SNPRINTF)
+check_symbol_exists(mmap "sys/mman.h" HAVE_MMAP)
+check_symbol_exists(setmode "unistd.h" HAVE_SETMODE)
+check_symbol_exists(snprintf "stdio.h" HAVE_SNPRINTF)
+check_symbol_exists(strcasecmp "strings.h" HAVE_STRCASECMP)
+check_symbol_exists(strtol "stdlib.h" HAVE_STRTOUL)
+check_symbol_exists(getopt "unistd.h" HAVE_GETOPT)
+check_symbol_exists(lfind "search.h" HAVE_LFIND)
if(NOT HAVE_SNPRINTF)
add_definitions(-DNEED_LIBPORT)
@@ -531,12 +522,9 @@ else()
set(JBIG_FOUND FALSE)
endif()
-set(CMAKE_REQUIRED_LIBRARIES_SAVE ${CMAKE_REQUIRED_LIBRARIES})
set(CMAKE_REQUIRED_INCLUDES_SAVE ${CMAKE_REQUIRED_INCLUDES})
set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${JBIG_INCLUDE_DIR})
-set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${JBIG_LIBRARY})
-check_function_exists(jbg_newlen HAVE_JBG_NEWLEN)
-set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES_SAVE})
+check_symbol_exists(jbg_newlen "jbig.h" HAVE_JBG_NEWLEN)
set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_SAVE})
# liblzma2
From bed3b0cb9d2a0069b7182f17c656cf0f8812c9f4 Mon Sep 17 00:00:00 2001
From: Ben Boeckel
Date: Thu, 28 Dec 2017 17:28:21 -0500
Subject: [PATCH 06/66] cmake: avoid tautological logic
---
CMakeLists.txt | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ad6b4e49..3b332842 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -580,12 +580,8 @@ set(win32_io FALSE)
if(WIN32)
set(win32_io TRUE)
endif()
-set(USE_WIN32_FILEIO ${win32_io} CACHE BOOL "Use win32 IO system (Microsoft Windows only)")
-if (USE_WIN32_FILEIO)
- set(USE_WIN32_FILEIO TRUE)
-else()
- set(USE_WIN32_FILEIO FALSE)
-endif()
+
+set(USE_WIN32_FILEIO ${win32_io})
# Orthogonal features
From 0f2624713b8305675e0b9b7ba60a546357bc5d6c Mon Sep 17 00:00:00 2001
From: Ben Boeckel
Date: Fri, 29 Dec 2017 12:46:01 -0500
Subject: [PATCH 07/66] cmake: avoid an unnecessary intermediate variable
---
CMakeLists.txt | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3b332842..7254c567 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -396,14 +396,12 @@ if(NOT HAVE_SNPRINTF)
endif()
# CPU bit order
-set(fillorder FILLORDER_MSB2LSB)
+set(HOST_FILLORDER FILLORDER_MSB2LSB)
if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "i.*86.*" OR
CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "amd64.*" OR
CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86_64.*")
- set(fillorder FILLORDER_LSB2MSB)
+ set(HOST_FILLORDER FILLORDER_LSB2MSB)
endif()
-set(HOST_FILLORDER ${fillorder} CACHE STRING "Native CPU bit order")
-mark_as_advanced(HOST_FILLORDER)
# CPU endianness
include(TestBigEndian)
From 8d3c75b99f3208041abd65106a10cf4ebdd5e4b4 Mon Sep 17 00:00:00 2001
From: Ben Boeckel
Date: Fri, 29 Dec 2017 12:46:16 -0500
Subject: [PATCH 08/66] cmake: avoid an unnecessary intermediate variable
---
CMakeLists.txt | 14 +-------------
1 file changed, 1 insertion(+), 13 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7254c567..af2a1e98 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -405,19 +405,7 @@ endif()
# CPU endianness
include(TestBigEndian)
-test_big_endian(bigendian)
-if (bigendian)
- set(bigendian ON)
-else()
- set(bigendian OFF)
-endif()
-set(HOST_BIG_ENDIAN ${bigendian} CACHE STRING "Native CPU bit order")
-mark_as_advanced(HOST_BIG_ENDIAN)
-if (HOST_BIG_ENDIAN)
- set(HOST_BIG_ENDIAN 1)
-else()
- set(HOST_BIG_ENDIAN 0)
-endif()
+test_big_endian(HOST_BIG_ENDIAN)
# IEEE floating point
set(HAVE_IEEEFP 1 CACHE STRING "IEEE floating point is available")
From 4eb15b2739813d03389dac0b95972d70b4cb8a94 Mon Sep 17 00:00:00 2001
From: Ben Boeckel
Date: Fri, 29 Dec 2017 12:46:29 -0500
Subject: [PATCH 09/66] cmake: avoid setting hard-coded variables in the cache
---
CMakeLists.txt | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index af2a1e98..448ceaba 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -408,8 +408,7 @@ include(TestBigEndian)
test_big_endian(HOST_BIG_ENDIAN)
# IEEE floating point
-set(HAVE_IEEEFP 1 CACHE STRING "IEEE floating point is available")
-mark_as_advanced(HAVE_IEEEFP)
+set(HAVE_IEEEFP 1)
report_values(CMAKE_HOST_SYSTEM_PROCESSOR HOST_FILLORDER
HOST_BIG_ENDIAN HAVE_IEEEFP)
From 7bf855b942e85233f4a2c9484118d8e4167fd938 Mon Sep 17 00:00:00 2001
From: Kevin Funk
Date: Mon, 29 Jan 2018 20:38:02 +0100
Subject: [PATCH 10/66] Bump minimum required CMake version to v2.8.11
Because we use the BUILD_INTERFACE generator expression
---
CMakeLists.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 52b5ae99..a6554d69 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -23,7 +23,7 @@
# LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
# OF THIS SOFTWARE.
-cmake_minimum_required(VERSION 2.8.9)
+cmake_minimum_required(VERSION 2.8.11) # b/c of use of BUILD_INTERFACE generator expression
# Default policy is from 2.8.9
cmake_policy(VERSION 2.8.9)
From abd37566d81ba33f40fd750bedb22cdd88fbeb6e Mon Sep 17 00:00:00 2001
From: Paul Kehrer
Date: Tue, 30 Jan 2018 13:45:01 +0800
Subject: [PATCH 11/66] Fix a memory leak in TIFFStreamOpen
TIFFStreamOpen allocates a new tiff{o,i}s_data, but if TIFFClientOpen
fails then that struct is leaked. Delete it if the returned TIFF * is
null.
---
libtiff/tif_stream.cxx | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/libtiff/tif_stream.cxx b/libtiff/tif_stream.cxx
index 83c6bb05..c1fe3779 100644
--- a/libtiff/tif_stream.cxx
+++ b/libtiff/tif_stream.cxx
@@ -373,6 +373,9 @@ _tiffStreamOpen(const char* name, const char* mode, void *fd)
_tiffosSizeProc,
_tiffDummyMapProc,
_tiffDummyUnmapProc);
+ if (!tif) {
+ delete data;
+ }
} else {
tiffis_data *data = new tiffis_data;
data->stream = reinterpret_cast(fd);
@@ -387,6 +390,9 @@ _tiffStreamOpen(const char* name, const char* mode, void *fd)
_tiffisSizeProc,
_tiffDummyMapProc,
_tiffDummyUnmapProc);
+ if (!tif) {
+ delete data;
+ }
}
return (tif);
From 08084a9774ec22eb507339db9f68f8997ae8aefb Mon Sep 17 00:00:00 2001
From: Paul Kehrer
Date: Tue, 30 Jan 2018 13:56:49 +0800
Subject: [PATCH 12/66] use hard tabs like the rest of the project
---
libtiff/tif_stream.cxx | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/libtiff/tif_stream.cxx b/libtiff/tif_stream.cxx
index c1fe3779..f036f3e2 100644
--- a/libtiff/tif_stream.cxx
+++ b/libtiff/tif_stream.cxx
@@ -373,9 +373,9 @@ _tiffStreamOpen(const char* name, const char* mode, void *fd)
_tiffosSizeProc,
_tiffDummyMapProc,
_tiffDummyUnmapProc);
- if (!tif) {
+ if (!tif) {
delete data;
- }
+ }
} else {
tiffis_data *data = new tiffis_data;
data->stream = reinterpret_cast(fd);
@@ -390,9 +390,9 @@ _tiffStreamOpen(const char* name, const char* mode, void *fd)
_tiffisSizeProc,
_tiffDummyMapProc,
_tiffDummyUnmapProc);
- if (!tif) {
+ if (!tif) {
delete data;
- }
+ }
}
return (tif);
From 92556cf625619e0917184e4debd20e19f6c1848f Mon Sep 17 00:00:00 2001
From: Paul Kehrer
Date: Wed, 31 Jan 2018 07:58:18 +0800
Subject: [PATCH 13/66] tabs are hard
---
libtiff/tif_stream.cxx | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/libtiff/tif_stream.cxx b/libtiff/tif_stream.cxx
index f036f3e2..7f640a9c 100644
--- a/libtiff/tif_stream.cxx
+++ b/libtiff/tif_stream.cxx
@@ -374,7 +374,7 @@ _tiffStreamOpen(const char* name, const char* mode, void *fd)
_tiffDummyMapProc,
_tiffDummyUnmapProc);
if (!tif) {
- delete data;
+ delete data;
}
} else {
tiffis_data *data = new tiffis_data;
@@ -391,7 +391,7 @@ _tiffStreamOpen(const char* name, const char* mode, void *fd)
_tiffDummyMapProc,
_tiffDummyUnmapProc);
if (!tif) {
- delete data;
+ delete data;
}
}
From e9fa4baf1da46058e75c29d9b8d894c913199963 Mon Sep 17 00:00:00 2001
From: Nathan Baker
Date: Sun, 4 Feb 2018 23:54:17 +0000
Subject: [PATCH 14/66] Fix all compiler warnings for default build
---
contrib/iptcutil/iptcutil.c | 1 +
tools/thumbnail.c | 16 ++++++++--------
tools/tiff2pdf.c | 13 +++++++------
tools/tiffcmp.c | 3 ++-
tools/tiffcrop.c | 16 +++++++++-------
5 files changed, 27 insertions(+), 22 deletions(-)
diff --git a/contrib/iptcutil/iptcutil.c b/contrib/iptcutil/iptcutil.c
index b5b774ff..ad0a79c5 100644
--- a/contrib/iptcutil/iptcutil.c
+++ b/contrib/iptcutil/iptcutil.c
@@ -926,6 +926,7 @@ int tokenizer(unsigned inflag,char *token,int tokmax,char *line,
{
case IN_WHITE:
_p_state=IN_TOKEN; /* switch states */
+ /* Fall through */
case IN_TOKEN: /* these 2 are */
case IN_QUOTE: /* identical here */
diff --git a/tools/thumbnail.c b/tools/thumbnail.c
index db9c0c08..4e73df08 100644
--- a/tools/thumbnail.c
+++ b/tools/thumbnail.c
@@ -526,14 +526,14 @@ setrow(uint8* row, uint32 nrows, const uint8* rows[])
for (i = fw; i > 8; i--)
acc += bits[*src++];
/* fall thru... */
- case 8: acc += bits[*src++];
- case 7: acc += bits[*src++];
- case 6: acc += bits[*src++];
- case 5: acc += bits[*src++];
- case 4: acc += bits[*src++];
- case 3: acc += bits[*src++];
- case 2: acc += bits[*src++];
- case 1: acc += bits[*src++];
+ case 8: acc += bits[*src++]; /* fall thru */
+ case 7: acc += bits[*src++]; /* fall thru */
+ case 6: acc += bits[*src++]; /* fall thru */
+ case 5: acc += bits[*src++]; /* fall thru */
+ case 4: acc += bits[*src++]; /* fall thru */
+ case 3: acc += bits[*src++]; /* fall thru */
+ case 2: acc += bits[*src++]; /* fall thru */
+ case 1: acc += bits[*src++]; /* fall thru */
case 0: break;
}
acc += bits[*src & mask1];
diff --git a/tools/tiff2pdf.c b/tools/tiff2pdf.c
index 484776c1..984ef654 100644
--- a/tools/tiff2pdf.c
+++ b/tools/tiff2pdf.c
@@ -3736,12 +3736,13 @@ tsize_t
t2p_sample_rgbaa_to_rgb(tdata_t data, uint32 samplecount)
{
uint32 i;
-
- /* For the 3 first samples, there is overlapping between souce and
- destination, so use memmove().
- See http://bugzilla.maptools.org/show_bug.cgi?id=2577 */
- for(i = 0; i < 3 && i < samplecount; i++)
- memmove((uint8*)data + i * 3, (uint8*)data + i * 4, 3);
+
+ /* For the 3 first samples, there is overlap between source and
+ * destination, so use memmove().
+ * See http://bugzilla.maptools.org/show_bug.cgi?id=2577
+ */
+ for(i = 0; i < 3 && i < samplecount; i++)
+ memmove((uint8*)data + i * 3, (uint8*)data + i * 4, 3);
for(; i < samplecount; i++)
memcpy((uint8*)data + i * 3, (uint8*)data + i * 4, 3);
diff --git a/tools/tiffcmp.c b/tools/tiffcmp.c
index 02a5e342..299847df 100644
--- a/tools/tiffcmp.c
+++ b/tools/tiffcmp.c
@@ -436,7 +436,8 @@ PrintIntDiff(uint32 row, int sample, uint32 pix, uint32 w1, uint32 w2)
{
int32 mask1, mask2, s;
- mask1 = ~((-1) << bitspersample);
+ /* mask1 should have the n lowest bits set, where n == bitspersample */
+ mask1 = ((int32)1 << bitspersample) - 1;
s = (8 - bitspersample);
mask2 = mask1 << s;
for (; mask2 && pix < imagewidth;
diff --git a/tools/tiffcrop.c b/tools/tiffcrop.c
index d82a94c8..91a38f67 100644
--- a/tools/tiffcrop.c
+++ b/tools/tiffcrop.c
@@ -2210,8 +2210,9 @@ main(int argc, char* argv[])
unsigned int total_pages = 0;
unsigned int total_images = 0;
unsigned int end_of_input = FALSE;
- int seg, length;
- char temp_filename[PATH_MAX + 1];
+ int seg;
+ size_t length;
+ char temp_filename[PATH_MAX + 16]; /* Extra space keeps the compiler from complaining */
little_endian = *((unsigned char *)&little_endian) & '1';
@@ -2303,8 +2304,8 @@ main(int argc, char* argv[])
if (dump.infile != NULL)
fclose (dump.infile);
- /* dump.infilename is guaranteed to be NUL termimated and have 20 bytes
- fewer than PATH_MAX */
+ /* dump.infilename is guaranteed to be NUL terminated and have 20 bytes
+ fewer than PATH_MAX */
snprintf(temp_filename, sizeof(temp_filename), "%s-read-%03d.%s",
dump.infilename, dump_images,
(dump.format == DUMP_TEXT) ? "txt" : "raw");
@@ -2322,7 +2323,7 @@ main(int argc, char* argv[])
if (dump.outfile != NULL)
fclose (dump.outfile);
- /* dump.outfilename is guaranteed to be NUL termimated and have 20 bytes
+ /* dump.outfilename is guaranteed to be NUL terminated and have 20 bytes
fewer than PATH_MAX */
snprintf(temp_filename, sizeof(temp_filename), "%s-write-%03d.%s",
dump.outfilename, dump_images,
@@ -9055,8 +9056,9 @@ mirrorImage(uint16 spp, uint16 bps, uint16 mirror, uint32 width, uint32 length,
_TIFFfree(line_buff);
if (mirror == MIRROR_VERT)
break;
+ /* Fall through */
case MIRROR_HORIZ :
- if ((bps % 8) == 0) /* byte alligned data */
+ if ((bps % 8) == 0) /* byte aligned data */
{
for (row = 0; row < length; row++)
{
@@ -9201,7 +9203,7 @@ invertImage(uint16 photometric, uint16 spp, uint16 bps, uint32 width, uint32 len
bytebuff2 = 4 - (uint8)(*src & 48 >> 4);
bytebuff3 = 4 - (uint8)(*src & 12 >> 2);
bytebuff4 = 4 - (uint8)(*src & 3);
- *src = (bytebuff1 << 6) || (bytebuff2 << 4) || (bytebuff3 << 2) || bytebuff4;
+ *src = (bytebuff1 << 6) | (bytebuff2 << 4) | (bytebuff3 << 2) | bytebuff4;
src++;
}
break;
From 4125ca9a4723b7e0ba516fb623059a7729ce152f Mon Sep 17 00:00:00 2001
From: Ben Boeckel
Date: Tue, 6 Feb 2018 10:24:33 -0500
Subject: [PATCH 15/66] cmake: check CXX_SUPPORT
This variable is set in response to the `cxx` cache variable; use it
instead.
---
libtiff/CMakeLists.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libtiff/CMakeLists.txt b/libtiff/CMakeLists.txt
index 087dfa9e..9d8665b2 100644
--- a/libtiff/CMakeLists.txt
+++ b/libtiff/CMakeLists.txt
@@ -138,7 +138,7 @@ install(TARGETS tiff
install(FILES ${tiff_HEADERS} ${nodist_tiff_HEADERS}
DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}")
-if(cxx)
+if(CXX_SUPPORT)
add_library(tiffxx ${tiffxx_SOURCES} ${tiffxx_HEADERS})
target_link_libraries(tiffxx tiff)
set_target_properties(tiffxx PROPERTIES SOVERSION ${SO_COMPATVERSION})
From 473851d211cf8805a161820337ca74cc9615d6ef Mon Sep 17 00:00:00 2001
From: Nathan Baker
Date: Tue, 6 Feb 2018 10:13:57 -0500
Subject: [PATCH 16/66] Fix for bug 2772
It is possible to craft a TIFF document where the IFD list is circular,
leading to an infinite loop while traversing the chain. The libtiff
directory reader has a failsafe that will break out of this loop after
reading 65535 directory entries, but it will continue processing,
consuming time and resources to process what is essentially a bogus TIFF
document.
This change fixes the above behavior by breaking out of processing when
a TIFF document has >= 65535 directories and terminating with an error.
---
contrib/addtiffo/tif_overview.c | 14 +++++++++++++-
tools/tiff2pdf.c | 10 ++++++++++
tools/tiffcrop.c | 13 +++++++++++--
3 files changed, 34 insertions(+), 3 deletions(-)
diff --git a/contrib/addtiffo/tif_overview.c b/contrib/addtiffo/tif_overview.c
index c61ffbb8..03b35733 100644
--- a/contrib/addtiffo/tif_overview.c
+++ b/contrib/addtiffo/tif_overview.c
@@ -65,6 +65,8 @@
# define MAX(a,b) ((a>b) ? a : b)
#endif
+#define TIFF_DIR_MAX 65534
+
void TIFFBuildOverviews( TIFF *, int, int *, int, const char *,
int (*)(double,void*), void * );
@@ -91,6 +93,7 @@ uint32 TIFF_WriteOverview( TIFF *hTIFF, uint32 nXSize, uint32 nYSize,
{
toff_t nBaseDirOffset;
toff_t nOffset;
+ tdir_t iNumDir;
(void) bUseSubIFDs;
@@ -147,7 +150,16 @@ uint32 TIFF_WriteOverview( TIFF *hTIFF, uint32 nXSize, uint32 nYSize,
return 0;
TIFFWriteDirectory( hTIFF );
- TIFFSetDirectory( hTIFF, (tdir_t) (TIFFNumberOfDirectories(hTIFF)-1) );
+ iNumDir = TIFFNumberOfDirectories(hTIFF);
+ if( iNumDir > TIFF_DIR_MAX )
+ {
+ TIFFErrorExt( TIFFClientdata(hTIFF),
+ "TIFF_WriteOverview",
+ "File `%s' has too many directories.\n",
+ TIFFFileName(hTIFF) );
+ exit(-1);
+ }
+ TIFFSetDirectory( hTIFF, (tdir_t) (iNumDir - 1) );
nOffset = TIFFCurrentDirOffset( hTIFF );
diff --git a/tools/tiff2pdf.c b/tools/tiff2pdf.c
index 984ef654..832a2475 100644
--- a/tools/tiff2pdf.c
+++ b/tools/tiff2pdf.c
@@ -68,6 +68,8 @@ extern int getopt(int, char**, char*);
#define PS_UNIT_SIZE 72.0F
+#define TIFF_DIR_MAX 65534
+
/* This type is of PDF color spaces. */
typedef enum {
T2P_CS_BILEVEL = 0x01, /* Bilevel, black and white */
@@ -1051,6 +1053,14 @@ void t2p_read_tiff_init(T2P* t2p, TIFF* input){
uint16* tiff_transferfunction[3];
directorycount=TIFFNumberOfDirectories(input);
+ if(directorycount > TIFF_DIR_MAX) {
+ TIFFError(
+ TIFF2PDF_MODULE,
+ "TIFF contains too many directories, %s",
+ TIFFFileName(input));
+ t2p->t2p_error = T2P_ERR_ERROR;
+ return;
+ }
t2p->tiff_pages = (T2P_PAGE*) _TIFFmalloc(TIFFSafeMultiply(tmsize_t,directorycount,sizeof(T2P_PAGE)));
if(t2p->tiff_pages==NULL){
TIFFError(
diff --git a/tools/tiffcrop.c b/tools/tiffcrop.c
index 91a38f67..e466dae6 100644
--- a/tools/tiffcrop.c
+++ b/tools/tiffcrop.c
@@ -215,6 +215,8 @@ extern int getopt(int argc, char * const argv[], const char *optstring);
#define DUMP_TEXT 1
#define DUMP_RAW 2
+#define TIFF_DIR_MAX 65534
+
/* Offsets into buffer for margins and fixed width and length segments */
struct offset {
uint32 tmargin;
@@ -2232,7 +2234,7 @@ main(int argc, char* argv[])
pageNum = -1;
else
total_images = 0;
- /* read multiple input files and write to output file(s) */
+ /* Read multiple input files and write to output file(s) */
while (optind < argc - 1)
{
in = TIFFOpen (argv[optind], "r");
@@ -2240,7 +2242,14 @@ main(int argc, char* argv[])
return (-3);
/* If only one input file is specified, we can use directory count */
- total_images = TIFFNumberOfDirectories(in);
+ total_images = TIFFNumberOfDirectories(in);
+ if (total_images > TIFF_DIR_MAX)
+ {
+ TIFFError (TIFFFileName(in), "File contains too many directories");
+ if (out != NULL)
+ (void) TIFFClose(out);
+ return (1);
+ }
if (image_count == 0)
{
dirnum = 0;
From 5347f0f731359807c6aa186d04cd57ae47c6dd62 Mon Sep 17 00:00:00 2001
From: Even Rouault
Date: Wed, 14 Feb 2018 15:39:32 +0100
Subject: [PATCH 17/66] Add warning about COMPRESSION_ZSTD not being officialy
registered
---
libtiff/tiff.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libtiff/tiff.h b/libtiff/tiff.h
index b0d49220..4c2f5adc 100644
--- a/libtiff/tiff.h
+++ b/libtiff/tiff.h
@@ -188,7 +188,7 @@ typedef enum {
#define COMPRESSION_SGILOG24 34677 /* SGI Log 24-bit packed */
#define COMPRESSION_JP2000 34712 /* Leadtools JPEG2000 */
#define COMPRESSION_LZMA 34925 /* LZMA2 */
-#define COMPRESSION_ZSTD 34926 /* ZSTD */
+#define COMPRESSION_ZSTD 34926 /* ZSTD: WARNING not registerd in Adobe-maintained registry */
#define TIFFTAG_PHOTOMETRIC 262 /* photometric interpretation */
#define PHOTOMETRIC_MINISWHITE 0 /* min value is white */
#define PHOTOMETRIC_MINISBLACK 1 /* min value is black */
From cad3e7d8754954becc7bd991049a4e79b334ed27 Mon Sep 17 00:00:00 2001
From: Even Rouault
Date: Wed, 14 Feb 2018 15:50:53 +0100
Subject: [PATCH 18/66] Typo fix in comment
---
libtiff/tif_jpeg.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libtiff/tif_jpeg.c b/libtiff/tif_jpeg.c
index 4f46698f..f2ddc331 100644
--- a/libtiff/tif_jpeg.c
+++ b/libtiff/tif_jpeg.c
@@ -74,7 +74,7 @@ int TIFFJPEGIsFullStripRequired_12(TIFF* tif);
"JPEGLib: JPEG parameter struct mismatch: library thinks size is 432,
caller expects 464"
- For such users we wil fix the problem here. See install.doc file from
+ For such users we will fix the problem here. See install.doc file from
the JPEG library distribution for details.
*/
From 642b8f998e80b7d2078a9a75dde678a48ada3ad8 Mon Sep 17 00:00:00 2001
From: Stefan Weil
Date: Sat, 24 Feb 2018 21:47:52 +0100
Subject: [PATCH 19/66] Fix some typos
Most of them were found by codespell.
Signed-off-by: Stefan Weil
---
ChangeLog | 20 ++++++++++----------
contrib/iptcutil/iptcutil.c | 2 +-
contrib/pds/README | 2 +-
contrib/pds/tif_imageiter.c | 6 +++---
contrib/pds/tif_imageiter.h | 2 +-
contrib/pds/tif_pdsdirread.c | 4 ++--
contrib/tags/README | 2 +-
contrib/tags/xtif_dir.c | 2 +-
contrib/win_dib/README.tiff2dib | 2 +-
contrib/win_dib/Tiffile.cpp | 4 ++--
html/addingtags.html | 4 ++--
html/bugs.html | 2 +-
html/build.html | 2 +-
html/libtiff.html | 2 +-
html/man/TIFFReadDirectory.3tiff.html | 8 ++++----
html/man/TIFFWriteDirectory.3tiff.html | 2 +-
html/man/TIFFmemory.3tiff.html | 2 +-
html/v3.5.3.html | 2 +-
html/v3.5.7.html | 2 +-
html/v3.6.0.html | 4 ++--
html/v3.6.1.html | 2 +-
html/v3.7.2.html | 2 +-
html/v3.7.3.html | 2 +-
html/v3.9.0.html | 2 +-
man/TIFFmemory.3tiff | 2 +-
tiff.spec | 2 +-
tools/thumbnail.c | 18 +++++++++---------
tools/tiff2ps.c | 10 +++++-----
tools/tiffcp.c | 4 ++--
tools/tiffcrop.c | 12 ++++++------
tools/tiffinfo.c | 2 +-
tools/tiffinfoce.c | 2 +-
32 files changed, 68 insertions(+), 68 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index ea8622b8..f9814391 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1849,7 +1849,7 @@
* libtiff/tif_jpeg.c: in JPEGFixupTags(), recognize SOF2, SOF9 and SOF10
markers to avoid emitting a warning (even if, according to the TechNote,
- there are admitedly unusual/not recommended or even forbidden variants, but
+ there are admittedly unusual/not recommended or even forbidden variants, but
they do work well with libjpeg for SOF2, and with libjpeg-turbo for SOF2,
SOF9 and SOF10).
Define in_color_space and input_components to the right values in
@@ -2432,7 +2432,7 @@
2012-05-19 Bob Friesenhahn
* man/TIFFGetField.3tiff: Correct the 'count' field type in the
- example for how to retreive the value of unsupported tags.
+ example for how to retrieve the value of unsupported tags.
2012-03-30 Frank Warmerdam
@@ -3039,7 +3039,7 @@
2010-04-21 Frank Warmerdam
- * libtiff/tif_jpeg.c: avoid preparing jpeg tables everytime
+ * libtiff/tif_jpeg.c: avoid preparing jpeg tables every time
JPEGSetupEncode() is called if the tables already seem to be
established. This prevents spurious updates and rewriting of
directories with jpegtables when doing updates to existing images.
@@ -3371,7 +3371,7 @@
* test/common.sh - start verbose mode after common settings.
- * libtiff/tif_dirinfo.c: Replace lfind() with local equivelent to
+ * libtiff/tif_dirinfo.c: Replace lfind() with local equivalent to
avoid type mismatches on different platforms.
http://bugzilla.maptools.org/show_bug.cgi?id=1889
@@ -3518,7 +3518,7 @@
* tools/tiffdump.c: When compiling for Microsoft Windows, apply
consistent (__int64) casting when testing if _lseeki64 has
- successfully seeked as requested. This is necessary for large
+ successfully sought as requested. This is necessary for large
file support to work since off_t is only 32-bit.
2008-07-29 Frank Warmerdam
@@ -4316,7 +4316,7 @@ btiff/tif_win32.c: Replace custom Win32 memory api with generic
* libtiff/tif_getimage.c: replaced usage of TIFFScanlineSize in
gtStripContig with TIFFNewScanlineSize so as to fix buggy behaviour
on subsampled images - this ought to get sorted when we feel brave
- enough to replace TIFFScanlineSize alltogether
+ enough to replace TIFFScanlineSize altogether
* libtiff/tif_ojpeg.c: fixed bug in OJPEGReadSkip
@@ -4974,7 +4974,7 @@ btiff/tif_win32.c: Replace custom Win32 memory api with generic
2005-06-03 Andrey Kiselev
- * libtiff/tif_open.c: Replace runtime endianess check with the compile
+ * libtiff/tif_open.c: Replace runtime endianness check with the compile
time one.
* libtiff/tif_predict.c: Floating point predictor now works on
@@ -6316,7 +6316,7 @@ btiff/tif_win32.c: Replace custom Win32 memory api with generic
2003-11-16 Andrey Kiselev
* libtiff/{tiff.h, tif_dirinfo.c}: Added support for IFD (13)
- datatype, intruduced in "Adobe PageMaker TIFF Tech. Notes".
+ datatype, introduced in "Adobe PageMaker TIFF Tech. Notes".
2003-11-15 Frank Warmerdam
@@ -6627,7 +6627,7 @@ btiff/tif_win32.c: Replace custom Win32 memory api with generic
* contrib/ojpeg/{Makefile.in, jdhuff.h, jinclude.h, ojpeg.c, README},
configure, Makefile.in: Improved libtiff compilation with OJPEG
- support. Now no need for patching IJG JPEG library, hack requred by
+ support. Now no need for patching IJG JPEG library, hack required by
libtiff will be compiled and used in-place. Implemented with
suggestion and help from Bill Allombert, Debian's libjpeg maintainer.
@@ -7485,7 +7485,7 @@ btiff/tif_win32.c: Replace custom Win32 memory api with generic
sizes. It fixes two problems:
Without scaling (-S) the fax is now centered on the page size specified
- with -H and/or -W. Before, fax2ps was using an obscure and practially
+ with -H and/or -W. Before, fax2ps was using an obscure and practically
useless algorithm to allocate the image relative to Letter sized paper
which sometime sled to useless whitespace on the paper, while at the
same time cutting of the faxes printable area at the opposite border.
diff --git a/contrib/iptcutil/iptcutil.c b/contrib/iptcutil/iptcutil.c
index ad0a79c5..621716df 100644
--- a/contrib/iptcutil/iptcutil.c
+++ b/contrib/iptcutil/iptcutil.c
@@ -782,7 +782,7 @@ int sindex(char ch,char *string)
char *cp;
for(cp=string;*cp;++cp)
if(ch==*cp)
- return (int)(cp-string); /* return postion of character */
+ return (int)(cp-string); /* return position of character */
return -1; /* eol ... no match found */
}
diff --git a/contrib/pds/README b/contrib/pds/README
index b9abc6b3..a36b0549 100644
--- a/contrib/pds/README
+++ b/contrib/pds/README
@@ -30,7 +30,7 @@ Your ReadRGBA() routine works well for reading many different formats
(TILED, STIP, compressed or not, etc.) of the most basic types of data
(RGB, 8-bit greyscale, 8-bit colormapped) into an SGI-style data array,
and serves as a good template for users with other needs. I used it as
-an exmaple of how to make an iterator which, rather than fill a data
+an example of how to make an iterator which, rather than fill a data
array, calls an arbitrary user-supplied callback function for each
"chunk" of data - that "chunk" might be a strip or a tile, and might
have one sample-per-pixel or two, and might be 8-bit data or 16-bit or
diff --git a/contrib/pds/tif_imageiter.c b/contrib/pds/tif_imageiter.c
index 9e7bd44a..243cfd65 100644
--- a/contrib/pds/tif_imageiter.c
+++ b/contrib/pds/tif_imageiter.c
@@ -114,7 +114,7 @@ TIFFImageIterBegin(TIFFImageIter* img, TIFF* tif, int stop, char emsg[1024])
TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "Missing required \"Colormap\" tag");
return (0);
}
- /* fall thru... */
+ /* fall through... */
case PHOTOMETRIC_MINISWHITE:
case PHOTOMETRIC_MINISBLACK:
/* This should work now so skip the check - BSR
@@ -181,7 +181,7 @@ TIFFImageIterBegin(TIFFImageIter* img, TIFF* tif, int stop, char emsg[1024])
case ORIENTATION_LEFTBOT: /* XXX */
TIFFWarning(TIFFFileName(tif), "using bottom-left orientation");
img->orientation = ORIENTATION_BOTLEFT;
- /* fall thru... */
+ /* fall through... */
case ORIENTATION_BOTLEFT:
break;
case ORIENTATION_TOPRIGHT:
@@ -190,7 +190,7 @@ TIFFImageIterBegin(TIFFImageIter* img, TIFF* tif, int stop, char emsg[1024])
default:
TIFFWarning(TIFFFileName(tif), "using top-left orientation");
img->orientation = ORIENTATION_TOPLEFT;
- /* fall thru... */
+ /* fall through... */
case ORIENTATION_TOPLEFT:
break;
}
diff --git a/contrib/pds/tif_imageiter.h b/contrib/pds/tif_imageiter.h
index e7dbe46c..4f4fd279 100644
--- a/contrib/pds/tif_imageiter.h
+++ b/contrib/pds/tif_imageiter.h
@@ -44,7 +44,7 @@ struct _TIFFImageIter {
uint16 samplesperpixel; /* image samples/pixel */
uint16 orientation; /* image orientation */
uint16 photometric; /* image photometric interp */
- uint16* redcmap; /* colormap pallete */
+ uint16* redcmap; /* colormap palette */
uint16* greencmap;
uint16* bluecmap;
/* get image data routine */
diff --git a/contrib/pds/tif_pdsdirread.c b/contrib/pds/tif_pdsdirread.c
index 567600c5..cc6231da 100644
--- a/contrib/pds/tif_pdsdirread.c
+++ b/contrib/pds/tif_pdsdirread.c
@@ -192,7 +192,7 @@ TIFFReadPrivateDataSubDirectory(TIFF* tif, toff_t pdir_offset,
* the fields to check type and tag information,
* and to extract info required to size data
* structures. A second pass is made afterwards
- * to read in everthing not taken in the first pass.
+ * to read in everything not taken in the first pass.
*/
td = &tif->tif_dir;
@@ -825,7 +825,7 @@ TIFFFetchNormalSubTag(TIFF* tif, TIFFDirEntry* dp, const TIFFFieldInfo* fip,
break;
}
}
- /* fall thru... */
+ /* fall through... */
case TIFF_LONG:
case TIFF_SLONG:
{ uint32 v32 =
diff --git a/contrib/tags/README b/contrib/tags/README
index 73c6c213..3220b7b1 100644
--- a/contrib/tags/README
+++ b/contrib/tags/README
@@ -2,7 +2,7 @@
NOTE: Sept/2004
The following described approach to managing tag extensions has been
-mostly superceeded since libtiff 3.6.0. The described approach requires
+mostly superseded since libtiff 3.6.0. The described approach requires
internal knowledge of the libtiff API and tends to be very fragile
in the face of libtiff upgrades.
diff --git a/contrib/tags/xtif_dir.c b/contrib/tags/xtif_dir.c
index e67a6abf..35295526 100644
--- a/contrib/tags/xtif_dir.c
+++ b/contrib/tags/xtif_dir.c
@@ -269,7 +269,7 @@ _XTIFFDefaultDirectory(TIFF *tif)
* Install into TIFF structure.
*/
TIFFMEMBER(tif,clientdir) = (tidata_t)xt;
- tif->tif_flags |= XTIFF_INITIALIZED; /* dont do this again! */
+ tif->tif_flags |= XTIFF_INITIALIZED; /* don't do this again! */
}
/* set up our own defaults */
diff --git a/contrib/win_dib/README.tiff2dib b/contrib/win_dib/README.tiff2dib
index 3e6075fb..ff70ca1a 100644
--- a/contrib/win_dib/README.tiff2dib
+++ b/contrib/win_dib/README.tiff2dib
@@ -40,7 +40,7 @@ it contain the function LoadTIFFinDIB that load
a TIFF file and build a memory DIB with it and return the
HANDLE (HDIB) of the memory bloc containing this DIB.
Since DIB is the "natural" bitmap format for Windows 3.1, 95 and NT,
-this function sould be usefull for some Windows 95 (or NT) developer.
+this function should be useful for some Windows 95 (or NT) developer.
Sorry for my approximate english ...
diff --git a/contrib/win_dib/Tiffile.cpp b/contrib/win_dib/Tiffile.cpp
index 9d958b1c..2f7965d6 100644
--- a/contrib/win_dib/Tiffile.cpp
+++ b/contrib/win_dib/Tiffile.cpp
@@ -360,7 +360,7 @@ setorientation(TIFFRGBAImage* img, uint32 h)
case ORIENTATION_LEFTBOT: /* XXX */
TIFFWarning(TIFFFileName(tif), "using bottom-left orientation");
img->orientation = ORIENTATION_BOTLEFT;
- /* fall thru... */
+ /* fall through... */
case ORIENTATION_BOTLEFT:
y = 0;
break;
@@ -370,7 +370,7 @@ setorientation(TIFFRGBAImage* img, uint32 h)
default:
TIFFWarning(TIFFFileName(tif), "using top-left orientation");
img->orientation = ORIENTATION_TOPLEFT;
- /* fall thru... */
+ /* fall through... */
case ORIENTATION_TOPLEFT:
y = h-1;
break;
diff --git a/html/addingtags.html b/html/addingtags.html
index 4e89205b..c61a2623 100644
--- a/html/addingtags.html
+++ b/html/addingtags.html
@@ -12,7 +12,7 @@ Defining New TIFF Tags
Libtiff has built-in knowledge of all the standard TIFF tags, as
-well as extentions. The following describes how to add knowledge of
+well as extensions. The following describes how to add knowledge of
new tags as builtins to libtiff, or how to application specific tags can
be used by applications without modifying libtiff.
@@ -113,7 +113,7 @@ their own tags to store information outside the core TIFF specification.
This is done by calling TIFFMergeFieldInfo() with one or more TIFFFieldInfos.
-The libgeotiff library provides geospatial information extentions within
+The libgeotiff library provides geospatial information extensions within
a TIFF file. First, a set of TIFFFieldInfo's is prepared with information
on the new tags:
diff --git a/html/bugs.html b/html/bugs.html
index 07fc78b8..643c3c6e 100644
--- a/html/bugs.html
+++ b/html/bugs.html
@@ -22,7 +22,7 @@ If you think you've discovered a bug, please first check to see if it is
already known by looking at the list of already reported bugs. You can do so
by visiting the buglist at
http://bugzilla.maptools.org/buglist.cgi?product=libtiff. Also verify that
-the problem is still reproducable with the current development software
+the problem is still reproducible with the current development software
from CVS.
If you'd like to enter a new bug, you can do so at
diff --git a/html/build.html b/html/build.html
index f52b0966..77fbc40b 100644
--- a/html/build.html
+++ b/html/build.html
@@ -689,7 +689,7 @@ libtiff/uvcode.h LogL/LogLuv codec-specific definitions
libtiff/version.h version string (generated by Makefile)
libtiff/tif_apple.c Apple-related OS support
libtiff/tif_atari.c Atari-related OS support
-libtiff/tif_aux.c auxilary directory-related functions
+libtiff/tif_aux.c auxiliary directory-related functions
libtiff/tif_close.c close an open TIFF file
libtiff/tif_codec.c configuration table of builtin codecs
libtiff/tif_compress.c compression scheme support
diff --git a/html/libtiff.html b/html/libtiff.html
index b1de7a27..9da85e3d 100644
--- a/html/libtiff.html
+++ b/html/libtiff.html
@@ -97,7 +97,7 @@
information.
The library include file <tiffio.h> contains a C pre-processor
define TIFFLIB_VERSION that can be used to check library
- version compatiblity at compile time.
+ version compatibility at compile time.
Library Datatypes
diff --git a/html/man/TIFFReadDirectory.3tiff.html b/html/man/TIFFReadDirectory.3tiff.html
index 1e32f7cd..5e4004db 100644
--- a/html/man/TIFFReadDirectory.3tiff.html
+++ b/html/man/TIFFReadDirectory.3tiff.html
@@ -151,23 +151,23 @@ specification. This error is not fatal.
unknown tag was encountered in the directory; the library
ignores all such tags.
-TIFF directory is missing requred
+
TIFF directory is missing required
"ImageLength" field. The image violates the
specification by not having a necessary field. There is no
way for the library to recover from this error.
-TIFF directory is missing requred
+
TIFF directory is missing required
"PlanarConfig" field. The image violates the
specification by not having a necessary field. There is no
way for the library to recover from this error.
-TIFF directory is missing requred
+
TIFF directory is missing required
"StripOffsets" field. The image has multiple
strips, but is missing the tag that specifies the file
offset to each strip of data. There is no way for the
library to recover from this error.
-TIFF directory is missing requred
+
TIFF directory is missing required
"TileOffsets" field. The image has multiple
tiles, but is missing the tag that specifies the file offset
to each tile of data. There is no way for the library to
diff --git a/html/man/TIFFWriteDirectory.3tiff.html b/html/man/TIFFWriteDirectory.3tiff.html
index 9aff8c4c..6483aa6a 100644
--- a/html/man/TIFFWriteDirectory.3tiff.html
+++ b/html/man/TIFFWriteDirectory.3tiff.html
@@ -69,7 +69,7 @@ have an established location in the file. It will rewrite
the directory, but instead of place it at it’s old
location (as TIFFWriteDirectory would) it will place
them at the end of the file, correcting the pointer from the
-preceeding directory or file header to point to it’s
+preceding directory or file header to point to it’s
new location. This is particularly important in cases where
the size of the directory and pointed to data has grown, so
it won’t fit in the space available at the old
diff --git a/html/man/TIFFmemory.3tiff.html b/html/man/TIFFmemory.3tiff.html
index 39fa7894..283be9bd 100644
--- a/html/man/TIFFmemory.3tiff.html
+++ b/html/man/TIFFmemory.3tiff.html
@@ -76,7 +76,7 @@ another memory location using _TIFFmemcpy, or
compared for equality using _TIFFmemcmp. These
routines conform to the equivalent ANSI C
routines: memset, memcpy, and memcmp,
-repsectively.
+respectively.
diff --git a/html/v3.5.3.html b/html/v3.5.3.html
index 78f46983..67da683e 100644
--- a/html/v3.5.3.html
+++ b/html/v3.5.3.html
@@ -49,7 +49,7 @@ From Burn All GIF's Day:
Unisys license to use LZW in free software that complies with the Open
Source Definition
-Unfortunatly, the removal of LZW compression means that saved image size has
+Unfortunately, the removal of LZW compression means that saved image size has
grown dramatically. Without a change in the TIFF spec to support
another lossless compression format, this is unavoidable.
diff --git a/html/v3.5.7.html b/html/v3.5.7.html
index 96f47916..d4285a8b 100644
--- a/html/v3.5.7.html
+++ b/html/v3.5.7.html
@@ -200,7 +200,7 @@ that corrects behaviour for non-Letter paper
sizes. (Bug 35) It fixes two problems:
Without scaling (-S) the fax is now centered on the page size specified
- with -H and/or -W. Before, fax2ps was using an obscure and practially
+ with -H and/or -W. Before, fax2ps was using an obscure and practically
useless algorithm to allocate the image relative to Letter sized paper
which sometime sled to useless whitespace on the paper, while at the
same time cutting of the faxes printable area at the opposite border.
diff --git a/html/v3.6.0.html b/html/v3.6.0.html
index c53cd155..affbe09a 100644
--- a/html/v3.6.0.html
+++ b/html/v3.6.0.html
@@ -64,12 +64,12 @@ TIFFDirectory structure would changing, breaking any dynamically linked
software that used the private data structures.
Also, any tag not recognised
-by libtiff would not be read and accessable to applications without some
+by libtiff would not be read and accessible to applications without some
fairly complicated work on the applications part to pre-register the tags
as exemplified by the support for "Geo"TIFF tags by libgeotiff layered on
libtiff.
-Amoung other things this approach required the extension code
+Among other things this approach required the extension code
to access the private libtiff structures ... which made the higher level
non-libtiff code be locked into a specific version of libtiff at compile time.
This caused no end of bug reports!
diff --git a/html/v3.6.1.html b/html/v3.6.1.html
index 3d6d838d..3e4e3fbc 100644
--- a/html/v3.6.1.html
+++ b/html/v3.6.1.html
@@ -116,7 +116,7 @@ Patch supplied by Ross Finlayson.
it was done in 3.6.0).
libtiff/{tiff.h, tif_dirinfo.c}: Added support for IFD (13) datatype,
-intruduced in "Adobe PageMaker TIFF Technical Notes".
+introduced in "Adobe PageMaker TIFF Technical Notes".
libtiff/{tif_color.c, tif_getimage.c, tiffio.h}: New color space
conversion code: CIE L*a*b* 1976 images now supported by the TIFFRGBAImage
diff --git a/html/v3.7.2.html b/html/v3.7.2.html
index 45347b72..1fa4cc8e 100644
--- a/html/v3.7.2.html
+++ b/html/v3.7.2.html
@@ -46,7 +46,7 @@ The following information is located here:
- - Maintainance release. Many bugfixes in the build environment
+
- Maintenance release. Many bugfixes in the build environment
and compatibility improvements.
diff --git a/html/v3.7.3.html b/html/v3.7.3.html
index 28981aef..771e1906 100644
--- a/html/v3.7.3.html
+++ b/html/v3.7.3.html
@@ -45,7 +45,7 @@ The following information is located here:
MAJOR CHANGES:
- - Replace runtime endianess check with the compile time one.
+
- Replace runtime endianness check with the compile time one.
- Added support for the new predictor type (floating point
predictor), defined at the TIFF Technical Note 3.
diff --git a/html/v3.9.0.html b/html/v3.9.0.html
index 1c8bf969..0e9ff9ae 100644
--- a/html/v3.9.0.html
+++ b/html/v3.9.0.html
@@ -154,7 +154,7 @@ information is located here:
- libtiff/tif_getimage.c,tiffio.h: removed all use of
UaToAa and Bitmap16to8 arrays in TIFFRGBAImage structure to
- restore ABI compatability. These were just an attempt to
+ restore ABI compatibility. These were just an attempt to
speed up processing with precalculated tables. http://bugzilla.maptools.org/show_bug.cgi?id=1979
diff --git a/man/TIFFmemory.3tiff b/man/TIFFmemory.3tiff
index 3947c86e..70a82123 100644
--- a/man/TIFFmemory.3tiff
+++ b/man/TIFFmemory.3tiff
@@ -77,7 +77,7 @@ C routines:
.IR memcpy ,
and
.IR memcmp ,
-repsectively.
+respectively.
.SH DIAGNOSTICS
None.
.SH "SEE ALSO"
diff --git a/tiff.spec b/tiff.spec
index 58ee3094..a94ec9f5 100644
--- a/tiff.spec
+++ b/tiff.spec
@@ -43,7 +43,7 @@ product tiff
exp "tiff.sw.tools"
endsubsys
subsys dev
- id "${TIFF_NAME} Developement Software"
+ id "${TIFF_NAME} Development Software"
exp "tiff.sw.dev"
endsubsys
endimage
diff --git a/tools/thumbnail.c b/tools/thumbnail.c
index 4e73df08..3d1adc78 100644
--- a/tools/thumbnail.c
+++ b/tools/thumbnail.c
@@ -525,15 +525,15 @@ setrow(uint8* row, uint32 nrows, const uint8* rows[])
default:
for (i = fw; i > 8; i--)
acc += bits[*src++];
- /* fall thru... */
- case 8: acc += bits[*src++]; /* fall thru */
- case 7: acc += bits[*src++]; /* fall thru */
- case 6: acc += bits[*src++]; /* fall thru */
- case 5: acc += bits[*src++]; /* fall thru */
- case 4: acc += bits[*src++]; /* fall thru */
- case 3: acc += bits[*src++]; /* fall thru */
- case 2: acc += bits[*src++]; /* fall thru */
- case 1: acc += bits[*src++]; /* fall thru */
+ /* fall through... */
+ case 8: acc += bits[*src++]; /* fall through */
+ case 7: acc += bits[*src++]; /* fall through */
+ case 6: acc += bits[*src++]; /* fall through */
+ case 5: acc += bits[*src++]; /* fall through */
+ case 4: acc += bits[*src++]; /* fall through */
+ case 3: acc += bits[*src++]; /* fall through */
+ case 2: acc += bits[*src++]; /* fall through */
+ case 1: acc += bits[*src++]; /* fall through */
case 0: break;
}
acc += bits[*src & mask1];
diff --git a/tools/tiff2ps.c b/tools/tiff2ps.c
index af62e4cc..d8d3da3a 100644
--- a/tools/tiff2ps.c
+++ b/tools/tiff2ps.c
@@ -61,7 +61,7 @@
* if not specified on the command line.
* Add new command line option to specify document creator
* as an alterntive to the string "tiff2ps" following model
- * of patch submitted by Thomas Jarosch for specifiying a
+ * of patch submitted by Thomas Jarosch for specifying a
* document title which is also supported now.
*
* 2009-Feb-11
@@ -71,7 +71,7 @@
* or landscape) if -h or -w is specified. Rotation is in
* degrees counterclockwise since that is how Postscript does
* it. The auto opption rotates the image 90 degrees ccw to
- * produce landscape if that is a better fit than portait.
+ * produce landscape if that is a better fit than portrait.
*
* Cleaned up code in TIFF2PS and broke into smaller functions
* to simplify rotations.
@@ -518,7 +518,7 @@ checkImage(TIFF* tif)
"PhotometricInterpretation=YCbCr");
return (0);
}
- /* fall thru... */
+ /* fall through... */
case PHOTOMETRIC_RGB:
if (alpha && bitspersample != 8) {
TIFFError(filename,
@@ -526,7 +526,7 @@ checkImage(TIFF* tif)
bitspersample);
return (0);
}
- /* fall thru... */
+ /* fall through... */
case PHOTOMETRIC_SEPARATED:
case PHOTOMETRIC_PALETTE:
case PHOTOMETRIC_MINISBLACK:
@@ -550,7 +550,7 @@ checkImage(TIFF* tif)
bitspersample = 8;
break;
case PHOTOMETRIC_CIELAB:
- /* fall thru... */
+ /* fall through... */
default:
TIFFError(filename,
"Can not handle image with PhotometricInterpretation=%d",
diff --git a/tools/tiffcp.c b/tools/tiffcp.c
index 482f5f4f..4638a905 100644
--- a/tools/tiffcp.c
+++ b/tools/tiffcp.c
@@ -657,7 +657,7 @@ tiffcp(TIFF* in, TIFF* out)
case ORIENTATION_RIGHTBOT: /* XXX */
TIFFWarning(TIFFFileName(in), "using bottom-left orientation");
orientation = ORIENTATION_BOTLEFT;
- /* fall thru... */
+ /* fall through... */
case ORIENTATION_LEFTBOT: /* XXX */
case ORIENTATION_BOTLEFT:
break;
@@ -666,7 +666,7 @@ tiffcp(TIFF* in, TIFF* out)
default:
TIFFWarning(TIFFFileName(in), "using top-left orientation");
orientation = ORIENTATION_TOPLEFT;
- /* fall thru... */
+ /* fall through... */
case ORIENTATION_LEFTTOP: /* XXX */
case ORIENTATION_TOPLEFT:
break;
diff --git a/tools/tiffcrop.c b/tools/tiffcrop.c
index e466dae6..a5e6061a 100644
--- a/tools/tiffcrop.c
+++ b/tools/tiffcrop.c
@@ -25,7 +25,7 @@
* ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE
* OR PERFORMANCE OF THIS SOFTWARE.
*
- * Some portions of the current code are derived from tiffcp, primarly in
+ * Some portions of the current code are derived from tiffcp, primarily in
* the areas of lowlevel reading and writing of TAGS, scanlines and tiles though
* some of the original functions have been extended to support arbitrary bit
* depths. These functions are presented at the top of this file.
@@ -1685,7 +1685,7 @@ void process_command_opts (int argc, char *argv[], char *mp, char *mode, uint32
*defconfig = PLANARCONFIG_CONTIG;
else
{
- TIFFError ("Unkown planar configuration", "%s", optarg);
+ TIFFError ("Unknown planar configuration", "%s", optarg);
TIFFError ("For valid options type", "tiffcrop -h");
exit (-1);
}
@@ -6782,12 +6782,12 @@ extractImageSection(struct image_data *image, struct pageseg *section,
#endif
bytebuff1 = bytebuff2 = 0;
- if (shift1 == 0) /* the region is byte and sample alligned */
+ if (shift1 == 0) /* the region is byte and sample aligned */
{
_TIFFmemcpy (sect_buff + dst_offset, src_buff + offset1, full_bytes);
#ifdef DEVELMODE
- TIFFError ("", " Alligned data src offset1: %8d, Dst offset: %8d\n", offset1, dst_offset);
+ TIFFError ("", " Aligned data src offset1: %8d, Dst offset: %8d\n", offset1, dst_offset);
sprintf(&bitarray[18], "\n");
sprintf(&bitarray[19], "\t");
for (j = 20, k = 7; j < 28; j++, k--)
@@ -7730,7 +7730,7 @@ createCroppedImage(struct image_data *image, struct crop_mask *crop,
* original code assumes we are always copying all samples.
* Use of global variables for config, compression and others
* should be replaced by addition to the crop_mask struct (which
- * will be renamed to proc_opts indicating that is controlls
+ * will be renamed to proc_opts indicating that is controls
* user supplied processing options, not just cropping) and
* then passed in as an argument.
*/
@@ -8425,7 +8425,7 @@ rotateImage(uint16 rotation, struct image_data *image, uint32 *img_width,
ibuff = *ibuff_ptr;
switch (rotation)
{
- case 180: if ((bps % 8) == 0) /* byte alligned data */
+ case 180: if ((bps % 8) == 0) /* byte aligned data */
{
src = ibuff;
pix_offset = (spp * bps) / 8;
diff --git a/tools/tiffinfo.c b/tools/tiffinfo.c
index aecbb91a..049e3a34 100644
--- a/tools/tiffinfo.c
+++ b/tools/tiffinfo.c
@@ -84,7 +84,7 @@ main(int argc, char* argv[])
break;
case 'd':
showdata++;
- /* fall thru... */
+ /* fall through... */
case 'D':
readdata++;
break;
diff --git a/tools/tiffinfoce.c b/tools/tiffinfoce.c
index 82ab330b..1822a550 100644
--- a/tools/tiffinfoce.c
+++ b/tools/tiffinfoce.c
@@ -73,7 +73,7 @@ main(int argc, char* argv[])
break;
case 'd':
showdata++;
- /* fall thru... */
+ /* fall through... */
case 'D':
readdata++;
break;
From 25840917ad378bc7accad791de981e052a8481f2 Mon Sep 17 00:00:00 2001
From: Even Rouault
Date: Sat, 3 Mar 2018 23:00:28 +0100
Subject: [PATCH 20/66] Avoid warning with gcc 8 (partially revert
647b0e8c11ee11896f319b92cf110775f538d75c)
---
libtiff/tiffiop.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libtiff/tiffiop.h b/libtiff/tiffiop.h
index b4c84a2a..2fe75565 100644
--- a/libtiff/tiffiop.h
+++ b/libtiff/tiffiop.h
@@ -312,7 +312,7 @@ typedef size_t TIFFIOSize_t;
#define _TIFF_off_t off_t
#endif
-#if defined(__has_attribute)
+#if defined(__has_attribute) && defined(__clang__)
#if __has_attribute(no_sanitize)
#define TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW __attribute__((no_sanitize("unsigned-integer-overflow")))
#else
From 277644d8a4c2723aaa7049cacd6c852f9a539335 Mon Sep 17 00:00:00 2001
From: Even Rouault
Date: Sat, 10 Mar 2018 14:07:02 +0100
Subject: [PATCH 21/66] Typo fix in comment
---
libtiff/tiff.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libtiff/tiff.h b/libtiff/tiff.h
index 4c2f5adc..9270c903 100644
--- a/libtiff/tiff.h
+++ b/libtiff/tiff.h
@@ -188,7 +188,7 @@ typedef enum {
#define COMPRESSION_SGILOG24 34677 /* SGI Log 24-bit packed */
#define COMPRESSION_JP2000 34712 /* Leadtools JPEG2000 */
#define COMPRESSION_LZMA 34925 /* LZMA2 */
-#define COMPRESSION_ZSTD 34926 /* ZSTD: WARNING not registerd in Adobe-maintained registry */
+#define COMPRESSION_ZSTD 34926 /* ZSTD: WARNING not registered in Adobe-maintained registry */
#define TIFFTAG_PHOTOMETRIC 262 /* photometric interpretation */
#define PHOTOMETRIC_MINISWHITE 0 /* min value is white */
#define PHOTOMETRIC_MINISBLACK 1 /* min value is black */
From 3719385a3fac5cfb20b487619a5f08abbf967cf8 Mon Sep 17 00:00:00 2001
From: Even Rouault
Date: Sun, 11 Mar 2018 11:14:01 +0100
Subject: [PATCH 22/66] ChopUpSingleUncompressedStrip: avoid memory exhaustion
(CVE-2017-11613)
In ChopUpSingleUncompressedStrip(), if the computed number of strips is big
enough and we are in read only mode, validate that the file size is consistent
with that number of strips to avoid useless attempts at allocating a lot of
memory for the td_stripbytecount and td_stripoffset arrays.
Fixes http://bugzilla.maptools.org/show_bug.cgi?id=2724
---
libtiff/tif_dirread.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/libtiff/tif_dirread.c b/libtiff/tif_dirread.c
index 3fc0c8e0..1a3259c1 100644
--- a/libtiff/tif_dirread.c
+++ b/libtiff/tif_dirread.c
@@ -5696,6 +5696,17 @@ ChopUpSingleUncompressedStrip(TIFF* tif)
if( nstrips == 0 )
return;
+ /* If we are going to allocate a lot of memory, make sure that the */
+ /* file is as big as needed */
+ if( tif->tif_mode == O_RDONLY &&
+ nstrips > 1000000 &&
+ (tif->tif_dir.td_stripoffset[0] >= TIFFGetFileSize(tif) ||
+ tif->tif_dir.td_stripbytecount[0] >
+ TIFFGetFileSize(tif) - tif->tif_dir.td_stripoffset[0]) )
+ {
+ return;
+ }
+
newcounts = (uint64*) _TIFFCheckMalloc(tif, nstrips, sizeof (uint64),
"for chopped \"StripByteCounts\" array");
newoffsets = (uint64*) _TIFFCheckMalloc(tif, nstrips, sizeof (uint64),
From a6214606661af40c852e9413f7d3ff5b118a5176 Mon Sep 17 00:00:00 2001
From: Even Rouault
Date: Tue, 13 Mar 2018 15:51:37 +0100
Subject: [PATCH 23/66] libtiff/tif_luv.c: rewrite loops in a more readable way
(to avoid false positive reports like
http://bugzilla.maptools.org/show_bug.cgi?id=2779)
---
libtiff/tif_luv.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/libtiff/tif_luv.c b/libtiff/tif_luv.c
index 266bb399..aa35ea07 100644
--- a/libtiff/tif_luv.c
+++ b/libtiff/tif_luv.c
@@ -213,7 +213,7 @@ LogL16Decode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s)
bp = (unsigned char*) tif->tif_rawcp;
cc = tif->tif_rawcc;
/* get each byte string */
- for (shft = 2*8; (shft -= 8) >= 0; ) {
+ for (shft = 8; shft >= 0; shft -=8) {
for (i = 0; i < npixels && cc > 0; ) {
if (*bp >= 128) { /* run */
if( cc < 2 )
@@ -347,7 +347,7 @@ LogLuvDecode32(TIFF* tif, uint8* op, tmsize_t occ, uint16 s)
bp = (unsigned char*) tif->tif_rawcp;
cc = tif->tif_rawcc;
/* get each byte string */
- for (shft = 4*8; (shft -= 8) >= 0; ) {
+ for (shft = 24; shft >= 0; shft -=8) {
for (i = 0; i < npixels && cc > 0; ) {
if (*bp >= 128) { /* run */
if( cc < 2 )
@@ -465,7 +465,7 @@ LogL16Encode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
/* compress each byte string */
op = tif->tif_rawcp;
occ = tif->tif_rawdatasize - tif->tif_rawcc;
- for (shft = 2*8; (shft -= 8) >= 0; )
+ for (shft = 8; shft >= 0; shft -=8) {
for (i = 0; i < npixels; i += rc) {
if (occ < 4) {
tif->tif_rawcp = op;
@@ -520,6 +520,7 @@ LogL16Encode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
} else
rc = 0;
}
+ }
tif->tif_rawcp = op;
tif->tif_rawcc = tif->tif_rawdatasize - occ;
@@ -616,7 +617,7 @@ LogLuvEncode32(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
/* compress each byte string */
op = tif->tif_rawcp;
occ = tif->tif_rawdatasize - tif->tif_rawcc;
- for (shft = 4*8; (shft -= 8) >= 0; )
+ for (shft = 24; shft >= 0; shft -=8) {
for (i = 0; i < npixels; i += rc) {
if (occ < 4) {
tif->tif_rawcp = op;
@@ -671,6 +672,7 @@ LogLuvEncode32(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
} else
rc = 0;
}
+ }
tif->tif_rawcp = op;
tif->tif_rawcc = tif->tif_rawdatasize - occ;
From 7a092f8af2568d61993a8cc2e7a35a998d7d37be Mon Sep 17 00:00:00 2001
From: Even Rouault
Date: Sat, 17 Mar 2018 09:36:29 +0100
Subject: [PATCH 24/66] ChopUpSingleUncompressedStrip: avoid memory exhaustion
(CVE-2017-11613)
Rework fix done in 3719385a3fac5cfb20b487619a5f08abbf967cf8 to work in more
cases like https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=6979.
Credit to OSS Fuzz
Fixes http://bugzilla.maptools.org/show_bug.cgi?id=2724
---
libtiff/tif_dirread.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/libtiff/tif_dirread.c b/libtiff/tif_dirread.c
index 1a3259c1..6baa7b31 100644
--- a/libtiff/tif_dirread.c
+++ b/libtiff/tif_dirread.c
@@ -5700,9 +5700,8 @@ ChopUpSingleUncompressedStrip(TIFF* tif)
/* file is as big as needed */
if( tif->tif_mode == O_RDONLY &&
nstrips > 1000000 &&
- (tif->tif_dir.td_stripoffset[0] >= TIFFGetFileSize(tif) ||
- tif->tif_dir.td_stripbytecount[0] >
- TIFFGetFileSize(tif) - tif->tif_dir.td_stripoffset[0]) )
+ (offset >= TIFFGetFileSize(tif) ||
+ stripbytes > (TIFFGetFileSize(tif) - offset) / (nstrips - 1)) )
{
return;
}
From 43586d41054121e4f0f4439eb4907fd12df6b99f Mon Sep 17 00:00:00 2001
From: Roger Leigh
Date: Wed, 7 Mar 2018 16:40:23 +0000
Subject: [PATCH 25/66] tiffset: Add support for LONG8, SLONG8 and IFD8 field
types
---
tools/tiffset.c | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/tools/tiffset.c b/tools/tiffset.c
index 9a75d910..7ecc401b 100644
--- a/tools/tiffset.c
+++ b/tools/tiffset.c
@@ -188,6 +188,9 @@ main(int argc, char* argv[])
size = 4;
break;
+ case TIFF_LONG8:
+ case TIFF_SLONG8:
+ case TIFF_IFD8:
case TIFF_DOUBLE:
size = 8;
break;
@@ -224,7 +227,16 @@ main(int argc, char* argv[])
case TIFF_SLONG:
case TIFF_IFD:
for (i = 0; i < wc; i++)
- ((uint32 *)array)[i] = atol(argv[arg_index+i]);
+ ((int32 *)array)[i] = atol(argv[arg_index+i]);
+ break;
+ case TIFF_LONG8:
+ for (i = 0; i < wc; i++)
+ ((uint64 *)array)[i] = strtoll(argv[arg_index+i], (char **)NULL, 10);
+ break;
+ case TIFF_SLONG8:
+ case TIFF_IFD8:
+ for (i = 0; i < wc; i++)
+ ((int64 *)array)[i] = strtoll(argv[arg_index+i], (char **)NULL, 10);
break;
case TIFF_DOUBLE:
for (i = 0; i < wc; i++)
@@ -275,6 +287,12 @@ main(int argc, char* argv[])
ret = TIFFSetField(tiff, TIFFFieldTag(fip),
atol(argv[arg_index++]));
break;
+ case TIFF_LONG8:
+ case TIFF_SLONG8:
+ case TIFF_IFD8:
+ ret = TIFFSetField(tiff, TIFFFieldTag(fip),
+ strtoll(argv[arg_index++], (char **)NULL, 10));
+ break;
case TIFF_DOUBLE:
ret = TIFFSetField(tiff, TIFFFieldTag(fip),
atof(argv[arg_index++]));
From 14f304998ef89f8ed7a15e72458467f9c23539a7 Mon Sep 17 00:00:00 2001
From: Roger Leigh
Date: Fri, 23 Mar 2018 11:45:16 +0000
Subject: [PATCH 26/66] port: Add strtol, strtoll and strtoull
Also update strtoul. All use the same implementation from NetBSD libc.
---
CMakeLists.txt | 5 +-
configure.ac | 6 +-
libtiff/tif_config.h.cmake.in | 9 ++
libtiff/tif_config.h.in | 9 ++
port/CMakeLists.txt | 14 ++-
port/Makefile.am | 4 +-
port/_strtol.h | 213 ++++++++++++++++++++++++++++++++++
port/_strtoul.h | 176 ++++++++++++++++++++++++++++
port/libport.h | 11 +-
port/strtol.c | 44 +++++++
port/strtoll.c | 44 +++++++
port/strtoul.c | 94 +++------------
port/strtoull.c | 43 +++++++
13 files changed, 587 insertions(+), 85 deletions(-)
create mode 100644 port/_strtol.h
create mode 100644 port/_strtoul.h
create mode 100644 port/strtol.c
create mode 100644 port/strtoll.c
create mode 100644 port/strtoull.c
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0ee6f6a2..e6ba7fdf 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -387,7 +387,10 @@ check_symbol_exists(mmap "sys/mman.h" HAVE_MMAP)
check_symbol_exists(setmode "unistd.h" HAVE_SETMODE)
check_symbol_exists(snprintf "stdio.h" HAVE_SNPRINTF)
check_symbol_exists(strcasecmp "strings.h" HAVE_STRCASECMP)
-check_symbol_exists(strtol "stdlib.h" HAVE_STRTOUL)
+check_symbol_exists(strtol "stdlib.h" HAVE_STRTOL)
+check_symbol_exists(strtoll "stdlib.h" HAVE_STRTOLL)
+check_symbol_exists(strtoul "stdlib.h" HAVE_STRTOUL)
+check_symbol_exists(strtoull "stdlib.h" HAVE_STRTOULL)
check_symbol_exists(getopt "unistd.h" HAVE_GETOPT)
check_symbol_exists(lfind "search.h" HAVE_LFIND)
diff --git a/configure.ac b/configure.ac
index 5d9e25d0..bc5dbef5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -407,14 +407,16 @@ AC_DEFINE_UNQUOTED(TIFF_PTRDIFF_T,$PTRDIFF_T,[Pointer difference type])
AC_DEFINE_UNQUOTED(TIFF_PTRDIFF_FORMAT,$PTRDIFF_FORMAT,[Pointer difference type formatter])
dnl Checks for library functions.
-AC_CHECK_FUNCS([mmap setmode snprintf \
-strtoul])
+AC_CHECK_FUNCS([mmap setmode snprintf])
dnl Will use local replacements for unavailable functions
AC_REPLACE_FUNCS(getopt)
AC_REPLACE_FUNCS(snprintf)
AC_REPLACE_FUNCS(strcasecmp)
+AC_REPLACE_FUNCS(strtol)
+AC_REPLACE_FUNCS(strtoll)
AC_REPLACE_FUNCS(strtoul)
+AC_REPLACE_FUNCS(strtoull)
AC_REPLACE_FUNCS(lfind)
dnl ---------------------------------------------------------------------------
diff --git a/libtiff/tif_config.h.cmake.in b/libtiff/tif_config.h.cmake.in
index cbbcf825..dddb8b27 100644
--- a/libtiff/tif_config.h.cmake.in
+++ b/libtiff/tif_config.h.cmake.in
@@ -83,9 +83,18 @@
/* Define to 1 if you have the header file. */
#cmakedefine HAVE_STRING_H 1
+/* Define to 1 if you have the `strtol' function. */
+#cmakedefine HAVE_STRTOL 1
+
+/* Define to 1 if you have the `strtoll' function. */
+#cmakedefine HAVE_STRTOLL 1
+
/* Define to 1 if you have the `strtoul' function. */
#cmakedefine HAVE_STRTOUL 1
+/* Define to 1 if you have the `strtoull' function. */
+#cmakedefine HAVE_STRTOULL 1
+
/* Define to 1 if you have the header file. */
#cmakedefine HAVE_SYS_TIME_H 1
diff --git a/libtiff/tif_config.h.in b/libtiff/tif_config.h.in
index 789150db..ed1e80fc 100644
--- a/libtiff/tif_config.h.in
+++ b/libtiff/tif_config.h.in
@@ -107,9 +107,18 @@
/* Define to 1 if you have the header file. */
#undef HAVE_STRING_H
+/* Define to 1 if you have the `strtol' function. */
+#undef HAVE_STRTOL
+
+/* Define to 1 if you have the `strtoll' function. */
+#undef HAVE_STRTOLL
+
/* Define to 1 if you have the `strtoul' function. */
#undef HAVE_STRTOUL
+/* Define to 1 if you have the `strtoull' function. */
+#undef HAVE_STRTOULL
+
/* Define to 1 if you have the header file. */
#undef HAVE_SYS_STAT_H
diff --git a/port/CMakeLists.txt b/port/CMakeLists.txt
index 439fb3d7..b7eb3a29 100644
--- a/port/CMakeLists.txt
+++ b/port/CMakeLists.txt
@@ -28,7 +28,10 @@ set(port_optional_SOURCES
getopt.c
lfind.c
strcasecmp.c
- strtoul.c)
+ strtol.c
+ strtoll.c
+ strtoul.c
+ strtoull.c)
set(port_USED_FILES ${port_SOURCES} ${port_HEADERS})
@@ -44,9 +47,18 @@ endif()
if(NOT HAVE_STRCASECMP)
list(APPEND port_USED_FILES strcasecmp.c)
endif()
+if(NOT HAVE_STRTOL)
+ list(APPEND port_USED_FILES strtol.c)
+endif()
+if(NOT HAVE_STRTOLL)
+ list(APPEND port_USED_FILES strtoll.c)
+endif()
if(NOT HAVE_STRTOUL)
list(APPEND port_USED_FILES strtoul.c)
endif()
+if(NOT HAVE_STRTOULL)
+ list(APPEND port_USED_FILES strtoull.c)
+endif()
add_library(port STATIC ${port_USED_FILES})
diff --git a/port/Makefile.am b/port/Makefile.am
index 4d6e11d0..250479fe 100644
--- a/port/Makefile.am
+++ b/port/Makefile.am
@@ -27,7 +27,9 @@ EXTRA_DIST = \
CMakeLists.txt \
Makefile.vc \
libport.h \
- snprintf.c
+ snprintf.c \
+ _strtol.h \
+ _strtoul.h
noinst_LTLIBRARIES = libport.la
libport_la_SOURCES = dummy.c libport.h
diff --git a/port/_strtol.h b/port/_strtol.h
new file mode 100644
index 00000000..51c71490
--- /dev/null
+++ b/port/_strtol.h
@@ -0,0 +1,213 @@
+/* $NetBSD: _strtol.h,v 1.11 2017/07/06 21:08:44 joerg Exp $ */
+
+/*-
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * Original version ID:
+ * NetBSD: src/lib/libc/locale/_wcstol.h,v 1.2 2003/08/07 16:43:03 agc Exp
+ */
+
+/*
+ * function template for strtol, strtoll and strtoimax.
+ *
+ * parameters:
+ * _FUNCNAME : function name
+ * __INT : return type
+ * __INT_MIN : lower limit of the return type
+ * __INT_MAX : upper limit of the return type
+ */
+#if defined(_KERNEL) || defined(_STANDALONE) || defined(HAVE_NBTOOL_CONFIG_H) || defined(BCS_ONLY)
+__INT
+_FUNCNAME(const char *nptr, char **endptr, int base)
+#else
+#include
+#include "setlocale_local.h"
+#define INT_FUNCNAME_(pre, name, post) pre ## name ## post
+#define INT_FUNCNAME(pre, name, post) INT_FUNCNAME_(pre, name, post)
+
+static __INT
+INT_FUNCNAME(_int_, _FUNCNAME, _l)(const char *nptr, char **endptr,
+ int base, locale_t loc)
+#endif
+{
+ const char *s;
+ __INT acc, cutoff;
+ unsigned char c;
+ int i, neg, any, cutlim;
+
+ _DIAGASSERT(nptr != NULL);
+ /* endptr may be NULL */
+
+ /* check base value */
+ if (base && (base < 2 || base > 36)) {
+#if !defined(_KERNEL) && !defined(_STANDALONE)
+ errno = EINVAL;
+ if (endptr != NULL)
+ /* LINTED interface specification */
+ *endptr = __UNCONST(nptr);
+ return 0;
+#else
+ panic("%s: invalid base %d", __func__, base);
+#endif
+ }
+
+ /*
+ * Skip white space and pick up leading +/- sign if any.
+ * If base is 0, allow 0x for hex and 0 for octal, else
+ * assume decimal; if base is already 16, allow 0x.
+ */
+ s = nptr;
+#if defined(_KERNEL) || defined(_STANDALONE) || \
+ defined(HAVE_NBTOOL_CONFIG_H) || defined(BCS_ONLY)
+ do {
+ c = *s++;
+ } while (isspace(c));
+#else
+ do {
+ c = *s++;
+ } while (isspace_l(c, loc));
+#endif
+ if (c == '-') {
+ neg = 1;
+ c = *s++;
+ } else {
+ neg = 0;
+ if (c == '+')
+ c = *s++;
+ }
+ if ((base == 0 || base == 16) &&
+ c == '0' && (*s == 'x' || *s == 'X') &&
+ ((s[1] >= '0' && s[1] <= '9') ||
+ (s[1] >= 'a' && s[1] <= 'f') ||
+ (s[1] >= 'A' && s[1] <= 'F'))) {
+ c = s[1];
+ s += 2;
+ base = 16;
+#if 0
+ } else if ((base == 0 || base == 2) &&
+ c == '0' && (*s == 'b' || *s == 'B') &&
+ (s[1] >= '0' && s[1] <= '1')) {
+ c = s[1];
+ s += 2;
+ base = 2;
+#endif
+ } else if (base == 0)
+ base = (c == '0' ? 8 : 10);
+
+ /*
+ * Compute the cutoff value between legal numbers and illegal
+ * numbers. That is the largest legal value, divided by the
+ * base. An input number that is greater than this value, if
+ * followed by a legal input character, is too big. One that
+ * is equal to this value may be valid or not; the limit
+ * between valid and invalid numbers is then based on the last
+ * digit. For instance, if the range for longs is
+ * [-2147483648..2147483647] and the input base is 10,
+ * cutoff will be set to 214748364 and cutlim to either
+ * 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated
+ * a value > 214748364, or equal but the next digit is > 7 (or 8),
+ * the number is too big, and we will return a range error.
+ *
+ * Set any if any `digits' consumed; make it negative to indicate
+ * overflow.
+ */
+ cutoff = (__INT)(neg ? __INT_MIN : __INT_MAX);
+ cutlim = (int)(cutoff % base);
+ cutoff /= base;
+ if (neg) {
+ if (cutlim > 0) {
+ cutlim -= base;
+ cutoff += 1;
+ }
+ cutlim = -cutlim;
+ }
+ for (acc = 0, any = 0;; c = *s++) {
+ if (c >= '0' && c <= '9')
+ i = c - '0';
+ else if (c >= 'a' && c <= 'z')
+ i = (c - 'a') + 10;
+ else if (c >= 'A' && c <= 'Z')
+ i = (c - 'A') + 10;
+ else
+ break;
+ if (i >= base)
+ break;
+ if (any < 0)
+ continue;
+ if (neg) {
+ if (acc < cutoff || (acc == cutoff && i > cutlim)) {
+ acc = __INT_MIN;
+#if !defined(_KERNEL) && !defined(_STANDALONE)
+ any = -1;
+ errno = ERANGE;
+#else
+ any = 0;
+ break;
+#endif
+ } else {
+ any = 1;
+ acc *= base;
+ acc -= i;
+ }
+ } else {
+ if (acc > cutoff || (acc == cutoff && i > cutlim)) {
+ acc = __INT_MAX;
+#if !defined(_KERNEL) && !defined(_STANDALONE)
+ any = -1;
+ errno = ERANGE;
+#else
+ any = 0;
+ break;
+#endif
+ } else {
+ any = 1;
+ acc *= base;
+ acc += i;
+ }
+ }
+ }
+ if (endptr != NULL)
+ /* LINTED interface specification */
+ *endptr = __UNCONST(any ? s - 1 : nptr);
+ return(acc);
+}
+
+#if !defined(_KERNEL) && !defined(_STANDALONE) && \
+ !defined(HAVE_NBTOOL_CONFIG_H) && !defined(BCS_ONLY)
+__INT
+_FUNCNAME(const char *nptr, char **endptr, int base)
+{
+ return INT_FUNCNAME(_int_, _FUNCNAME, _l)(nptr, endptr, base, _current_locale());
+}
+
+__INT
+INT_FUNCNAME(, _FUNCNAME, _l)(const char *nptr, char **endptr, int base, locale_t loc)
+{
+ return INT_FUNCNAME(_int_, _FUNCNAME, _l)(nptr, endptr, base, loc);
+}
+#endif
diff --git a/port/_strtoul.h b/port/_strtoul.h
new file mode 100644
index 00000000..9b948fb9
--- /dev/null
+++ b/port/_strtoul.h
@@ -0,0 +1,176 @@
+/* $NetBSD: _strtoul.h,v 1.11 2017/07/06 21:08:44 joerg Exp $ */
+
+/*-
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * Original version ID:
+ * NetBSD: src/lib/libc/locale/_wcstoul.h,v 1.2 2003/08/07 16:43:03 agc Exp
+ */
+
+/*
+ * function template for strtoul, strtoull and strtoumax.
+ *
+ * parameters:
+ * _FUNCNAME : function name
+ * __UINT : return type
+ * __UINT_MAX : upper limit of the return type
+ */
+#if defined(_KERNEL) || defined(_STANDALONE) || \
+ defined(HAVE_NBTOOL_CONFIG_H) || defined(BCS_ONLY)
+__UINT
+_FUNCNAME(const char *nptr, char **endptr, int base)
+#else
+#include
+#include "setlocale_local.h"
+#define INT_FUNCNAME_(pre, name, post) pre ## name ## post
+#define INT_FUNCNAME(pre, name, post) INT_FUNCNAME_(pre, name, post)
+
+static __UINT
+INT_FUNCNAME(_int_, _FUNCNAME, _l)(const char *nptr, char **endptr,
+ int base, locale_t loc)
+#endif
+{
+ const char *s;
+ __UINT acc, cutoff;
+ unsigned char c;
+ int i, neg, any, cutlim;
+
+ _DIAGASSERT(nptr != NULL);
+ /* endptr may be NULL */
+
+ /* check base value */
+ if (base && (base < 2 || base > 36)) {
+#if !defined(_KERNEL) && !defined(_STANDALONE)
+ errno = EINVAL;
+ if (endptr != NULL)
+ /* LINTED interface specification */
+ *endptr = __UNCONST(nptr);
+ return 0;
+#else
+ panic("%s: invalid base %d", __func__, base);
+#endif
+ }
+
+ /*
+ * Skip white space and pick up leading +/- sign if any.
+ * If base is 0, allow 0x for hex and 0 for octal, else
+ * assume decimal; if base is already 16, allow 0x.
+ */
+ s = nptr;
+#if defined(_KERNEL) || defined(_STANDALONE) || \
+ defined(HAVE_NBTOOL_CONFIG_H) || defined(BCS_ONLY)
+ do {
+ c = *s++;
+ } while (isspace(c));
+#else
+ do {
+ c = *s++;
+ } while (isspace_l(c, loc));
+#endif
+ if (c == '-') {
+ neg = 1;
+ c = *s++;
+ } else {
+ neg = 0;
+ if (c == '+')
+ c = *s++;
+ }
+ if ((base == 0 || base == 16) &&
+ c == '0' && (*s == 'x' || *s == 'X') &&
+ ((s[1] >= '0' && s[1] <= '9') ||
+ (s[1] >= 'a' && s[1] <= 'f') ||
+ (s[1] >= 'A' && s[1] <= 'F'))) {
+ c = s[1];
+ s += 2;
+ base = 16;
+#if 0
+ } else if ((base == 0 || base == 2) &&
+ c == '0' && (*s == 'b' || *s == 'B') &&
+ (s[1] >= '0' && s[1] <= '1')) {
+ c = s[1];
+ s += 2;
+ base = 2;
+#endif
+ } else if (base == 0)
+ base = (c == '0' ? 8 : 10);
+
+ /*
+ * See strtol for comments as to the logic used.
+ */
+ cutoff = ((__UINT)__UINT_MAX / (__UINT)base);
+ cutlim = (int)((__UINT)__UINT_MAX % (__UINT)base);
+ for (acc = 0, any = 0;; c = *s++) {
+ if (c >= '0' && c <= '9')
+ i = c - '0';
+ else if (c >= 'a' && c <= 'z')
+ i = (c - 'a') + 10;
+ else if (c >= 'A' && c <= 'Z')
+ i = (c - 'A') + 10;
+ else
+ break;
+ if (i >= base)
+ break;
+ if (any < 0)
+ continue;
+ if (acc > cutoff || (acc == cutoff && i > cutlim)) {
+ acc = __UINT_MAX;
+#if !defined(_KERNEL) && !defined(_STANDALONE)
+ any = -1;
+ errno = ERANGE;
+#else
+ any = 0;
+ break;
+#endif
+ } else {
+ any = 1;
+ acc *= (__UINT)base;
+ acc += i;
+ }
+ }
+ if (neg && any > 0)
+ acc = -acc;
+ if (endptr != NULL)
+ /* LINTED interface specification */
+ *endptr = __UNCONST(any ? s - 1 : nptr);
+ return(acc);
+}
+
+#if !defined(_KERNEL) && !defined(_STANDALONE) && \
+ !defined(HAVE_NBTOOL_CONFIG_H) && !defined(BCS_ONLY)
+__UINT
+_FUNCNAME(const char *nptr, char **endptr, int base)
+{
+ return INT_FUNCNAME(_int_, _FUNCNAME, _l)(nptr, endptr, base, _current_locale());
+}
+
+__UINT
+INT_FUNCNAME(, _FUNCNAME, _l)(const char *nptr, char **endptr, int base, locale_t loc)
+{
+ return INT_FUNCNAME(_int_, _FUNCNAME, _l)(nptr, endptr, base, loc);
+}
+#endif
diff --git a/port/libport.h b/port/libport.h
index 53ea3418..ff262638 100644
--- a/port/libport.h
+++ b/port/libport.h
@@ -36,9 +36,18 @@ int strcasecmp(const char *s1, const char *s2);
# define HAVE_GETOPT 1
#endif
-#if 0
+#if HAVE_STRTOL
+long strtol(const char *nptr, char **endptr, int base);
+#endif
+#if HAVE_STRTOLL
+long long strtoll(const char *nptr, char **endptr, int base);
+#endif
+#if HAVE_STRTOUL
unsigned long strtoul(const char *nptr, char **endptr, int base);
#endif
+#if HAVE_STRTOULL
+unsigned long long strtoull(const char *nptr, char **endptr, int base);
+#endif
#if 0
void *
diff --git a/port/strtol.c b/port/strtol.c
new file mode 100644
index 00000000..8c5d7b42
--- /dev/null
+++ b/port/strtol.c
@@ -0,0 +1,44 @@
+/* $NetBSD: strtol.c,v 1.18 2008/08/20 12:42:26 joerg Exp $ */
+
+/*-
+ * Copyright (c) 2005 The DragonFly Project. All rights reserved.
+ * Copyright (c) 2003 Citrus Project,
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+__RCSID("$NetBSD: strtol.c,v 1.18 2008/08/20 12:42:26 joerg Exp $");
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+#define _FUNCNAME strtol
+#define __INT long
+#define __INT_MIN LONG_MIN
+#define __INT_MAX LONG_MAX
+
+#include "_strtol.h"
diff --git a/port/strtoll.c b/port/strtoll.c
new file mode 100644
index 00000000..9a8c611d
--- /dev/null
+++ b/port/strtoll.c
@@ -0,0 +1,44 @@
+/* $NetBSD: strtol.c,v 1.18 2008/08/20 12:42:26 joerg Exp $ */
+
+/*-
+ * Copyright (c) 2005 The DragonFly Project. All rights reserved.
+ * Copyright (c) 2003 Citrus Project,
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+__RCSID("$NetBSD: strtol.c,v 1.18 2008/08/20 12:42:26 joerg Exp $");
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+#define _FUNCNAME strtoll
+#define __INT long long
+#define __INT_MIN LLONG_MIN
+#define __INT_MAX LLONG_MAX
+
+#include "_strtol.h"
diff --git a/port/strtoul.c b/port/strtoul.c
index 4439de78..0d3d2538 100644
--- a/port/strtoul.c
+++ b/port/strtoul.c
@@ -1,6 +1,9 @@
-/*
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
+/* $NetBSD: strtoul.c,v 1.3 2008/08/20 19:58:34 oster Exp $ */
+
+/*-
+ * Copyright (c) 2005 The DragonFly Project. All rights reserved.
+ * Copyright (c) 2003 Citrus Project,
+ * All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -10,14 +13,11 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
*
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
@@ -27,81 +27,17 @@
* SUCH DAMAGE.
*/
-#if 0
-static char sccsid[] = "@(#)strtoul.c 8.1 (Berkeley) 6/4/93";
-__RCSID("$NetBSD: strtoul.c,v 1.16 2003/08/07 16:43:45 agc Exp $");
-#endif
+__RCSID("$NetBSD: strtoul.c,v 1.3 2008/08/20 19:58:34 oster Exp $");
+#include
#include
#include
#include
+#include
#include
-/*
- * Convert a string to an unsigned long integer.
- *
- * Ignores `locale' stuff. Assumes that the upper and lower case
- * alphabets and digits are each contiguous.
- */
-unsigned long
-strtoul(const char *nptr, char **endptr, int base)
-{
- const char *s;
- unsigned long acc, cutoff;
- int c;
- int neg, any, cutlim;
+#define _FUNCNAME strtoul
+#define __UINT unsigned long int
+#define __UINT_MAX ULONG_MAX
- /*
- * See strtol for comments as to the logic used.
- */
- s = nptr;
- do {
- c = (unsigned char) *s++;
- } while (isspace(c));
- if (c == '-') {
- neg = 1;
- c = *s++;
- } else {
- neg = 0;
- if (c == '+')
- c = *s++;
- }
- if ((base == 0 || base == 16) &&
- c == '0' && (*s == 'x' || *s == 'X')) {
- c = s[1];
- s += 2;
- base = 16;
- }
- if (base == 0)
- base = c == '0' ? 8 : 10;
-
- cutoff = ULONG_MAX / (unsigned long)base;
- cutlim = (int)(ULONG_MAX % (unsigned long)base);
- for (acc = 0, any = 0;; c = (unsigned char) *s++) {
- if (isdigit(c))
- c -= '0';
- else if (isalpha(c))
- c -= isupper(c) ? 'A' - 10 : 'a' - 10;
- else
- break;
- if (c >= base)
- break;
- if (any < 0)
- continue;
- if (acc > cutoff || (acc == cutoff && c > cutlim)) {
- any = -1;
- acc = ULONG_MAX;
- errno = ERANGE;
- } else {
- any = 1;
- acc *= (unsigned long)base;
- acc += c;
- }
- }
- if (neg && any > 0)
- acc = -acc;
- if (endptr != 0)
- /* LINTED interface specification */
- *endptr = (char *)(any ? s - 1 : nptr);
- return (acc);
-}
+#include "_strtoul.h"
diff --git a/port/strtoull.c b/port/strtoull.c
new file mode 100644
index 00000000..29435f50
--- /dev/null
+++ b/port/strtoull.c
@@ -0,0 +1,43 @@
+/* $NetBSD: strtoul.c,v 1.3 2008/08/20 19:58:34 oster Exp $ */
+
+/*-
+ * Copyright (c) 2005 The DragonFly Project. All rights reserved.
+ * Copyright (c) 2003 Citrus Project,
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+__RCSID("$NetBSD: strtoul.c,v 1.3 2008/08/20 19:58:34 oster Exp $");
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+#define _FUNCNAME strtoull
+#define __UINT unsigned long long int
+#define __UINT_MAX ULLONG_MAX
+
+#include "_strtoul.h"
From bf5a45de679b25f8a9d0f22f34dbeeac1b5dce07 Mon Sep 17 00:00:00 2001
From: Roger Leigh
Date: Fri, 23 Mar 2018 23:18:09 +0000
Subject: [PATCH 27/66] port: Clean up NetBSD sources and headers to build
standalone
---
.appveyor.yml | 7 ++++++
port/_strtol.h | 63 ++++---------------------------------------------
port/_strtoul.h | 59 ++++-----------------------------------------
port/strtol.c | 3 ++-
port/strtoll.c | 4 ++--
port/strtoul.c | 3 ++-
port/strtoull.c | 3 ++-
7 files changed, 25 insertions(+), 117 deletions(-)
diff --git a/.appveyor.yml b/.appveyor.yml
index f469afe4..bcc0d1a0 100644
--- a/.appveyor.yml
+++ b/.appveyor.yml
@@ -32,6 +32,10 @@ environment:
shared: OFF
- compiler: vc14-nmake
configuration: Release
+ - compiler: vc9-cmake
+ configuration: Debug
+ generator: Visual Studio 9 2008
+ shared: ON
cache:
- 'c:\projects\download -> appveyor.yml'
@@ -68,6 +72,7 @@ before_build:
- 'if %compiler%==cygwin-cmake bash -c "cmake -G \"%generator%\" -DCMAKE_INSTALL_PREFIX:PATH=%AV_TIFF_CMAKE_INSTALL% -DCMAKE_BUILD_TYPE=%configuration% %AV_CMAKE_ARGS% %AV_TIFF_CMAKE_SOURCE%"'
- 'if %compiler%==mingw64-cmake cmake -G "%generator%" -DCMAKE_INSTALL_PREFIX:PATH=%AV_TIFF_CMAKE_INSTALL% -DCMAKE_BUILD_TYPE=%configuration% %AV_CMAKE_ARGS% %AV_TIFF_CMAKE_SOURCE%'
- 'if %compiler%==vc14-cmake cmake -G "%generator%" -DCMAKE_INSTALL_PREFIX:PATH=%AV_TIFF_CMAKE_INSTALL% -DCMAKE_BUILD_TYPE=%configuration% %AV_CMAKE_ARGS% %AV_TIFF_CMAKE_SOURCE%'
+ - 'if %compiler%==vc9-cmake cmake -G "%generator%" -DCMAKE_INSTALL_PREFIX:PATH=%AV_TIFF_CMAKE_INSTALL% -DCMAKE_BUILD_TYPE=%configuration% %AV_CMAKE_ARGS% %AV_TIFF_CMAKE_SOURCE%'
build_script:
- if NOT %compiler%==vc14-nmake cd %AV_TIFF_BUILD%
@@ -75,6 +80,7 @@ build_script:
- 'if %compiler%==cygwin-cmake bash -c "cmake --build . --config %configuration% --target install"'
- 'if %compiler%==mingw64-cmake cmake --build . --config %configuration% --target install'
- 'if %compiler%==vc14-cmake cmake --build . --config %configuration% --target install'
+ - 'if %compiler%==vc9-cmake cmake --build . --config %configuration% --target install'
- 'if %compiler%==vc14-nmake nmake /f Makefile.vc EXTRAFLAGS=/DHAVE_SNPRINTF=1'
- 'if %compiler%==vc14-nmake mkdir %AV_TIFF_INSTALL%'
- 'if %compiler%==vc14-nmake mkdir %AV_TIFF_INSTALL%\bin'
@@ -100,6 +106,7 @@ before_test:
- 'if %compiler%==cygwin-cmake bash -c "ctest -V -C %configuration%"'
- 'if %compiler%==mingw64-cmake ctest -V -C %configuration%'
- 'if %compiler%==vc14-cmake ctest -V -C %configuration%'
+ - 'if %compiler%==vc9-cmake ctest -V -C %configuration%'
# vc14-nmake does not support unit tests
# AppVeyor don't yet have a configurable retention policy, so this will
diff --git a/port/_strtol.h b/port/_strtol.h
index 51c71490..73a10063 100644
--- a/port/_strtol.h
+++ b/port/_strtol.h
@@ -32,6 +32,8 @@
* NetBSD: src/lib/libc/locale/_wcstol.h,v 1.2 2003/08/07 16:43:03 agc Exp
*/
+#include
+
/*
* function template for strtol, strtoll and strtoimax.
*
@@ -41,39 +43,24 @@
* __INT_MIN : lower limit of the return type
* __INT_MAX : upper limit of the return type
*/
-#if defined(_KERNEL) || defined(_STANDALONE) || defined(HAVE_NBTOOL_CONFIG_H) || defined(BCS_ONLY)
__INT
_FUNCNAME(const char *nptr, char **endptr, int base)
-#else
-#include
-#include "setlocale_local.h"
-#define INT_FUNCNAME_(pre, name, post) pre ## name ## post
-#define INT_FUNCNAME(pre, name, post) INT_FUNCNAME_(pre, name, post)
-
-static __INT
-INT_FUNCNAME(_int_, _FUNCNAME, _l)(const char *nptr, char **endptr,
- int base, locale_t loc)
-#endif
{
const char *s;
__INT acc, cutoff;
unsigned char c;
int i, neg, any, cutlim;
- _DIAGASSERT(nptr != NULL);
+ assert(nptr != NULL);
/* endptr may be NULL */
/* check base value */
if (base && (base < 2 || base > 36)) {
-#if !defined(_KERNEL) && !defined(_STANDALONE)
errno = EINVAL;
if (endptr != NULL)
/* LINTED interface specification */
- *endptr = __UNCONST(nptr);
+ *endptr = (char *)(nptr);
return 0;
-#else
- panic("%s: invalid base %d", __func__, base);
-#endif
}
/*
@@ -82,16 +69,9 @@ INT_FUNCNAME(_int_, _FUNCNAME, _l)(const char *nptr, char **endptr,
* assume decimal; if base is already 16, allow 0x.
*/
s = nptr;
-#if defined(_KERNEL) || defined(_STANDALONE) || \
- defined(HAVE_NBTOOL_CONFIG_H) || defined(BCS_ONLY)
do {
c = *s++;
} while (isspace(c));
-#else
- do {
- c = *s++;
- } while (isspace_l(c, loc));
-#endif
if (c == '-') {
neg = 1;
c = *s++;
@@ -108,14 +88,6 @@ INT_FUNCNAME(_int_, _FUNCNAME, _l)(const char *nptr, char **endptr,
c = s[1];
s += 2;
base = 16;
-#if 0
- } else if ((base == 0 || base == 2) &&
- c == '0' && (*s == 'b' || *s == 'B') &&
- (s[1] >= '0' && s[1] <= '1')) {
- c = s[1];
- s += 2;
- base = 2;
-#endif
} else if (base == 0)
base = (c == '0' ? 8 : 10);
@@ -162,13 +134,8 @@ INT_FUNCNAME(_int_, _FUNCNAME, _l)(const char *nptr, char **endptr,
if (neg) {
if (acc < cutoff || (acc == cutoff && i > cutlim)) {
acc = __INT_MIN;
-#if !defined(_KERNEL) && !defined(_STANDALONE)
any = -1;
errno = ERANGE;
-#else
- any = 0;
- break;
-#endif
} else {
any = 1;
acc *= base;
@@ -177,13 +144,8 @@ INT_FUNCNAME(_int_, _FUNCNAME, _l)(const char *nptr, char **endptr,
} else {
if (acc > cutoff || (acc == cutoff && i > cutlim)) {
acc = __INT_MAX;
-#if !defined(_KERNEL) && !defined(_STANDALONE)
any = -1;
errno = ERANGE;
-#else
- any = 0;
- break;
-#endif
} else {
any = 1;
acc *= base;
@@ -193,21 +155,6 @@ INT_FUNCNAME(_int_, _FUNCNAME, _l)(const char *nptr, char **endptr,
}
if (endptr != NULL)
/* LINTED interface specification */
- *endptr = __UNCONST(any ? s - 1 : nptr);
+ *endptr = (char *)(any ? s - 1 : nptr);
return(acc);
}
-
-#if !defined(_KERNEL) && !defined(_STANDALONE) && \
- !defined(HAVE_NBTOOL_CONFIG_H) && !defined(BCS_ONLY)
-__INT
-_FUNCNAME(const char *nptr, char **endptr, int base)
-{
- return INT_FUNCNAME(_int_, _FUNCNAME, _l)(nptr, endptr, base, _current_locale());
-}
-
-__INT
-INT_FUNCNAME(, _FUNCNAME, _l)(const char *nptr, char **endptr, int base, locale_t loc)
-{
- return INT_FUNCNAME(_int_, _FUNCNAME, _l)(nptr, endptr, base, loc);
-}
-#endif
diff --git a/port/_strtoul.h b/port/_strtoul.h
index 9b948fb9..5cb62168 100644
--- a/port/_strtoul.h
+++ b/port/_strtoul.h
@@ -32,6 +32,8 @@
* NetBSD: src/lib/libc/locale/_wcstoul.h,v 1.2 2003/08/07 16:43:03 agc Exp
*/
+#include
+
/*
* function template for strtoul, strtoull and strtoumax.
*
@@ -40,40 +42,24 @@
* __UINT : return type
* __UINT_MAX : upper limit of the return type
*/
-#if defined(_KERNEL) || defined(_STANDALONE) || \
- defined(HAVE_NBTOOL_CONFIG_H) || defined(BCS_ONLY)
__UINT
_FUNCNAME(const char *nptr, char **endptr, int base)
-#else
-#include
-#include "setlocale_local.h"
-#define INT_FUNCNAME_(pre, name, post) pre ## name ## post
-#define INT_FUNCNAME(pre, name, post) INT_FUNCNAME_(pre, name, post)
-
-static __UINT
-INT_FUNCNAME(_int_, _FUNCNAME, _l)(const char *nptr, char **endptr,
- int base, locale_t loc)
-#endif
{
const char *s;
__UINT acc, cutoff;
unsigned char c;
int i, neg, any, cutlim;
- _DIAGASSERT(nptr != NULL);
+ assert(nptr != NULL);
/* endptr may be NULL */
/* check base value */
if (base && (base < 2 || base > 36)) {
-#if !defined(_KERNEL) && !defined(_STANDALONE)
errno = EINVAL;
if (endptr != NULL)
/* LINTED interface specification */
- *endptr = __UNCONST(nptr);
+ *endptr = (char *)(nptr);
return 0;
-#else
- panic("%s: invalid base %d", __func__, base);
-#endif
}
/*
@@ -82,16 +68,9 @@ INT_FUNCNAME(_int_, _FUNCNAME, _l)(const char *nptr, char **endptr,
* assume decimal; if base is already 16, allow 0x.
*/
s = nptr;
-#if defined(_KERNEL) || defined(_STANDALONE) || \
- defined(HAVE_NBTOOL_CONFIG_H) || defined(BCS_ONLY)
do {
c = *s++;
} while (isspace(c));
-#else
- do {
- c = *s++;
- } while (isspace_l(c, loc));
-#endif
if (c == '-') {
neg = 1;
c = *s++;
@@ -108,14 +87,6 @@ INT_FUNCNAME(_int_, _FUNCNAME, _l)(const char *nptr, char **endptr,
c = s[1];
s += 2;
base = 16;
-#if 0
- } else if ((base == 0 || base == 2) &&
- c == '0' && (*s == 'b' || *s == 'B') &&
- (s[1] >= '0' && s[1] <= '1')) {
- c = s[1];
- s += 2;
- base = 2;
-#endif
} else if (base == 0)
base = (c == '0' ? 8 : 10);
@@ -139,13 +110,8 @@ INT_FUNCNAME(_int_, _FUNCNAME, _l)(const char *nptr, char **endptr,
continue;
if (acc > cutoff || (acc == cutoff && i > cutlim)) {
acc = __UINT_MAX;
-#if !defined(_KERNEL) && !defined(_STANDALONE)
any = -1;
errno = ERANGE;
-#else
- any = 0;
- break;
-#endif
} else {
any = 1;
acc *= (__UINT)base;
@@ -156,21 +122,6 @@ INT_FUNCNAME(_int_, _FUNCNAME, _l)(const char *nptr, char **endptr,
acc = -acc;
if (endptr != NULL)
/* LINTED interface specification */
- *endptr = __UNCONST(any ? s - 1 : nptr);
+ *endptr = (char *)(any ? s - 1 : nptr);
return(acc);
}
-
-#if !defined(_KERNEL) && !defined(_STANDALONE) && \
- !defined(HAVE_NBTOOL_CONFIG_H) && !defined(BCS_ONLY)
-__UINT
-_FUNCNAME(const char *nptr, char **endptr, int base)
-{
- return INT_FUNCNAME(_int_, _FUNCNAME, _l)(nptr, endptr, base, _current_locale());
-}
-
-__UINT
-INT_FUNCNAME(, _FUNCNAME, _l)(const char *nptr, char **endptr, int base, locale_t loc)
-{
- return INT_FUNCNAME(_int_, _FUNCNAME, _l)(nptr, endptr, base, loc);
-}
-#endif
diff --git a/port/strtol.c b/port/strtol.c
index 8c5d7b42..a355dde9 100644
--- a/port/strtol.c
+++ b/port/strtol.c
@@ -27,13 +27,14 @@
* SUCH DAMAGE.
*/
+#if 0
__RCSID("$NetBSD: strtol.c,v 1.18 2008/08/20 12:42:26 joerg Exp $");
+#endif
#include
#include
#include
#include
-#include
#include
#define _FUNCNAME strtol
diff --git a/port/strtoll.c b/port/strtoll.c
index 9a8c611d..4784b098 100644
--- a/port/strtoll.c
+++ b/port/strtoll.c
@@ -27,13 +27,13 @@
* SUCH DAMAGE.
*/
+#if 0
__RCSID("$NetBSD: strtol.c,v 1.18 2008/08/20 12:42:26 joerg Exp $");
+#endif
#include
#include
#include
-#include
-#include
#include
#define _FUNCNAME strtoll
diff --git a/port/strtoul.c b/port/strtoul.c
index 0d3d2538..dbd44f16 100644
--- a/port/strtoul.c
+++ b/port/strtoul.c
@@ -27,13 +27,14 @@
* SUCH DAMAGE.
*/
+#if 0
__RCSID("$NetBSD: strtoul.c,v 1.3 2008/08/20 19:58:34 oster Exp $");
+#endif
#include
#include
#include
#include
-#include
#include
#define _FUNCNAME strtoul
diff --git a/port/strtoull.c b/port/strtoull.c
index 29435f50..91e4ddfb 100644
--- a/port/strtoull.c
+++ b/port/strtoull.c
@@ -27,13 +27,14 @@
* SUCH DAMAGE.
*/
+#if 0
__RCSID("$NetBSD: strtoul.c,v 1.3 2008/08/20 19:58:34 oster Exp $");
+#endif
#include
#include
#include
#include
-#include
#include
#define _FUNCNAME strtoull
From be4c85b16e8801a16eec25e80eb9f3dd6a96731b Mon Sep 17 00:00:00 2001
From: Hugo Lefeuvre
Date: Sun, 8 Apr 2018 14:07:08 -0400
Subject: [PATCH 28/66] Fix NULL pointer dereference in TIFFPrintDirectory
The TIFFPrintDirectory function relies on the following assumptions,
supposed to be guaranteed by the specification:
(a) A Transfer Function field is only present if the TIFF file has
photometric type < 3.
(b) If SamplesPerPixel > Color Channels, then the ExtraSamples field
has count SamplesPerPixel - (Color Channels) and contains
information about supplementary channels.
While respect of (a) and (b) are essential for the well functioning of
TIFFPrintDirectory, no checks are realized neither by the callee nor
by TIFFPrintDirectory itself. Hence, following scenarios might happen
and trigger the NULL pointer dereference:
(1) TIFF File of photometric type 4 or more has illegal Transfer
Function field.
(2) TIFF File has photometric type 3 or less and defines a
SamplesPerPixel field such that SamplesPerPixel > Color Channels
without defining all extra samples in the ExtraSamples fields.
In this patch, we address both issues with respect of the following
principles:
(A) In the case of (1), the defined transfer table should be printed
safely even if it isn't 'legal'. This allows us to avoid expensive
checks in TIFFPrintDirectory. Also, it is quite possible that
an alternative photometric type would be developed (not part of the
standard) and would allow definition of Transfer Table. We want
libtiff to be able to handle this scenario out of the box.
(B) In the case of (2), the transfer table should be printed at its
right size, that is if TIFF file has photometric type Palette
then the transfer table should have one row and not three, even
if two extra samples are declared.
In order to fulfill (A) we simply add a new 'i < 3' end condition to
the broken TIFFPrintDirectory loop. This makes sure that in any case
where (b) would be respected but not (a), everything stays fine.
(B) is fulfilled by the loop condition
'i < td->td_samplesperpixel - td->td_extrasamples'. This is enough as
long as (b) is respected.
Naturally, we also make sure (b) is respected. This is done in the
TIFFReadDirectory function by making sure any non-color channel is
counted in ExtraSamples.
This commit addresses CVE-2018-7456.
---
libtiff/tif_dirread.c | 62 +++++++++++++++++++++++++++++++++++++++++++
libtiff/tif_print.c | 2 +-
2 files changed, 63 insertions(+), 1 deletion(-)
diff --git a/libtiff/tif_dirread.c b/libtiff/tif_dirread.c
index 6baa7b31..af5b84a7 100644
--- a/libtiff/tif_dirread.c
+++ b/libtiff/tif_dirread.c
@@ -165,6 +165,7 @@ static int TIFFFetchStripThing(TIFF* tif, TIFFDirEntry* dir, uint32 nstrips, uin
static int TIFFFetchSubjectDistance(TIFF*, TIFFDirEntry*);
static void ChopUpSingleUncompressedStrip(TIFF*);
static uint64 TIFFReadUInt64(const uint8 *value);
+static int _TIFFGetMaxColorChannels(uint16 photometric);
static int _TIFFFillStrilesInternal( TIFF *tif, int loadStripByteCount );
@@ -3504,6 +3505,35 @@ static void TIFFReadDirEntryOutputErr(TIFF* tif, enum TIFFReadDirEntryErr err, c
}
}
+/*
+ * Return the maximum number of color channels specified for a given photometric
+ * type. 0 is returned if photometric type isn't supported or no default value
+ * is defined by the specification.
+ */
+static int _TIFFGetMaxColorChannels( uint16 photometric )
+{
+ switch (photometric) {
+ case PHOTOMETRIC_PALETTE:
+ case PHOTOMETRIC_MINISWHITE:
+ case PHOTOMETRIC_MINISBLACK:
+ return 1;
+ case PHOTOMETRIC_YCBCR:
+ case PHOTOMETRIC_RGB:
+ case PHOTOMETRIC_CIELAB:
+ return 3;
+ case PHOTOMETRIC_SEPARATED:
+ case PHOTOMETRIC_MASK:
+ return 4;
+ case PHOTOMETRIC_LOGL:
+ case PHOTOMETRIC_LOGLUV:
+ case PHOTOMETRIC_CFA:
+ case PHOTOMETRIC_ITULAB:
+ case PHOTOMETRIC_ICCLAB:
+ default:
+ return 0;
+ }
+}
+
/*
* Read the next TIFF directory from a file and convert it to the internal
* format. We read directories sequentially.
@@ -3520,6 +3550,7 @@ TIFFReadDirectory(TIFF* tif)
uint32 fii=FAILED_FII;
toff_t nextdiroff;
int bitspersample_read = FALSE;
+ int color_channels;
tif->tif_diroff=tif->tif_nextdiroff;
if (!TIFFCheckDirOffset(tif,tif->tif_nextdiroff))
@@ -4024,6 +4055,37 @@ TIFFReadDirectory(TIFF* tif)
}
}
}
+
+ /*
+ * Make sure all non-color channels are extrasamples.
+ * If it's not the case, define them as such.
+ */
+ color_channels = _TIFFGetMaxColorChannels(tif->tif_dir.td_photometric);
+ if (color_channels && tif->tif_dir.td_samplesperpixel - tif->tif_dir.td_extrasamples > color_channels) {
+ uint16 old_extrasamples;
+ uint16 *new_sampleinfo;
+
+ TIFFWarningExt(tif->tif_clientdata,module, "Sum of Photometric type-related "
+ "color channels and ExtraSamples doesn't match SamplesPerPixel. "
+ "Defining non-color channels as ExtraSamples.");
+
+ old_extrasamples = tif->tif_dir.td_extrasamples;
+ tif->tif_dir.td_extrasamples = (tif->tif_dir.td_samplesperpixel - color_channels);
+
+ // sampleinfo should contain information relative to these new extra samples
+ new_sampleinfo = (uint16*) _TIFFcalloc(tif->tif_dir.td_extrasamples, sizeof(uint16));
+ if (!new_sampleinfo) {
+ TIFFErrorExt(tif->tif_clientdata, module, "Failed to allocate memory for "
+ "temporary new sampleinfo array (%d 16 bit elements)",
+ tif->tif_dir.td_extrasamples);
+ goto bad;
+ }
+
+ memcpy(new_sampleinfo, tif->tif_dir.td_sampleinfo, old_extrasamples * sizeof(uint16));
+ _TIFFsetShortArray(&tif->tif_dir.td_sampleinfo, new_sampleinfo, tif->tif_dir.td_extrasamples);
+ _TIFFfree(new_sampleinfo);
+ }
+
/*
* Verify Palette image has a Colormap.
*/
diff --git a/libtiff/tif_print.c b/libtiff/tif_print.c
index 8deceb2b..1d86adbf 100644
--- a/libtiff/tif_print.c
+++ b/libtiff/tif_print.c
@@ -544,7 +544,7 @@ TIFFPrintDirectory(TIFF* tif, FILE* fd, long flags)
uint16 i;
fprintf(fd, " %2ld: %5u",
l, td->td_transferfunction[0][l]);
- for (i = 1; i < td->td_samplesperpixel; i++)
+ for (i = 1; i < td->td_samplesperpixel - td->td_extrasamples && i < 3; i++)
fprintf(fd, " %5u",
td->td_transferfunction[i][l]);
fputc('\n', fd);
From 47be9914ddba71eef9617cbb6656194228846228 Mon Sep 17 00:00:00 2001
From: Even Rouault
Date: Fri, 13 Apr 2018 00:07:13 +0200
Subject: [PATCH 29/66] Fix MSVC warning
---
libtiff/tif_dirread.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libtiff/tif_dirread.c b/libtiff/tif_dirread.c
index af5b84a7..546c6fed 100644
--- a/libtiff/tif_dirread.c
+++ b/libtiff/tif_dirread.c
@@ -4070,7 +4070,7 @@ TIFFReadDirectory(TIFF* tif)
"Defining non-color channels as ExtraSamples.");
old_extrasamples = tif->tif_dir.td_extrasamples;
- tif->tif_dir.td_extrasamples = (tif->tif_dir.td_samplesperpixel - color_channels);
+ tif->tif_dir.td_extrasamples = (uint16) (tif->tif_dir.td_samplesperpixel - color_channels);
// sampleinfo should contain information relative to these new extra samples
new_sampleinfo = (uint16*) _TIFFcalloc(tif->tif_dir.td_extrasamples, sizeof(uint16));
From c4f9b53aa55afbd1311eba8c126c14e8b5d1820a Mon Sep 17 00:00:00 2001
From: Even Rouault
Date: Sat, 14 Apr 2018 17:17:34 +0200
Subject: [PATCH 30/66] _TIFFGetMaxColorChannels: update for LOGLUV, ITULAB and
ICCLAB that have 3 color channels
---
libtiff/tif_dirread.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/libtiff/tif_dirread.c b/libtiff/tif_dirread.c
index 546c6fed..67b54057 100644
--- a/libtiff/tif_dirread.c
+++ b/libtiff/tif_dirread.c
@@ -3520,15 +3520,15 @@ static int _TIFFGetMaxColorChannels( uint16 photometric )
case PHOTOMETRIC_YCBCR:
case PHOTOMETRIC_RGB:
case PHOTOMETRIC_CIELAB:
+ case PHOTOMETRIC_LOGLUV:
+ case PHOTOMETRIC_ITULAB:
+ case PHOTOMETRIC_ICCLAB:
return 3;
case PHOTOMETRIC_SEPARATED:
case PHOTOMETRIC_MASK:
return 4;
case PHOTOMETRIC_LOGL:
- case PHOTOMETRIC_LOGLUV:
case PHOTOMETRIC_CFA:
- case PHOTOMETRIC_ITULAB:
- case PHOTOMETRIC_ICCLAB:
default:
return 0;
}
From a6cfa01085847cdfe74cde2ef4afeedd0b96f6a7 Mon Sep 17 00:00:00 2001
From: Paul Kehrer
Date: Tue, 17 Apr 2018 08:52:07 +0000
Subject: [PATCH 31/66] move oss-fuzz build script and fuzzer into libtiff tree
---
contrib/oss-fuzz/build.sh | 52 +++++++++++++
contrib/oss-fuzz/tiff_read_rgba_fuzzer.cc | 90 +++++++++++++++++++++++
2 files changed, 142 insertions(+)
create mode 100755 contrib/oss-fuzz/build.sh
create mode 100644 contrib/oss-fuzz/tiff_read_rgba_fuzzer.cc
diff --git a/contrib/oss-fuzz/build.sh b/contrib/oss-fuzz/build.sh
new file mode 100755
index 00000000..c3ac121f
--- /dev/null
+++ b/contrib/oss-fuzz/build.sh
@@ -0,0 +1,52 @@
+#!/bin/bash -eu
+# Copyright (c) 1988-1997 Sam Leffler
+# Copyright (c) 1991-1997 Silicon Graphics, Inc.
+#
+# Permission to use, copy, modify, distribute, and sell this software and
+# its documentation for any purpose is hereby granted without fee, provided
+# that (i) the above copyright notices and this permission notice appear in
+# all copies of the software and related documentation, and (ii) the names of
+# Sam Leffler and Silicon Graphics may not be used in any advertising or
+# publicity relating to the software without the specific, prior written
+# permission of Sam Leffler and Silicon Graphics.
+#
+# THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
+# WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
+#
+# IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
+# ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
+# OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+# WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
+# LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+# OF THIS SOFTWARE.
+
+# build zlib
+pushd "$SRC/zlib"
+./configure --static --prefix="$WORK"
+make -j$(nproc) CFLAGS="$CFLAGS -fPIC"
+make install
+popd
+
+# Build libjpeg-turbo
+pushd "$SRC/libjpeg-turbo"
+cmake . -DCMAKE_INSTALL_PREFIX=$WORK -DENABLE_STATIC=on -DENABLE_SHARED=off
+make -j$(nproc)
+make install
+popd
+
+cmake . -DCMAKE_INSTALL_PREFIX=$WORK -DBUILD_SHARED_LIBS=off
+make -j$(nproc)
+make install
+
+$CXX $CXXFLAGS -std=c++11 -I$WORK/include \
+ $SRC/libtiff/contrib/oss-fuzz/tiff_read_rgba_fuzzer.cc -o $OUT/tiff_read_rgba_fuzzer \
+ -lFuzzingEngine $WORK/lib/libtiffxx.a $WORK/lib/libtiff.a $WORK/lib/libz.a $WORK/lib/libjpeg.a
+
+mkdir afl_testcases
+(cd afl_testcases; tar xf "$SRC/afl_testcases.tgz")
+mkdir tif
+find afl_testcases -type f -name '*.tif' -exec mv -n {} tif/ \;
+zip -rj tif.zip tif/
+cp tif.zip "$OUT/tiff_read_rgba_fuzzer_seed_corpus.zip"
+cp "$SRC/tiff.dict" "$OUT/tiff_read_rgba_fuzzer.dict"
diff --git a/contrib/oss-fuzz/tiff_read_rgba_fuzzer.cc b/contrib/oss-fuzz/tiff_read_rgba_fuzzer.cc
new file mode 100644
index 00000000..919bbc6c
--- /dev/null
+++ b/contrib/oss-fuzz/tiff_read_rgba_fuzzer.cc
@@ -0,0 +1,90 @@
+/* Copyright (c) 1988-1997 Sam Leffler
+ * Copyright (c) 1991-1997 Silicon Graphics, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and
+ * its documentation for any purpose is hereby granted without fee, provided
+ * that (i) the above copyright notices and this permission notice appear in
+ * all copies of the software and related documentation, and (ii) the names of
+ * Sam Leffler and Silicon Graphics may not be used in any advertising or
+ * publicity relating to the software without the specific, prior written
+ * permission of Sam Leffler and Silicon Graphics.
+ *
+ * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
+ * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
+ * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
+ * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+ * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
+ * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+#include
+#include
+#include
+#include
+
+
+/* stolen from tiffiop.h, which is a private header so we can't just include it */
+/* safe multiply returns either the multiplied value or 0 if it overflowed */
+#define __TIFFSafeMultiply(t,v,m) ((((t)(m) != (t)0) && (((t)(((v)*(m))/(m))) == (t)(v))) ? (t)((v)*(m)) : (t)0)
+
+const uint64 MAX_SIZE = 500000000;
+
+extern "C" void handle_error(const char *unused, const char *unused2, va_list unused3) {
+ return;
+}
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
+ TIFFSetErrorHandler(handle_error);
+ TIFFSetWarningHandler(handle_error);
+ std::istringstream s(std::string(Data,Data+Size));
+ TIFF* tif = TIFFStreamOpen("MemTIFF", &s);
+ if (!tif) {
+ return 0;
+ }
+ uint32 w, h;
+ size_t npixels;
+ uint32* raster;
+
+ TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &w);
+ TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &h);
+ /* don't continue if file size is ludicrous */
+ if (TIFFTileSize64(tif) > MAX_SIZE) {
+ TIFFClose(tif);
+ return 0;
+ }
+ uint64 bufsize = TIFFTileSize64(tif) * 4;
+ /* don't continue if the buffer size greater than the max allowed by the fuzzer */
+ if (bufsize > MAX_SIZE || bufsize == 0) {
+ TIFFClose(tif);
+ return 0;
+ }
+ /* another hack to work around an OOM in tif_fax3.c */
+ uint32 tilewidth = 0;
+ uint32 imagewidth = 0;
+ TIFFGetField(tif, TIFFTAG_TILEWIDTH, &tilewidth);
+ TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &imagewidth);
+ tilewidth = __TIFFSafeMultiply(uint32, tilewidth, 2);
+ imagewidth = __TIFFSafeMultiply(uint32, imagewidth, 2);
+ if (tilewidth * 2 > MAX_SIZE || imagewidth * 2 > MAX_SIZE || tilewidth == 0 || imagewidth == 0) {
+ TIFFClose(tif);
+ return 0;
+ }
+ npixels = w * h;
+ uint32 size = __TIFFSafeMultiply(uint32, w, h);
+ if (size > MAX_SIZE || size == 0) {
+ TIFFClose(tif);
+ return 0;
+ }
+ raster = (uint32*) _TIFFmalloc(npixels * sizeof (uint32));
+ if (raster != NULL) {
+ TIFFReadRGBAImage(tif, w, h, raster, 0);
+ _TIFFfree(raster);
+ }
+ TIFFClose(tif);
+
+ return 0;
+}
From ba1eba27610ce11a15365175269ddbb5093c16ee Mon Sep 17 00:00:00 2001
From: Paul Kehrer
Date: Tue, 17 Apr 2018 22:38:41 +0800
Subject: [PATCH 32/66] remove a pointless multiplication and a variable that's
not necessary
---
contrib/oss-fuzz/tiff_read_rgba_fuzzer.cc | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/contrib/oss-fuzz/tiff_read_rgba_fuzzer.cc b/contrib/oss-fuzz/tiff_read_rgba_fuzzer.cc
index 919bbc6c..b1b189f8 100644
--- a/contrib/oss-fuzz/tiff_read_rgba_fuzzer.cc
+++ b/contrib/oss-fuzz/tiff_read_rgba_fuzzer.cc
@@ -46,7 +46,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
return 0;
}
uint32 w, h;
- size_t npixels;
uint32* raster;
TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &w);
@@ -56,7 +55,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
TIFFClose(tif);
return 0;
}
- uint64 bufsize = TIFFTileSize64(tif) * 4;
+ uint64 bufsize = TIFFTileSize64(tif);
/* don't continue if the buffer size greater than the max allowed by the fuzzer */
if (bufsize > MAX_SIZE || bufsize == 0) {
TIFFClose(tif);
@@ -73,13 +72,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
TIFFClose(tif);
return 0;
}
- npixels = w * h;
uint32 size = __TIFFSafeMultiply(uint32, w, h);
if (size > MAX_SIZE || size == 0) {
TIFFClose(tif);
return 0;
}
- raster = (uint32*) _TIFFmalloc(npixels * sizeof (uint32));
+ raster = (uint32*) _TIFFmalloc(size * sizeof (uint32));
if (raster != NULL) {
TIFFReadRGBAImage(tif, w, h, raster, 0);
_TIFFfree(raster);
From 6150fd4349fe38ad156fa96aaca80acd5a08cefc Mon Sep 17 00:00:00 2001
From: Even Rouault
Date: Fri, 4 May 2018 21:03:41 +0200
Subject: [PATCH 33/66] tif_color.c: fix code comment
---
libtiff/tif_color.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libtiff/tif_color.c b/libtiff/tif_color.c
index 40ca36f6..8fae40ea 100644
--- a/libtiff/tif_color.c
+++ b/libtiff/tif_color.c
@@ -166,7 +166,7 @@ TIFFCIELabToRGBInit(TIFFCIELabToRGB* cielab,
}
/*
- * Convert color value from the YCbCr space to CIE XYZ.
+ * Convert color value from the YCbCr space to RGB.
* The colorspace conversion algorithm comes from the IJG v5a code;
* see below for more information on how it works.
*/
From de144fd228e4be8aa484c3caf3d814b6fa88c6d9 Mon Sep 17 00:00:00 2001
From: Even Rouault
Date: Sat, 12 May 2018 14:24:15 +0200
Subject: [PATCH 34/66] TIFFWriteDirectorySec: avoid assertion. Fixes
http://bugzilla.maptools.org/show_bug.cgi?id=2795. CVE-2018-10963
---
libtiff/tif_dirwrite.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/libtiff/tif_dirwrite.c b/libtiff/tif_dirwrite.c
index 2430de6d..c15a28db 100644
--- a/libtiff/tif_dirwrite.c
+++ b/libtiff/tif_dirwrite.c
@@ -695,8 +695,11 @@ TIFFWriteDirectorySec(TIFF* tif, int isimage, int imagedone, uint64* pdiroff)
}
break;
default:
- assert(0); /* we should never get here */
- break;
+ TIFFErrorExt(tif->tif_clientdata,module,
+ "Cannot write tag %d (%s)",
+ TIFFFieldTag(o),
+ o->field_name ? o->field_name : "unknown");
+ goto bad;
}
}
}
From b68fc85f398227fe59798e0eb4168effeb9e6bf4 Mon Sep 17 00:00:00 2001
From: Even Rouault
Date: Sat, 12 May 2018 14:36:49 +0200
Subject: [PATCH 35/66] TIFFFetchNormalTag(): avoid (probably false positive)
clang-tidy clang-analyzer-core.NullDereference warnings
---
libtiff/tif_dirread.c | 39 ++++++++++++++++++++-------------------
1 file changed, 20 insertions(+), 19 deletions(-)
diff --git a/libtiff/tif_dirread.c b/libtiff/tif_dirread.c
index 67b54057..e80a3b13 100644
--- a/libtiff/tif_dirread.c
+++ b/libtiff/tif_dirread.c
@@ -4941,17 +4941,18 @@ TIFFFetchNormalTag(TIFF* tif, TIFFDirEntry* dp, int recover)
err=TIFFReadDirEntryByteArray(tif,dp,&data);
if (err==TIFFReadDirEntryErrOk)
{
- uint8* ma;
- uint32 mb;
+ uint32 mb = 0;
int n;
- ma=data;
- mb=0;
- while (mb<(uint32)dp->tdir_count)
+ if (data != NULL)
{
- if (*ma==0)
- break;
- ma++;
- mb++;
+ uint8* ma = data;
+ while (mb<(uint32)dp->tdir_count)
+ {
+ if (*ma==0)
+ break;
+ ma++;
+ mb++;
+ }
}
if (mb+1<(uint32)dp->tdir_count)
TIFFWarningExt(tif->tif_clientdata,module,"ASCII value for tag \"%s\" contains null byte in value; value incorrectly truncated during reading due to implementation limitations",fip->field_name);
@@ -5201,11 +5202,11 @@ TIFFFetchNormalTag(TIFF* tif, TIFFDirEntry* dp, int recover)
if (err==TIFFReadDirEntryErrOk)
{
int m;
- if( dp->tdir_count > 0 && data[dp->tdir_count-1] != '\0' )
- {
- TIFFWarningExt(tif->tif_clientdata,module,"ASCII value for tag \"%s\" does not end in null byte. Forcing it to be null",fip->field_name);
- data[dp->tdir_count-1] = '\0';
- }
+ if( data != 0 && dp->tdir_count > 0 && data[dp->tdir_count-1] != '\0' )
+ {
+ TIFFWarningExt(tif->tif_clientdata,module,"ASCII value for tag \"%s\" does not end in null byte. Forcing it to be null",fip->field_name);
+ data[dp->tdir_count-1] = '\0';
+ }
m=TIFFSetField(tif,dp->tdir_tag,(uint16)(dp->tdir_count),data);
if (data!=0)
_TIFFfree(data);
@@ -5378,11 +5379,11 @@ TIFFFetchNormalTag(TIFF* tif, TIFFDirEntry* dp, int recover)
if (err==TIFFReadDirEntryErrOk)
{
int m;
- if( dp->tdir_count > 0 && data[dp->tdir_count-1] != '\0' )
- {
- TIFFWarningExt(tif->tif_clientdata,module,"ASCII value for tag \"%s\" does not end in null byte. Forcing it to be null",fip->field_name);
- data[dp->tdir_count-1] = '\0';
- }
+ if( data != 0 && dp->tdir_count > 0 && data[dp->tdir_count-1] != '\0' )
+ {
+ TIFFWarningExt(tif->tif_clientdata,module,"ASCII value for tag \"%s\" does not end in null byte. Forcing it to be null",fip->field_name);
+ data[dp->tdir_count-1] = '\0';
+ }
m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data);
if (data!=0)
_TIFFfree(data);
From 58a898cb4459055bb488ca815c23b880c242a27d Mon Sep 17 00:00:00 2001
From: Even Rouault
Date: Sat, 12 May 2018 15:32:31 +0200
Subject: [PATCH 36/66] LZWDecodeCompat(): fix potential index-out-of-bounds
write. Fixes http://bugzilla.maptools.org/show_bug.cgi?id=2780 /
CVE-2018-8905
The fix consists in using the similar code LZWDecode() to validate we
don't write outside of the output buffer.
---
libtiff/tif_lzw.c | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/libtiff/tif_lzw.c b/libtiff/tif_lzw.c
index 4ccb443c..94d85e38 100644
--- a/libtiff/tif_lzw.c
+++ b/libtiff/tif_lzw.c
@@ -602,6 +602,7 @@ LZWDecodeCompat(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s)
char *tp;
unsigned char *bp;
int code, nbits;
+ int len;
long nextbits, nextdata, nbitsmask;
code_t *codep, *free_entp, *maxcodep, *oldcodep;
@@ -753,13 +754,18 @@ LZWDecodeCompat(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s)
} while (--occ);
break;
}
- assert(occ >= codep->length);
- op += codep->length;
- occ -= codep->length;
- tp = op;
+ len = codep->length;
+ tp = op + len;
do {
- *--tp = codep->value;
- } while( (codep = codep->next) != NULL );
+ int t;
+ --tp;
+ t = codep->value;
+ codep = codep->next;
+ *tp = (char)t;
+ } while (codep && tp > op);
+ assert(occ >= len);
+ op += len;
+ occ -= len;
} else {
*op++ = (char)code;
occ--;
From 924405d5b31b9ff37a67abd1e294892758f6379a Mon Sep 17 00:00:00 2001
From: Stefan Weil
Date: Mon, 26 Feb 2018 11:34:14 +0100
Subject: [PATCH 37/66] Remove builtin support for GUI warning and error
message boxes
Now warnings always go to the console by default unless applications
define their own warning and error handlers.
GUI applications (and Windows CE) are required to define such handlers.
Signed-off-by: Stefan Weil
---
libtiff/tif_win32.c | 39 ---------------------------------------
libtiff/tif_wince.c | 3 ---
nmake.opt | 14 --------------
3 files changed, 56 deletions(-)
diff --git a/libtiff/tif_win32.c b/libtiff/tif_win32.c
index cde4f6dc..088880e7 100644
--- a/libtiff/tif_win32.c
+++ b/libtiff/tif_win32.c
@@ -405,60 +405,21 @@ _TIFFmemcmp(const void* p1, const void* p2, tmsize_t c)
static void
Win32WarningHandler(const char* module, const char* fmt, va_list ap)
{
-#ifndef TIF_PLATFORM_CONSOLE
- LPTSTR szTitle;
- LPTSTR szTmp;
- LPCTSTR szTitleText = "%s Warning";
- LPCTSTR szDefaultModule = "LIBTIFF";
- LPCTSTR szTmpModule = (module == NULL) ? szDefaultModule : module;
- SIZE_T nBufSize = (strlen(szTmpModule) +
- strlen(szTitleText) + strlen(fmt) + 256)*sizeof(char);
-
- if ((szTitle = (LPTSTR)LocalAlloc(LMEM_FIXED, nBufSize)) == NULL)
- return;
- sprintf(szTitle, szTitleText, szTmpModule);
- szTmp = szTitle + (strlen(szTitle)+2)*sizeof(char);
- vsnprintf(szTmp, nBufSize-(strlen(szTitle)+2)*sizeof(char), fmt, ap);
- MessageBoxA(GetFocus(), szTmp, szTitle, MB_OK | MB_ICONINFORMATION);
- LocalFree(szTitle);
-
- return;
-#else
if (module != NULL)
fprintf(stderr, "%s: ", module);
fprintf(stderr, "Warning, ");
vfprintf(stderr, fmt, ap);
fprintf(stderr, ".\n");
-#endif
}
TIFFErrorHandler _TIFFwarningHandler = Win32WarningHandler;
static void
Win32ErrorHandler(const char* module, const char* fmt, va_list ap)
{
-#ifndef TIF_PLATFORM_CONSOLE
- LPTSTR szTitle;
- LPTSTR szTmp;
- LPCTSTR szTitleText = "%s Error";
- LPCTSTR szDefaultModule = "LIBTIFF";
- LPCTSTR szTmpModule = (module == NULL) ? szDefaultModule : module;
- SIZE_T nBufSize = (strlen(szTmpModule) +
- strlen(szTitleText) + strlen(fmt) + 256)*sizeof(char);
-
- if ((szTitle = (LPTSTR)LocalAlloc(LMEM_FIXED, nBufSize)) == NULL)
- return;
- sprintf(szTitle, szTitleText, szTmpModule);
- szTmp = szTitle + (strlen(szTitle)+2)*sizeof(char);
- vsnprintf(szTmp, nBufSize-(strlen(szTitle)+2)*sizeof(char), fmt, ap);
- MessageBoxA(GetFocus(), szTmp, szTitle, MB_OK | MB_ICONEXCLAMATION);
- LocalFree(szTitle);
- return;
-#else
if (module != NULL)
fprintf(stderr, "%s: ", module);
vfprintf(stderr, fmt, ap);
fprintf(stderr, ".\n");
-#endif
}
TIFFErrorHandler _TIFFerrorHandler = Win32ErrorHandler;
diff --git a/libtiff/tif_wince.c b/libtiff/tif_wince.c
index 5bd7daf5..b3b168f1 100644
--- a/libtiff/tif_wince.c
+++ b/libtiff/tif_wince.c
@@ -34,9 +34,6 @@
#include "tiffiop.h"
#include
-/* Turn off console support on Windows CE. */
-#undef TIF_PLATFORM_CONSOLE
-
COMPILATION SHOULD FAIL
This file is not yet updated to reflect changes in LibTiff 4.0. If you have
the opportunity to update and test this file, please contact LibTiff folks
diff --git a/nmake.opt b/nmake.opt
index c354bdfc..ae544670 100644
--- a/nmake.opt
+++ b/nmake.opt
@@ -34,13 +34,6 @@
###### Edit the following lines to choose a feature set you need. #######
#
-#
-# Select WINMODE_CONSOLE to build a library which reports errors to stderr, or
-# WINMODE_WINDOWED to build such that errors are reported via MessageBox().
-#
-WINMODE_CONSOLE = 1
-#WINMODE_WINDOWED = 1
-
#
# Comment out the following lines to disable internal codecs.
#
@@ -159,13 +152,6 @@ DLLNAME = libtiff.dll
# Set the native cpu bit order
EXTRAFLAGS = -DFILLODER_LSB2MSB $(EXTRAFLAGS)
-!IFDEF WINMODE_WINDOWED
-EXTRAFLAGS = -DTIF_PLATFORM_WINDOWED $(EXTRAFLAGS)
-LIBS = user32.lib $(LIBS)
-!ELSE
-EXTRAFLAGS = -DTIF_PLATFORM_CONSOLE $(EXTRAFLAGS)
-!ENDIF
-
# Codec stuff
!IFDEF CCITT_SUPPORT
EXTRAFLAGS = -DCCITT_SUPPORT $(EXTRAFLAGS)
From 1db1efeb204549fe3f5d982ea9807da729b4f27c Mon Sep 17 00:00:00 2001
From: Even Rouault
Date: Mon, 2 Jul 2018 20:07:45 +0200
Subject: [PATCH 38/66] Fix TIFFTAG_ZSTD_LEVEL pseudo tag value to be > 65536,
and the next one in the series
---
libtiff/tiff.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libtiff/tiff.h b/libtiff/tiff.h
index 9270c903..e924513c 100644
--- a/libtiff/tiff.h
+++ b/libtiff/tiff.h
@@ -602,7 +602,7 @@ typedef enum {
#define TIFFTAG_PERSAMPLE 65563 /* interface for per sample tags */
#define PERSAMPLE_MERGED 0 /* present as a single value */
#define PERSAMPLE_MULTI 1 /* present as multiple values */
-#define TIFFTAG_ZSTD_LEVEL 65534 /* ZSTD compression level */
+#define TIFFTAG_ZSTD_LEVEL 65564 /* ZSTD compression level */
/*
* EXIF tags
From 48e2696e9b3266b33d2309d0946d5e207e095677 Mon Sep 17 00:00:00 2001
From: Even Rouault
Date: Thu, 5 Jul 2018 21:01:02 +0200
Subject: [PATCH 39/66] Add tag and pseudo-tag definitions for ESRI LERC codec
(out of tree codec whose source is at
https://github.com/OSGeo/gdal/blob/master/gdal/frmts/gtiff/tif_lerc.c)
---
libtiff/tif_dirinfo.c | 7 ++++++-
libtiff/tif_read.c | 6 ++++++
libtiff/tiff.h | 11 +++++++++++
3 files changed, 23 insertions(+), 1 deletion(-)
diff --git a/libtiff/tif_dirinfo.c b/libtiff/tif_dirinfo.c
index fd12b737..52d53d44 100644
--- a/libtiff/tif_dirinfo.c
+++ b/libtiff/tif_dirinfo.c
@@ -977,6 +977,8 @@ _TIFFCheckFieldIsValidForCodec(TIFF *tif, ttag_t tag)
case TIFFTAG_CONSECUTIVEBADFAXLINES:
case TIFFTAG_GROUP3OPTIONS:
case TIFFTAG_GROUP4OPTIONS:
+ /* LERC */
+ case TIFFTAG_LERC_PARAMETERS:
break;
default:
return 1;
@@ -1056,7 +1058,10 @@ _TIFFCheckFieldIsValidForCodec(TIFF *tif, ttag_t tag)
if (tag == TIFFTAG_PREDICTOR)
return 1;
break;
-
+ case COMPRESSION_LERC:
+ if (tag == TIFFTAG_LERC_PARAMETERS)
+ return 1;
+ break;
}
return 0;
}
diff --git a/libtiff/tif_read.c b/libtiff/tif_read.c
index d1cfe469..518363bb 100644
--- a/libtiff/tif_read.c
+++ b/libtiff/tif_read.c
@@ -346,6 +346,12 @@ TIFFSeek(TIFF* tif, uint32 row, uint16 sample )
return 0;
whole_strip = tif->tif_dir.td_stripbytecount[strip] < 10
|| isMapped(tif);
+ if( td->td_compression == COMPRESSION_LERC )
+ {
+ /* Ideally plugins should have a way to declare they don't support
+ * chunk strip */
+ whole_strip = 1;
+ }
#else
whole_strip = 1;
#endif
diff --git a/libtiff/tiff.h b/libtiff/tiff.h
index e924513c..497034c0 100644
--- a/libtiff/tiff.h
+++ b/libtiff/tiff.h
@@ -187,6 +187,8 @@ typedef enum {
#define COMPRESSION_SGILOG 34676 /* SGI Log Luminance RLE */
#define COMPRESSION_SGILOG24 34677 /* SGI Log 24-bit packed */
#define COMPRESSION_JP2000 34712 /* Leadtools JPEG2000 */
+#define COMPRESSION_LERC 34887 /* ESRI Lerc codec: https://github.com/Esri/lerc */
+/* compression codes 34887-34889 are reserved for ESRI */
#define COMPRESSION_LZMA 34925 /* LZMA2 */
#define COMPRESSION_ZSTD 34926 /* ZSTD: WARNING not registered in Adobe-maintained registry */
#define TIFFTAG_PHOTOMETRIC 262 /* photometric interpretation */
@@ -449,6 +451,8 @@ typedef enum {
/* tag 34929 is a private tag registered to FedEx */
#define TIFFTAG_FEDEX_EDR 34929 /* unknown use */
#define TIFFTAG_INTEROPERABILITYIFD 40965 /* Pointer to Interoperability private directory */
+/* tags 50674 to 50677 are reserved for ESRI */
+#define TIFFTAG_LERC_PARAMETERS 50674 /* Stores LERC version and additional compression method */
/* Adobe Digital Negative (DNG) format tags */
#define TIFFTAG_DNGVERSION 50706 /* &DNG version number */
#define TIFFTAG_DNGBACKWARDVERSION 50707 /* &DNG compatibility version */
@@ -603,6 +607,13 @@ typedef enum {
#define PERSAMPLE_MERGED 0 /* present as a single value */
#define PERSAMPLE_MULTI 1 /* present as multiple values */
#define TIFFTAG_ZSTD_LEVEL 65564 /* ZSTD compression level */
+#define TIFFTAG_LERC_VERSION 65565 /* LERC version */
+#define LERC_VERSION_2_4 4
+#define TIFFTAG_LERC_ADD_COMPRESSION 65566 /* LERC additional compression */
+#define LERC_ADD_COMPRESSION_NONE 0
+#define LERC_ADD_COMPRESSION_DEFLATE 1
+#define LERC_ADD_COMPRESSION_ZSTD 2
+#define TIFFTAG_LERC_MAXZERROR 65567 /* LERC maximum error */
/*
* EXIF tags
From 4af64003c8322d2cba6f86245a3ccf88dd6125d5 Mon Sep 17 00:00:00 2001
From: Even Rouault
Date: Tue, 7 Aug 2018 11:48:06 +0200
Subject: [PATCH 40/66] Fix libtiff 4.0.8 regression when reading
LZW-compressed strips with scanline API
Fixes http://bugzilla.maptools.org/show_bug.cgi?id=2800
---
libtiff/tif_config.h.in | 3 +++
libtiff/tif_lzw.c | 12 ++++++++++--
test/CMakeLists.txt | 5 ++++-
test/Makefile.am | 4 +++-
test/common.sh | 1 +
test/images/lzw-single-strip.tiff | Bin 0 -> 76264 bytes
test/tiffcp-lzw-scanline-decode.sh | 6 ++++++
7 files changed, 27 insertions(+), 4 deletions(-)
create mode 100644 test/images/lzw-single-strip.tiff
create mode 100755 test/tiffcp-lzw-scanline-decode.sh
diff --git a/libtiff/tif_config.h.in b/libtiff/tif_config.h.in
index ed1e80fc..a799435b 100644
--- a/libtiff/tif_config.h.in
+++ b/libtiff/tif_config.h.in
@@ -71,6 +71,9 @@
/* Define to 1 if you have the `lfind' function. */
#undef HAVE_LFIND
+/* Define to 1 if you have the header file. */
+#undef HAVE_MEMORY_H
+
/* Define to 1 if you have the `mmap' function. */
#undef HAVE_MMAP
diff --git a/libtiff/tif_lzw.c b/libtiff/tif_lzw.c
index 94d85e38..ac685dd7 100644
--- a/libtiff/tif_lzw.c
+++ b/libtiff/tif_lzw.c
@@ -133,6 +133,7 @@ typedef struct {
long dec_restart; /* restart count */
#ifdef LZW_CHECKEOS
uint64 dec_bitsleft; /* available bits in raw data */
+ tmsize_t old_tif_rawcc; /* value of tif_rawcc at the end of the previous TIFLZWDecode() call */
#endif
decodeFunc dec_decode; /* regular or backwards compatible */
code_t* dec_codep; /* current recognized code */
@@ -318,6 +319,7 @@ LZWPreDecode(TIFF* tif, uint16 s)
sp->dec_nbitsmask = MAXCODE(BITS_MIN);
#ifdef LZW_CHECKEOS
sp->dec_bitsleft = 0;
+ sp->old_tif_rawcc = 0;
#endif
sp->dec_free_entp = sp->dec_codetab + CODE_FIRST;
/*
@@ -425,7 +427,7 @@ LZWDecode(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s)
bp = (unsigned char *)tif->tif_rawcp;
#ifdef LZW_CHECKEOS
- sp->dec_bitsleft = (((uint64)tif->tif_rawcc) << 3);
+ sp->dec_bitsleft += (((uint64)tif->tif_rawcc - sp->old_tif_rawcc) << 3);
#endif
nbits = sp->lzw_nbits;
nextdata = sp->lzw_nextdata;
@@ -553,6 +555,9 @@ LZWDecode(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s)
tif->tif_rawcc -= (tmsize_t)( (uint8*) bp - tif->tif_rawcp );
tif->tif_rawcp = (uint8*) bp;
+#ifdef LZW_CHECKEOS
+ sp->old_tif_rawcc = tif->tif_rawcc;
+#endif
sp->lzw_nbits = (unsigned short) nbits;
sp->lzw_nextdata = nextdata;
sp->lzw_nextbits = nextbits;
@@ -656,7 +661,7 @@ LZWDecodeCompat(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s)
bp = (unsigned char *)tif->tif_rawcp;
#ifdef LZW_CHECKEOS
- sp->dec_bitsleft = (((uint64)tif->tif_rawcc) << 3);
+ sp->dec_bitsleft += (((uint64)tif->tif_rawcc - sp->old_tif_rawcc) << 3);
#endif
nbits = sp->lzw_nbits;
nextdata = sp->lzw_nextdata;
@@ -774,6 +779,9 @@ LZWDecodeCompat(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s)
tif->tif_rawcc -= (tmsize_t)( (uint8*) bp - tif->tif_rawcp );
tif->tif_rawcp = (uint8*) bp;
+#ifdef LZW_CHECKEOS
+ sp->old_tif_rawcc = tif->tif_rawcc;
+#endif
sp->lzw_nbits = (unsigned short)nbits;
sp->lzw_nextdata = nextdata;
sp->lzw_nextbits = nextbits;
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 912be19c..266e3fcf 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -44,6 +44,7 @@ set(TESTSCRIPTS
tiffcp-logluv.sh
tiffcp-thumbnail.sh
tiffcp-lzw-compat.sh
+ tiffcp-lzw-scanline-decode.sh
tiffdump.sh
tiffinfo.sh
tiffcp-split.sh
@@ -120,7 +121,8 @@ set(TIFFIMAGES
images/rgb-3c-16b.tiff
images/rgb-3c-8b.tiff
images/quad-tile.jpg.tiff
- images/quad-lzw-compat.tiff)
+ images/quad-lzw-compat.tiff
+ images/lzw-single-strip.tiff)
set(BMPIMAGES
images/palette-1c-8b.bmp
@@ -335,6 +337,7 @@ add_convert_test(tiffcp g32d "-c g3:2d" "images/miniswhite-1c-1b.ti
add_convert_test(tiffcp g32dfill "-c g3:2d:fill" "images/miniswhite-1c-1b.tiff" FALSE)
add_convert_test(tiffcp g4 "-c g4" "images/miniswhite-1c-1b.tiff" FALSE)
add_convert_test(tiffcp none "-c none" "images/quad-lzw-compat.tiff" FALSE)
+add_convert_test(tiffcp noner1 "-c none -r 1" "images/lzw-single-strip.tiff" FALSE)
add_convert_test_multi(tiffcp tiffcp "" logluv "-c none" "-c sgilog" ""
"images/logluv-3c-16b.tiff" FALSE)
add_convert_test_multi(tiffcp thumbnail "" thumbnail "g3:1d" "" ""
diff --git a/test/Makefile.am b/test/Makefile.am
index 2052487c..52a3fa4b 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -79,6 +79,7 @@ TESTSCRIPTS = \
tiffcp-logluv.sh \
tiffcp-thumbnail.sh \
tiffcp-lzw-compat.sh \
+ tiffcp-lzw-scanline-decode.sh \
tiffdump.sh \
tiffinfo.sh \
tiffcp-split.sh \
@@ -158,7 +159,8 @@ TIFFIMAGES = \
images/rgb-3c-16b.tiff \
images/rgb-3c-8b.tiff \
images/quad-tile.jpg.tiff \
- images/quad-lzw-compat.tiff
+ images/quad-lzw-compat.tiff \
+ images/lzw-single-strip.tiff
PNMIMAGES = \
images/minisblack-1c-8b.pgm \
diff --git a/test/common.sh b/test/common.sh
index 6b1380dd..42c38737 100644
--- a/test/common.sh
+++ b/test/common.sh
@@ -41,6 +41,7 @@ IMG_RGB_3C_16B=${IMAGES}/rgb-3c-16b.tiff
IMG_RGB_3C_8B=${IMAGES}/rgb-3c-8b.tiff
IMG_MINISBLACK_2C_8B_ALPHA=${IMAGES}/minisblack-2c-8b-alpha.tiff
IMG_QUAD_LZW_COMPAT=${IMAGES}/quad-lzw-compat.tiff
+IMG_LZW_SINGLE_STROP=${IMAGES}/lzw-single-strip.tiff
IMG_MINISWHITE_1C_1B_PBM=${IMAGES}/miniswhite-1c-1b.pbm
IMG_MINISBLACK_1C_8B_PGM=${IMAGES}/minisblack-1c-8b.pgm
diff --git a/test/images/lzw-single-strip.tiff b/test/images/lzw-single-strip.tiff
new file mode 100644
index 0000000000000000000000000000000000000000..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