diff -Nru tiff-4.6.0/.gitignore tiff-4.6.1~git240130/.gitignore --- tiff-4.6.0/.gitignore 2023-09-08 09:12:35.000000000 +0000 +++ tiff-4.6.1~git240130/.gitignore 1970-01-01 00:00:00.000000000 +0000 @@ -1,82 +0,0 @@ -aclocal.m4 -autom4te.cache -configure -Makefile.in -config/compile -config/config.guess -config/config.h -config/config.h.in -config/config.sub -config/depcomp -config/install-sh -config/ltmain.sh -config/missing -config/mkinstalldirs -config/test-driver -**/Makefile -*.o -*.la -*.lo -.deps -.libs -config.log -config.status -contrib/addtiffo/addtiffo -contrib/dbs/tiff-bi -contrib/dbs/tiff-grayscale -contrib/dbs/tiff-palette -contrib/dbs/tiff-rgb -contrib/iptcutil/iptcutil -libtiff-4.pc -libtiff/mkg3states -libtiff/stamp-h1 -libtiff/stamp-h2 -libtiff/tif_config.h -libtiff/tiffconf.h -libtool -m4/libtool.m4 -m4/ltoptions.m4 -m4/ltsugar.m4 -m4/ltversion.m4 -m4/lt~obsolete.m4 -tools/fax2ps -tools/fax2tiff -tools/pal2rgb -tools/ppm2tiff -tools/raw2tiff -tools/rgb2ycbcr -tools/thumbnail -tools/tiff2bw -tools/tiff2pdf -tools/tiff2ps -tools/tiff2rgba -tools/tiffcmp -tools/tiffcp -tools/tiffcrop -tools/tiffdither -tools/tiffdump -tools/tiffgt -tools/tiffinfo -tools/tiffmedian -tools/tiffset -tools/tiffsplit -test/ascii_tag -test/custom_dir -test/long_tag -test/raw_decode -test/rewrite -test/short_tag -test/strip_rw -test/defer_strile_loading -test/defer_strile_writing -test/testtypes -test/custom_dir_EXIF_231 -test/rational_precision2double -test/*.log -test/*.trs -test/o-* -*~ -.idea -.vs -cmake-build* -build* diff -Nru tiff-4.6.0/build/gitlab-ci tiff-4.6.1~git240130/build/gitlab-ci --- tiff-4.6.0/build/gitlab-ci 2023-09-08 09:12:35.000000000 +0000 +++ tiff-4.6.1~git240130/build/gitlab-ci 2024-03-04 19:02:20.000000000 +0000 @@ -52,8 +52,8 @@ else opts2="" fi - echo "Running cmake -G "$1" -DCMAKE_BUILD_TYPE="$2" -DCMAKE_INSTALL_PREFIX=../cmake-install ${opts} ${opts2} .." - cmake -G "$1" -DCMAKE_BUILD_TYPE="$2" -DCMAKE_INSTALL_PREFIX=../cmake-install ${opts} ${opts2} .. + echo "Running cmake -G "$1" -DCMAKE_UNITY_BUILD=ON -DCMAKE_BUILD_TYPE="$2" -DCMAKE_INSTALL_PREFIX=../cmake-install ${opts} ${opts2} .." + cmake -G "$1" -DCMAKE_UNITY_BUILD=ON -DCMAKE_BUILD_TYPE="$2" -DCMAKE_INSTALL_PREFIX=../cmake-install ${opts} ${opts2} .. $COVERITY_BUILD cmake --build . cmake --build . --target install ctest -V diff -Nru tiff-4.6.0/cmake/TiffConfig.cmake.in tiff-4.6.1~git240130/cmake/TiffConfig.cmake.in --- tiff-4.6.0/cmake/TiffConfig.cmake.in 2023-09-08 09:12:35.000000000 +0000 +++ tiff-4.6.1~git240130/cmake/TiffConfig.cmake.in 2024-03-04 19:02:20.000000000 +0000 @@ -11,8 +11,7 @@ endfunction() # Tell the user project where to find our headers and libraries -get_filename_component(_DIR "${CMAKE_CURRENT_LIST_FILE}" ABSOLUTE) -get_filename_component(_DIR "${_DIR}" DIRECTORY) +get_filename_component(_DIR "${CMAKE_CURRENT_LIST_DIR}/../../.." ABSOLUTE) get_filename_component(_ROOT "${_DIR}/@PROJECT_ROOT_DIR@" ABSOLUTE) # Use _ROOT as prefix here for the possibility of relocation after installation. set_variable_from_rel_or_absolute_path("TIFF_INCLUDE_DIR" "${_ROOT}" "@CMAKE_INSTALL_INCLUDEDIR@") @@ -21,7 +20,7 @@ set(TIFF_LIBRARIES TIFF::tiff) if(NOT TARGET TIFF::tiff) - include("${_DIR}/TiffTargets.cmake") + include("${CMAKE_CURRENT_LIST_DIR}/TiffTargets.cmake") endif() unset (_ROOT) diff -Nru tiff-4.6.0/contrib/iptcutil/iptcutil.c tiff-4.6.1~git240130/contrib/iptcutil/iptcutil.c --- tiff-4.6.0/contrib/iptcutil/iptcutil.c 2023-09-08 09:12:35.000000000 +0000 +++ tiff-4.6.1~git240130/contrib/iptcutil/iptcutil.c 2024-03-04 19:02:20.000000000 +0000 @@ -459,38 +459,38 @@ { if (state == 0) { - int state, next; + int state2, next2; - char brkused, quoted; + char brkused2, quoted2; - state = 0; - next = 0; + state2 = 0; + next2 = 0; while (tokenizer(0, newstr, inputlen, token, "", "#", "", 0, - &brkused, &next, "ed) == 0) + &brkused2, &next2, "ed2) == 0) { - if (state == 0) + if (state2 == 0) dataset = (unsigned char)atoi(newstr); - else if (state == 1) + else if (state2 == 1) recnum = (unsigned char)atoi(newstr); - state++; + state2++; } } else if (state == 1) { - int next; + int next2; unsigned long len; - char brkused, quoted; + char brkused2, quoted2; - next = 0; + next2 = 0; len = (unsigned long)strlen(token); while (tokenizer(0, newstr, inputlen, token, "", "&", "", 0, - &brkused, &next, "ed) == 0) + &brkused2, &next2, "ed2) == 0) { - if (brkused && next > 0) + if (brkused2 && next2 > 0) { - char *s = &token[next - 1]; + char *s = &token[next2 - 1]; len -= convertHTMLcodes(s, (int)strlen(s)); } @@ -511,9 +511,9 @@ fputc((len >> 8) & 255, ofile); fputc(len & 255, ofile); } - next = 0; + next2 = 0; while (len--) - fputc(token[next++], ofile); + fputc(token[next2++], ofile); } state++; } diff -Nru tiff-4.6.0/debian/changelog tiff-4.6.1~git240130/debian/changelog --- tiff-4.6.0/debian/changelog 2024-01-08 20:13:48.000000000 +0000 +++ tiff-4.6.1~git240130/debian/changelog 2024-03-04 19:56:52.000000000 +0000 @@ -1,3 +1,13 @@ +tiff (4.6.1~git240130-0ubuntu1~18.04.sav0) bionic; urgency=medium + + * New 4.6.1 pre-release from git source (commit 1d28fe63 on 2024-01-30): + - Fixes all known security issues including CVE-2023-{6228,6277,52356} + * d/patches/: Drop CVE-2023-6277.patch (upstreamed as per above comment) + - Add bump-version-for-new-symbol.patch to use version 4.6.1 (new symbol) + * d/libtiff6.symbols: Update (new TIFFOpenOptionsSetMaxCumulatedMemAlloc) + + -- Rob Savoury Mon, 04 Mar 2024 11:56:52 -0800 + tiff (4.6.0-2~18.04.sav0) bionic; urgency=medium * Backport to Bionic diff -Nru tiff-4.6.0/debian/libtiff6.symbols tiff-4.6.1~git240130/debian/libtiff6.symbols --- tiff-4.6.0/debian/libtiff6.symbols 2022-12-10 09:16:36.000000000 +0000 +++ tiff-4.6.1~git240130/debian/libtiff6.symbols 2024-03-04 19:23:25.000000000 +0000 @@ -5,6 +5,7 @@ LIBTIFF_4.3@LIBTIFF_4.3 4.5.0~rc1 LIBTIFF_4.4@LIBTIFF_4.4 4.5.0~rc1 LIBTIFF_4.5@LIBTIFF_4.5 4.5.0~rc1 + LIBTIFF_4.6.1@LIBTIFF_4.6.1 4.6.1~git TIFFAccessTagMethods@LIBTIFF_4.0 4.0.3 TIFFCIELabToRGBInit@LIBTIFF_4.0 4.0.3 TIFFCIELabToXYZ@LIBTIFF_4.0 4.0.3 @@ -91,6 +92,7 @@ TIFFOpenOptionsAlloc@LIBTIFF_4.5 4.5.0~rc1 TIFFOpenOptionsFree@LIBTIFF_4.5 4.5.0~rc1 TIFFOpenOptionsSetErrorHandlerExtR@LIBTIFF_4.5 4.5.0~rc1 + TIFFOpenOptionsSetMaxCumulatedMemAlloc@LIBTIFF_4.6.1 4.6.1~git TIFFOpenOptionsSetMaxSingleMemAlloc@LIBTIFF_4.5 4.5.0~rc1 TIFFOpenOptionsSetWarningHandlerExtR@LIBTIFF_4.5 4.5.0~rc1 TIFFPrintDirectory@LIBTIFF_4.0 4.0.3 diff -Nru tiff-4.6.0/debian/patches/CVE-2023-6277.patch tiff-4.6.1~git240130/debian/patches/CVE-2023-6277.patch --- tiff-4.6.0/debian/patches/CVE-2023-6277.patch 2023-11-26 09:27:57.000000000 +0000 +++ tiff-4.6.1~git240130/debian/patches/CVE-2023-6277.patch 1970-01-01 00:00:00.000000000 +0000 @@ -1,170 +0,0 @@ -From 5320c9d89c054fa805d037d84c57da874470b01a Mon Sep 17 00:00:00 2001 -From: Su Laus -Date: Tue, 31 Oct 2023 15:43:29 +0000 -Subject: [PATCH] Prevent some out-of-memory attacks - -Some small fuzzer files fake large amounts of data and provoke out-of-memory situations. For non-compressed data content / tags, out-of-memory can be prevented by comparing with the file size. - -At image reading, data size of some tags / data structures (StripByteCounts, StripOffsets, StripArray, TIFF directory) is compared with file size to prevent provoked out-of-memory attacks. - -See issue https://gitlab.com/libtiff/libtiff/-/issues/614#note_1602683857 ---- - libtiff/tif_dirread.c | 92 ++++++++++++++++++++++++++++++++++++++++++- - 1 file changed, 90 insertions(+), 2 deletions(-) - -diff --git a/libtiff/tif_dirread.c b/libtiff/tif_dirread.c -index 2c49dc6a..58a42760 100644 ---- a/libtiff/tif_dirread.c -+++ b/libtiff/tif_dirread.c -@@ -1308,6 +1308,21 @@ TIFFReadDirEntryArrayWithLimit(TIFF *tif, TIFFDirEntry *direntry, - datasize = (*count) * typesize; - assert((tmsize_t)datasize > 0); - -+ /* Before allocating a huge amount of memory for corrupted files, check if -+ * size of requested memory is not greater than file size. -+ */ -+ uint64_t filesize = TIFFGetFileSize(tif); -+ if (datasize > filesize) -+ { -+ TIFFWarningExtR(tif, "ReadDirEntryArray", -+ "Requested memory size for tag %d (0x%x) %" PRIu32 -+ " is greather than filesize %" PRIu64 -+ ". Memory not allocated, tag not read", -+ direntry->tdir_tag, direntry->tdir_tag, datasize, -+ filesize); -+ return (TIFFReadDirEntryErrAlloc); -+ } -+ - if (isMapped(tif) && datasize > (uint64_t)tif->tif_size) - return TIFFReadDirEntryErrIo; - -@@ -5266,6 +5281,20 @@ static int EstimateStripByteCounts(TIFF *tif, TIFFDirEntry *dir, - if (!_TIFFFillStrilesInternal(tif, 0)) - return -1; - -+ /* Before allocating a huge amount of memory for corrupted files, check if -+ * size of requested memory is not greater than file size. */ -+ uint64_t filesize = TIFFGetFileSize(tif); -+ uint64_t allocsize = (uint64_t)td->td_nstrips * sizeof(uint64_t); -+ if (allocsize > filesize) -+ { -+ TIFFWarningExtR(tif, module, -+ "Requested memory size for StripByteCounts of %" PRIu64 -+ " is greather than filesize %" PRIu64 -+ ". Memory not allocated", -+ allocsize, filesize); -+ return -1; -+ } -+ - if (td->td_stripbytecount_p) - _TIFFfreeExt(tif, td->td_stripbytecount_p); - td->td_stripbytecount_p = (uint64_t *)_TIFFCheckMalloc( -@@ -5276,9 +5305,7 @@ static int EstimateStripByteCounts(TIFF *tif, TIFFDirEntry *dir, - if (td->td_compression != COMPRESSION_NONE) - { - uint64_t space; -- uint64_t filesize; - uint16_t n; -- filesize = TIFFGetFileSize(tif); - if (!(tif->tif_flags & TIFF_BIGTIFF)) - space = sizeof(TIFFHeaderClassic) + 2 + dircount * 12 + 4; - else -@@ -5807,6 +5834,20 @@ static uint16_t TIFFFetchDirectory(TIFF *tif, uint64_t diroff, - dircount16 = (uint16_t)dircount64; - dirsize = 20; - } -+ /* Before allocating a huge amount of memory for corrupted files, check -+ * if size of requested memory is not greater than file size. */ -+ uint64_t filesize = TIFFGetFileSize(tif); -+ uint64_t allocsize = (uint64_t)dircount16 * dirsize; -+ if (allocsize > filesize) -+ { -+ TIFFWarningExtR( -+ tif, module, -+ "Requested memory size for TIFF directory of %" PRIu64 -+ " is greather than filesize %" PRIu64 -+ ". Memory not allocated, TIFF directory not read", -+ allocsize, filesize); -+ return 0; -+ } - origdir = _TIFFCheckMalloc(tif, dircount16, dirsize, - "to read TIFF directory"); - if (origdir == NULL) -@@ -5921,6 +5962,20 @@ static uint16_t TIFFFetchDirectory(TIFF *tif, uint64_t diroff, - "directories not supported"); - return 0; - } -+ /* Before allocating a huge amount of memory for corrupted files, check -+ * if size of requested memory is not greater than file size. */ -+ uint64_t filesize = TIFFGetFileSize(tif); -+ uint64_t allocsize = (uint64_t)dircount16 * dirsize; -+ if (allocsize > filesize) -+ { -+ TIFFWarningExtR( -+ tif, module, -+ "Requested memory size for TIFF directory of %" PRIu64 -+ " is greather than filesize %" PRIu64 -+ ". Memory not allocated, TIFF directory not read", -+ allocsize, filesize); -+ return 0; -+ } - origdir = _TIFFCheckMalloc(tif, dircount16, dirsize, - "to read TIFF directory"); - if (origdir == NULL) -@@ -5968,6 +6023,8 @@ static uint16_t TIFFFetchDirectory(TIFF *tif, uint64_t diroff, - } - } - } -+ /* No check against filesize needed here because "dir" should have same size -+ * than "origdir" checked above. */ - dir = (TIFFDirEntry *)_TIFFCheckMalloc( - tif, dircount16, sizeof(TIFFDirEntry), "to read TIFF directory"); - if (dir == 0) -@@ -7164,6 +7221,20 @@ static int TIFFFetchStripThing(TIFF *tif, TIFFDirEntry *dir, uint32_t nstrips, - return (0); - } - -+ /* Before allocating a huge amount of memory for corrupted files, check -+ * if size of requested memory is not greater than file size. */ -+ uint64_t filesize = TIFFGetFileSize(tif); -+ uint64_t allocsize = (uint64_t)nstrips * sizeof(uint64_t); -+ if (allocsize > filesize) -+ { -+ TIFFWarningExtR(tif, module, -+ "Requested memory size for StripArray of %" PRIu64 -+ " is greather than filesize %" PRIu64 -+ ". Memory not allocated", -+ allocsize, filesize); -+ _TIFFfreeExt(tif, data); -+ return (0); -+ } - resizeddata = (uint64_t *)_TIFFCheckMalloc( - tif, nstrips, sizeof(uint64_t), "for strip array"); - if (resizeddata == 0) -@@ -7263,6 +7334,23 @@ static void allocChoppedUpStripArrays(TIFF *tif, uint32_t nstrips, - } - bytecount = last_offset + last_bytecount - offset; - -+ /* Before allocating a huge amount of memory for corrupted files, check if -+ * size of StripByteCount and StripOffset tags is not greater than -+ * file size. -+ */ -+ uint64_t allocsize = (uint64_t)nstrips * sizeof(uint64_t) * 2; -+ uint64_t filesize = TIFFGetFileSize(tif); -+ if (allocsize > filesize) -+ { -+ TIFFWarningExtR(tif, "allocChoppedUpStripArrays", -+ "Requested memory size for StripByteCount and " -+ "StripOffsets %" PRIu64 -+ " is greather than filesize %" PRIu64 -+ ". Memory not allocated", -+ allocsize, filesize); -+ return; -+ } -+ - newcounts = - (uint64_t *)_TIFFCheckMalloc(tif, nstrips, sizeof(uint64_t), - "for chopped \"StripByteCounts\" array"); --- -GitLab - diff -Nru tiff-4.6.0/debian/patches/bump-version-for-new-symbol.patch tiff-4.6.1~git240130/debian/patches/bump-version-for-new-symbol.patch --- tiff-4.6.0/debian/patches/bump-version-for-new-symbol.patch 1970-01-01 00:00:00.000000000 +0000 +++ tiff-4.6.1~git240130/debian/patches/bump-version-for-new-symbol.patch 2024-03-04 19:56:42.000000000 +0000 @@ -0,0 +1,40 @@ +From: Rob Savoury +Date: Mon, 04 Mar 2024 11:53:56 -0800 +Subject: Bump version for new symbol + +Upcoming tiff 4.6.1 adds a new symbol TIFFOpenOptionsSetMaxCumulatedMemAlloc, +so use 4.6.1 to give pkg-config etc the correct version including this symbol. +--- + VERSION | 2 +- + configure.ac | 4 ++-- + 2 files changed, 3 insertions(+), 3 deletions(-) + +diff --git a/VERSION b/VERSION +index 6016e8a..8ac28bf 100644 +--- a/VERSION ++++ b/VERSION +@@ -1 +1 @@ +-4.6.0 ++4.6.1 +diff --git a/configure.ac b/configure.ac +index e86208d..7a2b32d 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -25,7 +25,7 @@ dnl OF THIS SOFTWARE. + dnl Process this file with autoconf to produce a configure script. + + AC_PREREQ(2.64) +-AC_INIT([LibTIFF Software],[4.6.0],[tiff@lists.osgeo.org],[tiff]) ++AC_INIT([LibTIFF Software],[4.6.1],[tiff@lists.osgeo.org],[tiff]) + AC_CONFIG_AUX_DIR(config) + AC_CONFIG_MACRO_DIR(m4) + AC_LANG(C) +@@ -41,7 +41,7 @@ dnl Versioning. + dnl Don't fill the ALPHA_VERSION field, if not applicable. + LIBTIFF_MAJOR_VERSION=4 + LIBTIFF_MINOR_VERSION=6 +-LIBTIFF_MICRO_VERSION=0 ++LIBTIFF_MICRO_VERSION=1 + LIBTIFF_ALPHA_VERSION= + LIBTIFF_VERSION=$LIBTIFF_MAJOR_VERSION.$LIBTIFF_MINOR_VERSION.$LIBTIFF_MICRO_VERSION$LIBTIFF_ALPHA_VERSION + dnl This (LIBTIFF_RELEASE_DATE) is used to set the #define TIFFLIB_VERSION in tiffvers.h. diff -Nru tiff-4.6.0/debian/patches/series tiff-4.6.1~git240130/debian/patches/series --- tiff-4.6.0/debian/patches/series 2024-01-08 20:12:46.000000000 +0000 +++ tiff-4.6.1~git240130/debian/patches/series 2024-03-04 19:47:48.000000000 +0000 @@ -1,3 +1,3 @@ +bump-version-for-new-symbol.patch no_smartquotes.patch -CVE-2023-6277.patch fix-build-with-older-sphinx.patch diff -Nru tiff-4.6.0/doc/functions/TIFFClose.rst tiff-4.6.1~git240130/doc/functions/TIFFClose.rst --- tiff-4.6.0/doc/functions/TIFFClose.rst 2023-09-08 09:12:35.000000000 +0000 +++ tiff-4.6.1~git240130/doc/functions/TIFFClose.rst 2024-03-04 19:02:20.000000000 +0000 @@ -27,6 +27,15 @@ The given structure will be completely freed, so you should save opened file handle and pointer to the close procedure in external variables before calling :c:func:`TIFFCleanup`, if you will need these ones to close the file. +:c:func:`TIFFCleanup` calls :c:func:`TIFFFlush`, which stores all pending data +in the file. + +.. note:: + Both functions have no return value. + If you want to check whether the data has been successfully written + to the file, you can call :c:func:`TIFFFlush`, which has a return value, + before :c:func:`TIFFClose`. + Diagnostics ----------- diff -Nru tiff-4.6.0/doc/functions/TIFFCreateDirectory.rst tiff-4.6.1~git240130/doc/functions/TIFFCreateDirectory.rst --- tiff-4.6.0/doc/functions/TIFFCreateDirectory.rst 2023-09-08 09:12:35.000000000 +0000 +++ tiff-4.6.1~git240130/doc/functions/TIFFCreateDirectory.rst 2024-03-04 19:02:20.000000000 +0000 @@ -63,6 +63,10 @@ - that unlike :c:func:`TIFFWriteDirectory`, :c:func:`TIFFCheckpointDirectory` does not free up the directory data structures in memory. +After ``libtiff`` version 4.6.0 :c:func:`TIFFCreateDirectory` also releases +the directory part of the `tif` structure by calling :c:func:`TIFFFreeDirectory`, +which should have been called by the user application before creating a new directory. + Diagnostics ----------- diff -Nru tiff-4.6.0/doc/functions/TIFFCustomDirectory.rst tiff-4.6.1~git240130/doc/functions/TIFFCustomDirectory.rst --- tiff-4.6.0/doc/functions/TIFFCustomDirectory.rst 2023-09-08 09:12:35.000000000 +0000 +++ tiff-4.6.1~git240130/doc/functions/TIFFCustomDirectory.rst 2024-03-04 19:02:20.000000000 +0000 @@ -94,6 +94,11 @@ the creation and reading of EXIF, GPS and custom directories. See test/custom_dir.c and test/custom_dir_EXIF_231.c +After ``libtiff`` version 4.6.0 :c:func:`TIFFCreateCustomDirectory`, +:c:func:`TIFFCreateEXIFDirectory` and :c:func:`TIFFCreateGPSDirectory` also +releases the directory part of the `tif` structure by calling :c:func:`TIFFFreeDirectory`, +which should have been called by the user application before creating a new directory. + Hints and detailed instructions ------------------------------- diff -Nru tiff-4.6.0/doc/functions/TIFFDeferStrileArrayWriting.rst tiff-4.6.1~git240130/doc/functions/TIFFDeferStrileArrayWriting.rst --- tiff-4.6.0/doc/functions/TIFFDeferStrileArrayWriting.rst 2023-09-08 09:12:35.000000000 +0000 +++ tiff-4.6.1~git240130/doc/functions/TIFFDeferStrileArrayWriting.rst 2024-03-04 19:02:20.000000000 +0000 @@ -61,6 +61,11 @@ All error messages are directed to the :c:func:`TIFFErrorExtR` routine. Likewise, warning messages are directed to the :c:func:`TIFFWarningExtR` routine. +Note +---- + +This functionality was introduced with libtiff 4.1. + See also -------- diff -Nru tiff-4.6.0/doc/functions/TIFFError.rst tiff-4.6.1~git240130/doc/functions/TIFFError.rst --- tiff-4.6.0/doc/functions/TIFFError.rst 2023-09-08 09:12:35.000000000 +0000 +++ tiff-4.6.1~git240130/doc/functions/TIFFError.rst 2024-03-04 19:02:20.000000000 +0000 @@ -65,6 +65,9 @@ Furthermore, a **custom defined data structure** *user_data* for the error handler can be given along. +Please refer to :doc:`/functions/TIFFOpenOptions` for how to setup the +application-specific handler introduced with libtiff 4.5. + Note ---- diff -Nru tiff-4.6.0/doc/functions/TIFFOpen.rst tiff-4.6.1~git240130/doc/functions/TIFFOpen.rst --- tiff-4.6.0/doc/functions/TIFFOpen.rst 2023-09-08 09:12:35.000000000 +0000 +++ tiff-4.6.1~git240130/doc/functions/TIFFOpen.rst 2024-03-04 19:02:20.000000000 +0000 @@ -94,8 +94,9 @@ file should be closed using its file descriptor *fd*. :c:func:`TIFFOpenExt` (added in libtiff 4.5) is like :c:func:`TIFFOpen`, -but options, such as re-entrant error and warning handlers may be passed -with the *opts* argument. The *opts* argument may be NULL. +but options, such as re-entrant error and warning handlers and a limit in byte +that libtiff internal memory allocation functions are allowed to request per call +may be passed with the *opts* argument. The *opts* argument may be NULL. Refer to :doc:`TIFFOpenOptions` for allocating and filling the *opts* argument parameters. The allocated memory for :c:type:`TIFFOpenOptions` can be released straight after successful execution of the related @@ -105,9 +106,7 @@ but opens a TIFF file with a Unicode filename. :c:func:`TIFFFdOpenExt` (added in libtiff 4.5) is like :c:func:`TIFFFdOpen`, -but options, such as re-entrant error and warning handlers may be passed -with the *opts* argument. The *opts* argument may be NULL. -Refer to :doc:`TIFFOpenOptions` for filling the *opts* argument. +but options argument *opts* like for :c:func:`TIFFOpenExt` can be passed. :c:func:`TIFFSetFileName` sets the file name in the tif-structure and returns the old file name. @@ -326,5 +325,5 @@ :doc:`libtiff` (3tiff), :doc:`TIFFClose` (3tiff), -:doc:`TIFFStrileQuery`, +:doc:`TIFFStrileQuery` (3tiff), :doc:`TIFFOpenOptions` \ No newline at end of file diff -Nru tiff-4.6.0/doc/functions/TIFFOpenOptions.rst tiff-4.6.1~git240130/doc/functions/TIFFOpenOptions.rst --- tiff-4.6.0/doc/functions/TIFFOpenOptions.rst 2023-09-08 09:12:35.000000000 +0000 +++ tiff-4.6.1~git240130/doc/functions/TIFFOpenOptions.rst 2024-03-04 19:02:20.000000000 +0000 @@ -18,6 +18,8 @@ .. c:function:: void TIFFOpenOptionsSetMaxSingleMemAlloc(TIFFOpenOptions* opts, tmsize_t max_single_mem_alloc) +.. c:function:: void TIFFOpenOptionsSetMaxCumulatedMemAlloc(TIFFOpenOptions* opts, tmsize_t max_cumulated_mem_alloc) + .. c:function:: void TIFFOpenOptionsSetErrorHandlerExtR(TIFFOpenOptions* opts, TIFFErrorHandlerExtR handler, void* errorhandler_user_data) .. c:function:: void TIFFOpenOptionsSetWarningHandlerExtR(TIFFOpenOptions* opts, TIFFErrorHandlerExtR handler, void* warnhandler_user_data) @@ -38,11 +40,25 @@ :c:func:`TIFFOpenOptionsFree` releases the allocated memory for :c:type:`TIFFOpenOptions`. The allocated memory for :c:type:`TIFFOpenOptions` can be released straight after successful execution of the related -TIFF open"Ext" functions like :c:func:`TIFFOpenExt`. +TIFFOpen"Ext" functions like :c:func:`TIFFOpenExt`. -:c:func:`TIFFOpenOptionsSetMaxSingleMemAlloc` sets parameter for the -maximum single memory limit in byte that ``libtiff`` internal memory allocation -functions are allowed to request per call. +:c:func:`TIFFOpenOptionsSetMaxSingleMemAlloc` (added in libtiff 4.5.0) sets +the value for the maximum single memory limit in byte that ``libtiff`` internal +memory allocation functions are allowed to request per call. + +.. note:: + However, the ``libtiff`` external functions :c:func:`_TIFFmalloc` + and :c:func:`_TIFFrealloc` **do not apply** this internal memory + allocation limit set by :c:func:`TIFFOpenOptionsSetMaxSingleMemAlloc`! + +:c:func:`TIFFOpenOptionsSetMaxCumulatedMemAlloc` (added in libtiff 4.6.1) sets +the maximum cumulated memory allocations in byte, for a given TIFF handle, +that ``libtiff`` internal memory allocation functions are allowed. + +.. note:: + However, the ``libtiff`` external functions :c:func:`_TIFFmalloc` + and :c:func:`_TIFFrealloc` **do not apply** this internal memory + allocation limit set by :c:func:`TIFFOpenOptionsSetMaxCumulatedMemAlloc`! :c:func:`TIFFOpenOptionsSetErrorHandlerExtR` sets the function pointer to an application-specific and per-TIFF handle (re-entrant) error handler. @@ -55,6 +71,43 @@ :c:func:`TIFFOpenOptionsSetErrorHandlerExtR` but for the warning handler, which is invoked through :c:func:`TIFFWarningExtR` +Example +------- + +:: + + #include "tiffio.h" + + typedef struct MyErrorHandlerUserDataStruct + { + /* ... any user data structure ... */ + } MyErrorHandlerUserDataStruct; + + static int myErrorHandler(TIFF *tiff, void *user_data, const char *module, + const char *fmt, va_list ap) + { + MyErrorHandlerUserDataStruct *errorhandler_user_data = + (MyErrorHandlerUserDataStruct *)user_data; + /*... code of myErrorHandler ...*/ + return 1; + } + + + main() + { + tmsize_t limit = (256 * 1024 * 1024); + MyErrorHandlerUserDataStruct user_data = { /* ... any data ... */}; + + TIFFOpenOptions *opts = TIFFOpenOptionsAlloc(); + TIFFOpenOptionsSetMaxSingleMemAlloc(opts, limit); + TIFFOpenOptionsSetErrorHandlerExtR(opts, myErrorHandler, &user_data); + TIFF *tif = TIFFOpenExt("foo.tif", "r", opts); + TIFFOpenOptionsFree(opts); + /* ... go on here ... */ + + TIFFClose(tif); + } + Note ---- diff -Nru tiff-4.6.0/doc/functions/TIFFStrileQuery.rst tiff-4.6.1~git240130/doc/functions/TIFFStrileQuery.rst --- tiff-4.6.0/doc/functions/TIFFStrileQuery.rst 2023-09-08 09:12:35.000000000 +0000 +++ tiff-4.6.1~git240130/doc/functions/TIFFStrileQuery.rst 2024-03-04 19:02:20.000000000 +0000 @@ -66,6 +66,11 @@ All error messages are directed to the :c:func:`TIFFErrorExtR` routine. Likewise, warning messages are directed to the :c:func:`TIFFWarningExtR` routine. +Note +---- + +This functionality was introduced with libtiff 4.1. + See also -------- diff -Nru tiff-4.6.0/doc/functions/libtiff.rst tiff-4.6.1~git240130/doc/functions/libtiff.rst --- tiff-4.6.0/doc/functions/libtiff.rst 2023-09-08 09:12:35.000000000 +0000 +++ tiff-4.6.1~git240130/doc/functions/libtiff.rst 2024-03-04 19:02:20.000000000 +0000 @@ -329,6 +329,8 @@ - releases the allocated memory for :c:type:`TIFFOpenOptions` * - :c:func:`TIFFOpenOptionsSetMaxSingleMemAlloc` - limits the maximum single memory allocation within ``libtiff`` + * - :c:func:`TIFFOpenOptionsSetMaxCumulatedMemAlloc` + - limits the maximum cumulated memory allocation within ``libtiff`` * - :c:func:`TIFFOpenOptionsSetErrorHandlerExtR` - setup of a user-specific and per-TIFF handle (re-entrant) error handler * - :c:func:`TIFFOpenOptionsSetWarningHandlerExtR` diff -Nru tiff-4.6.0/doc/index.rst tiff-4.6.1~git240130/doc/index.rst --- tiff-4.6.0/doc/index.rst 2023-09-08 09:12:35.000000000 +0000 +++ tiff-4.6.1~git240130/doc/index.rst 2024-03-04 19:02:20.000000000 +0000 @@ -39,9 +39,12 @@ Starting with libtiff v4.6.0, the source code for most TIFF tools (except tiffinfo, tiffdump, tiffcp and tiffset) was discontinued, due to the lack of contributors able to address reported security issues. - It will still be available in the source distribution, but they - will no longer be built by default, and issues related to them - will no longer be accepted in the libtiff bug tracker. + tiff2ps and tiff2pdf source code has been moved in a unsupported category, + no longer built by default, but are still part of the the source + distribution. Other retired utilities are in a archive/ directory, only + available in the libtiff git repository. + Issues related to unsupported and archived tools will no longer be accepted + in the libtiff bug tracker. The following sections are included in this documentation: diff -Nru tiff-4.6.0/doc/libtiff.rst tiff-4.6.1~git240130/doc/libtiff.rst --- tiff-4.6.0/doc/libtiff.rst 2023-09-08 09:12:35.000000000 +0000 +++ tiff-4.6.1~git240130/doc/libtiff.rst 2024-03-04 19:02:20.000000000 +0000 @@ -90,11 +90,20 @@ :c:func:`realloc`, and :c:func:`free` routines in the C library.) To deal with segmented pointer issues ``libtiff`` also provides -:c:func:`_TIFFmemcpy`, :c:func:`_TIFFmemset`, and :c:func:`_TIFFmemmove` +:c:func:`_TIFFmemcpy`, :c:func:`_TIFFmemset`, and :c:func:`_TIFFmemcmp` routines that mimic the equivalent ANSI C routines, but that are intended for use with memory allocated through :c:func:`_TIFFmalloc` and :c:func:`_TIFFrealloc`. +With ``libtiff`` 4.5 a method was introduced to limit the internal +memory allocation that functions are allowed to request per call +(see :c:func:`TIFFOpenOptionsSetMaxSingleMemAlloc` and :c:func:`TIFFOpenExt`). + +With ``libtiff`` 4.6.1 a method was introduced to limit the internal +cumulated memory allocation that functions are allowed to request for a given +TIFF handle +(see :c:func:`TIFFOpenOptionsSetMaxCumulatedMemAlloc` and :c:func:`TIFFOpenExt`). + Error Handling -------------- @@ -106,6 +115,10 @@ Likewise warning messages are directed to a single handler routine that can be specified with a call to :c:func:`TIFFSetWarningHandler` +Further application-specific and per-TIFF handle (re-entrant) error handler +and warning handler can be set. Please refer to :doc:`/functions/TIFFError` +and :doc:`/functions/TIFFOpenOptions`. + Basic File Handling ------------------- @@ -139,7 +152,7 @@ main() { TIFF* tif = TIFFOpen("foo.tif", "w"); - ... do stuff ... + /* ... do stuff ... */ TIFFClose(tif); } @@ -157,6 +170,25 @@ buffered information to a file. Note that if you call :c:func:`TIFFClose` you do not need to call :c:func:`TIFFFlush`. +.. warning:: + + In order to prevent out-of-memory issues when opening a TIFF file + :c:func:`TIFFOpenExt` can be used and then the maximum single memory + limit in bytes that ``libtiff`` internal memory allocation functions + are allowed to request per call can be set with + :c:func:`TIFFOpenOptionsSetMaxSingleMemAlloc`. + +Example + +:: + + tmsize_t limit = (256 * 1024 * 1024); + TIFFOpenOptions *opts = TIFFOpenOptionsAlloc(); + TIFFOpenOptionsSetMaxSingleMemAlloc(opts, limit); + TIFF *tif = TIFFOpenExt("foo.tif", "w", opts); + TIFFOpenOptionsFree(opts); + /* ... go on here ... */ + TIFF Directories ---------------- diff -Nru tiff-4.6.0/doc/releases/v4.6.0.rst tiff-4.6.1~git240130/doc/releases/v4.6.0.rst --- tiff-4.6.0/doc/releases/v4.6.0.rst 2023-09-08 09:12:35.000000000 +0000 +++ tiff-4.6.1~git240130/doc/releases/v4.6.0.rst 2024-03-04 19:02:20.000000000 +0000 @@ -26,12 +26,15 @@ of maintenance over the years and were the source of various reported security issues. See "Removed functionality" below for the list of removed utilities. - Starting with libtiff v4.6.0, their source code, at this time, will still be - available in the source distribution, but they will no longer be built by - default, and issues related to them will no longer be accepted in the - libtiff bug tracker. - The only remaining supported TIFF tools are tiffinfo, tiffdump, tiffcp, - tiffset and tiffsplit. + Starting with libtiff v4.6.0, the source code for most TIFF tools (except tiffinfo, + tiffdump, tiffcp and tiffset) was discontinued, due to the lack of contributors + able to address reported security issues. + tiff2ps and tiff2pdf source code has been moved in a unsupported category, + no longer built by default, but are still part of the the source + distribution. Other retired utilities are in a archive/ directory, only + available in the libtiff git repository. + Issues related to unsupported and archived tools will no longer be accepted + in the libtiff bug tracker. Software configuration changes diff -Nru tiff-4.6.0/libtiff/CMakeLists.txt tiff-4.6.1~git240130/libtiff/CMakeLists.txt --- tiff-4.6.0/libtiff/CMakeLists.txt 2023-09-08 09:12:35.000000000 +0000 +++ tiff-4.6.1~git240130/libtiff/CMakeLists.txt 2024-03-04 19:02:20.000000000 +0000 @@ -98,10 +98,21 @@ tif_zip.c tif_zstd.c) +if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.16) + set_property(SOURCE tif_jpeg.c tif_jpeg12.c PROPERTY SKIP_UNITY_BUILD_INCLUSION ON) +endif () + +# For all files (but tif_open.c, tif_unix.c and tif_win32.c), forbid the use +# of _TIFFmalloc/_TIFFfree and require the use of their "Ext" versions +target_compile_definitions(tiff PRIVATE TIFF_DO_NOT_USE_NON_EXT_ALLOC_FUNCTIONS) +set_property(SOURCE tif_open.c APPEND PROPERTY COMPILE_DEFINITIONS ALLOW_TIFF_NON_EXT_ALLOC_FUNCTIONS) + if(USE_WIN32_FILEIO) target_sources(tiff PRIVATE tif_win32.c) + set_property(SOURCE tif_win32.c APPEND PROPERTY COMPILE_DEFINITIONS ALLOW_TIFF_NON_EXT_ALLOC_FUNCTIONS) else() target_sources(tiff PRIVATE tif_unix.c) + set_property(SOURCE tif_unix.c APPEND PROPERTY COMPILE_DEFINITIONS ALLOW_TIFF_NON_EXT_ALLOC_FUNCTIONS) endif() target_include_directories(tiff @@ -113,8 +124,8 @@ ${TIFF_INCLUDES} ) -# MSVC specific resource preparation -if (WIN32 AND MSVC) +# Windows specific resource preparation +if (WIN32) message(STATUS "Include resource version information for LibTIFF") target_sources(tiff PRIVATE tif_win32_versioninfo.rc) source_group("Resource Files" FILES tif_win32_versioninfo.rc) @@ -130,7 +141,11 @@ endif() if(ZIP_SUPPORT AND LIBDEFLATE_SUPPORT) target_link_libraries(tiff PRIVATE Deflate::Deflate) - list(APPEND tiff_libs_private_list "${Deflate_LIBRARY}") + if(Deflate_VERSION_STRING VERSION_GREATER_EQUAL "1.9") + string(APPEND tiff_requires_private " libdeflate") + else() + list(APPEND tiff_libs_private_list "${Deflate_LIBRARY}") + endif() endif() if(JPEG_SUPPORT) target_link_libraries(tiff PRIVATE JPEG::JPEG) @@ -148,9 +163,13 @@ endif() if(LERC_SUPPORT) target_link_libraries(tiff PRIVATE LERC::LERC) - list(APPEND tiff_libs_private_list "${LERC_LIBRARY}") - if(NOT BUILD_SHARED_LIBS) - set_target_properties(tiff PROPERTIES COMPILE_DEFINITIONS LERC_STATIC) + if(LERC_VERSION_STRING VERSION_GREATER_EQUAL "4.0") + if(NOT BUILD_SHARED_LIBS) + set_target_properties(tiff PROPERTIES COMPILE_DEFINITIONS LERC_STATIC) + endif() + string(APPEND tiff_requires_private " Lerc") + else() + list(APPEND tiff_libs_private_list "${LERC_LIBRARY}") endif() endif() if(LZMA_SUPPORT) @@ -220,7 +239,7 @@ tiffio.hxx) # No .def file for this library. - if (WIN32) + if (WIN32 AND NOT MINGW) add_library(tiffxx STATIC ../placeholder.h) else() add_library(tiffxx ../placeholder.h) diff -Nru tiff-4.6.0/libtiff/libtiff.def tiff-4.6.1~git240130/libtiff/libtiff.def --- tiff-4.6.0/libtiff/libtiff.def 2023-09-08 09:12:35.000000000 +0000 +++ tiff-4.6.1~git240130/libtiff/libtiff.def 2024-03-04 19:02:20.000000000 +0000 @@ -85,6 +85,7 @@ TIFFOpenWExt TIFFOpenOptionsAlloc TIFFOpenOptionsFree + TIFFOpenOptionsSetMaxCumulatedMemAlloc TIFFOpenOptionsSetMaxSingleMemAlloc TIFFOpenOptionsSetErrorHandlerExtR TIFFOpenOptionsSetWarningHandlerExtR diff -Nru tiff-4.6.0/libtiff/libtiff.map tiff-4.6.1~git240130/libtiff/libtiff.map --- tiff-4.6.0/libtiff/libtiff.map 2023-09-08 09:12:35.000000000 +0000 +++ tiff-4.6.1~git240130/libtiff/libtiff.map 2024-03-04 19:02:20.000000000 +0000 @@ -214,3 +214,7 @@ TIFFOpenOptionsSetErrorHandlerExtR; TIFFOpenOptionsSetWarningHandlerExtR; } LIBTIFF_4.4; + +LIBTIFF_4.6.1 { + TIFFOpenOptionsSetMaxCumulatedMemAlloc; +} LIBTIFF_4.5; diff -Nru tiff-4.6.0/libtiff/tif_aux.c tiff-4.6.1~git240130/libtiff/tif_aux.c --- tiff-4.6.0/libtiff/tif_aux.c 2023-09-08 09:12:35.000000000 +0000 +++ tiff-4.6.1~git240130/libtiff/tif_aux.c 2024-03-04 19:02:20.000000000 +0000 @@ -385,53 +385,6 @@ return (ok); } -struct _Int64Parts -{ - int32_t low, high; -}; - -typedef union -{ - struct _Int64Parts part; - int64_t value; -} _Int64; - -float _TIFFUInt64ToFloat(uint64_t ui64) -{ - _Int64 i; - - i.value = ui64; - if (i.part.high >= 0) - { - return (float)i.value; - } - else - { - long double df; - df = (long double)i.value; - df += 18446744073709551616.0; /* adding 2**64 */ - return (float)df; - } -} - -double _TIFFUInt64ToDouble(uint64_t ui64) -{ - _Int64 i; - - i.value = ui64; - if (i.part.high >= 0) - { - return (double)i.value; - } - else - { - long double df; - df = (long double)i.value; - df += 18446744073709551616.0; /* adding 2**64 */ - return (double)df; - } -} - float _TIFFClampDoubleToFloat(double val) { if (val > FLT_MAX) diff -Nru tiff-4.6.0/libtiff/tif_close.c tiff-4.6.1~git240130/libtiff/tif_close.c --- tiff-4.6.0/libtiff/tif_close.c 2023-09-08 09:12:35.000000000 +0000 +++ tiff-4.6.1~git240130/libtiff/tif_close.c 2024-03-04 19:02:20.000000000 +0000 @@ -110,6 +110,14 @@ _TIFFfreeExt(tif, tif->tif_fieldscompat); } + if (tif->tif_cur_cumulated_mem_alloc != 0) + { + TIFFErrorExtR(tif, "TIFFCleanup", + "tif_cur_cumulated_mem_alloc = %" PRIu64 " whereas it " + "should be 0", + (uint64_t)tif->tif_cur_cumulated_mem_alloc); + } + _TIFFfreeExt(NULL, tif); } diff -Nru tiff-4.6.0/libtiff/tif_dir.c tiff-4.6.1~git240130/libtiff/tif_dir.c --- tiff-4.6.0/libtiff/tif_dir.c 2023-09-08 09:12:35.000000000 +0000 +++ tiff-4.6.1~git240130/libtiff/tif_dir.c 2024-03-04 19:02:20.000000000 +0000 @@ -211,7 +211,7 @@ } bad: TIFFErrorExtR(tif, "TIFFSetField", - "%s: Invalid InkNames value; no NUL at given buffer end " + "%s: Invalid InkNames value; no null at given buffer end " "location %" PRIu32 ", after %" PRIu16 " ink", tif->tif_name, slen, i); return (0); @@ -1676,6 +1676,8 @@ */ int TIFFCreateDirectory(TIFF *tif) { + /* Free previously allocated memory and setup default values. */ + TIFFFreeDirectory(tif); TIFFDefaultDirectory(tif); tif->tif_diroff = 0; tif->tif_nextdiroff = 0; @@ -1688,6 +1690,8 @@ int TIFFCreateCustomDirectory(TIFF *tif, const TIFFFieldArray *infoarray) { + /* Free previously allocated memory and setup default values. */ + TIFFFreeDirectory(tif); TIFFDefaultDirectory(tif); /* @@ -2151,17 +2155,22 @@ else tif->tif_curdir++; } - if (retval && probablySubIFD) + if (probablySubIFD) { - /* Reset IFD list to start new one for SubIFD chain and also start - * SubIFD chain with tif_curdir=0. */ - _TIFFCleanupIFDOffsetAndNumberMaps(tif); /* invalidate IFD loop lists */ - tif->tif_curdir = 0; /* first directory of new chain */ - /* add this offset to new IFD list */ - _TIFFCheckDirNumberAndOffset(tif, tif->tif_curdir, diroff); + if (retval) + { + /* Reset IFD list to start new one for SubIFD chain and also start + * SubIFD chain with tif_curdir=0. */ + /* invalidate IFD loop lists */ + _TIFFCleanupIFDOffsetAndNumberMaps(tif); + tif->tif_curdir = 0; /* first directory of new chain */ + /* add this offset to new IFD list */ + _TIFFCheckDirNumberAndOffset(tif, tif->tif_curdir, diroff); + } /* To be able to return from SubIFD or custom-IFD to main-IFD */ tif->tif_setdirectory_force_absolute = TRUE; } + return (retval); } diff -Nru tiff-4.6.0/libtiff/tif_dirinfo.c tiff-4.6.1~git240130/libtiff/tif_dirinfo.c --- tiff-4.6.0/libtiff/tif_dirinfo.c 2023-09-08 09:12:35.000000000 +0000 +++ tiff-4.6.1~git240130/libtiff/tif_dirinfo.c 2024-03-04 19:02:20.000000000 +0000 @@ -213,8 +213,6 @@ {TIFFTAG_CURRENTPREPROFILEMATRIX, -1, -1, TIFF_SRATIONAL, 0, TIFF_SETGET_C16_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "CurrentPreProfileMatrix", NULL}, {TIFFTAG_PERSAMPLE, 0, 0, TIFF_SHORT, 0, TIFF_SETGET_UNDEFINED, TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, TRUE, FALSE, "PerSample", NULL}, #if 0 - /* TODO: revert above #if 0 for TIFF 4.6.0 */ - /* begin DNG 1.2.0.0 tags */ {TIFFTAG_COLORIMETRICREFERENCE, 1, 1, TIFF_SHORT, 0, TIFF_SETGET_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ColorimetricReference", NULL}, {TIFFTAG_CAMERACALIBRATIONSIGNATURE, -1, -1, TIFF_BYTE, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "CameraCalibrationSignature", NULL}, @@ -282,9 +280,11 @@ {TIFFTAG_ILLUMINANTDATA2, -3, -3, TIFF_UNDEFINED, 0, TIFF_SETGET_C32_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "IlluminantData2", NULL}, {TIFFTAG_ILLUMINANTDATA3, -3, -3, TIFF_UNDEFINED, 0, TIFF_SETGET_C32_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "IlluminantData3", NULL}, /* end DNG tags */ +#endif /* begin TIFF/EP tags */ {TIFFTAG_EP_CFAREPEATPATTERNDIM, 2, 2, TIFF_SHORT, 0, TIFF_SETGET_C0_UINT16, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "EP CFARepeatPatternDim", NULL}, {TIFFTAG_EP_CFAPATTERN, -1, -1, TIFF_BYTE, 0, TIFF_SETGET_C16_UINT8, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 1, "EP CFAPattern", NULL}, +#if 0 /* TIFFTAG_EP_BATTERYLEVEL can be RATIONAL or ASCII. * LibTiff defines it as ASCII and converts RATIONAL to an ASCII string. */ {TIFFTAG_EP_BATTERYLEVEL, -1, -1, TIFF_ASCII, 0, TIFF_SETGET_ASCII, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "EP BatteryLevel", NULL}, @@ -374,7 +374,7 @@ {EXIFTAG_BRIGHTNESSVALUE, 1, 1, TIFF_SRATIONAL, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "BrightnessValue", NULL}, {EXIFTAG_EXPOSUREBIASVALUE, 1, 1, TIFF_SRATIONAL, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "ExposureBiasValue", NULL}, {EXIFTAG_MAXAPERTUREVALUE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "MaxApertureValue", NULL}, - /*--: EXIFTAG_SUBJECTDISTANCE: LibTiff returns value of "-1" if numerator equals 4294967295 (0xFFFFFFFF) to indicate infinite distance! + /*--: EXIFTAG_SUBJECTDISTANCE: LibTiff returns value of "-1" if numerator equals 4294967295 (0xFFFFFFFF) to indicate infinite distance! * However, there are two other EXIF tags where numerator indicates a special value and six other cases where the denominator indicates special values, * which are not treated within LibTiff!! */ {EXIFTAG_SUBJECTDISTANCE, 1, 1, TIFF_RATIONAL, 0, TIFF_SETGET_FLOAT, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, 1, 0, "SubjectDistance", NULL}, @@ -887,7 +887,7 @@ if (fld == NULL) { fld = _TIFFCreateAnonField(tif, tag, dt); - if (!_TIFFMergeFields(tif, fld, 1)) + if (fld == NULL || !_TIFFMergeFields(tif, fld, 1)) return NULL; } @@ -1197,12 +1197,24 @@ for (i = 0; i < n; i++) { tp->field_tag = info[i].field_tag; + if (info[i].field_readcount < TIFF_VARIABLE2 || + info[i].field_readcount == 0 || + info[i].field_writecount < TIFF_VARIABLE2 || + info[i].field_writecount == 0) + { + /* The fields (field_readcount) and (field_writecount) may use the + * values TIFF_VARIABLE (-1), TIFF_SPP (-2), TIFF_VARIABLE2 (-3). */ + TIFFErrorExtR(tif, module, + "The value of field_readcount and field_writecount " + "must be greater than or equal to -3 and not zero."); + return -1; + } tp->field_readcount = info[i].field_readcount; tp->field_writecount = info[i].field_writecount; tp->field_type = info[i].field_type; tp->field_anonymous = 0; tp->set_field_type = - _TIFFSetGetType(info[i].field_type, info[i].field_readcount, + _TIFFSetGetType(info[i].field_type, info[i].field_writecount, info[i].field_passcount); tp->get_field_type = _TIFFSetGetType(info[i].field_type, info[i].field_readcount, diff -Nru tiff-4.6.0/libtiff/tif_dirread.c tiff-4.6.1~git240130/libtiff/tif_dirread.c --- tiff-4.6.0/libtiff/tif_dirread.c 2023-09-08 09:12:35.000000000 +0000 +++ tiff-4.6.1~git240130/libtiff/tif_dirread.c 2024-03-04 19:02:20.000000000 +0000 @@ -1016,16 +1016,7 @@ err = TIFFReadDirEntryCheckedLong8(tif, direntry, &m); if (err != TIFFReadDirEntryErrOk) return (err); -#if defined(__WIN32__) && (_MSC_VER < 1500) - /* - * XXX: MSVC 6.0 does not support conversion - * of 64-bit integers into floating point - * values. - */ - *value = _TIFFUInt64ToFloat(m); -#else *value = (float)m; -#endif return (TIFFReadDirEntryErrOk); } case TIFF_SLONG8: @@ -1130,16 +1121,7 @@ err = TIFFReadDirEntryCheckedLong8(tif, direntry, &m); if (err != TIFFReadDirEntryErrOk) return (err); -#if defined(__WIN32__) && (_MSC_VER < 1500) - /* - * XXX: MSVC 6.0 does not support conversion - * of 64-bit integers into floating point - * values. - */ - *value = _TIFFUInt64ToDouble(m); -#else *value = (double)m; -#endif return (TIFFReadDirEntryErrOk); } case TIFF_SLONG8: @@ -1308,6 +1290,24 @@ datasize = (*count) * typesize; assert((tmsize_t)datasize > 0); + if (datasize > 100 * 1024 * 1024) + { + /* Before allocating a huge amount of memory for corrupted files, check + * if size of requested memory is not greater than file size. + */ + const uint64_t filesize = TIFFGetFileSize(tif); + if (datasize > filesize) + { + TIFFWarningExtR(tif, "ReadDirEntryArray", + "Requested memory size for tag %d (0x%x) %" PRIu32 + " is greater than filesize %" PRIu64 + ". Memory not allocated, tag not read", + direntry->tdir_tag, direntry->tdir_tag, datasize, + filesize); + return (TIFFReadDirEntryErrAlloc); + } + } + if (isMapped(tif) && datasize > (uint64_t)tif->tif_size) return TIFFReadDirEntryErrIo; @@ -2886,16 +2886,7 @@ { if (tif->tif_flags & TIFF_SWAB) TIFFSwabLong8(ma); -#if defined(__WIN32__) && (_MSC_VER < 1500) - /* - * XXX: MSVC 6.0 does not support - * conversion of 64-bit integers into - * floating point values. - */ - *mb++ = _TIFFUInt64ToFloat(*ma++); -#else *mb++ = (float)(*ma++); -#endif } } break; @@ -3131,16 +3122,7 @@ { if (tif->tif_flags & TIFF_SWAB) TIFFSwabLong8(ma); -#if defined(__WIN32__) && (_MSC_VER < 1500) - /* - * XXX: MSVC 6.0 does not support - * conversion of 64-bit integers into - * floating point values. - */ - *mb++ = _TIFFUInt64ToDouble(*ma++); -#else *mb++ = (double)(*ma++); -#endif } } break; @@ -4260,11 +4242,9 @@ dp->tdir_tag, dp->tdir_tag); /* the following knowingly leaks the anonymous field structure */ - if (!_TIFFMergeFields( - tif, - _TIFFCreateAnonField(tif, dp->tdir_tag, - (TIFFDataType)dp->tdir_type), - 1)) + const TIFFField *fld = _TIFFCreateAnonField( + tif, dp->tdir_tag, (TIFFDataType)dp->tdir_type); + if (fld == NULL || !_TIFFMergeFields(tif, fld, 1)) { TIFFWarningExtR( tif, module, @@ -5138,11 +5118,9 @@ "Unknown field with tag %" PRIu16 " (0x%" PRIx16 ") encountered", dp->tdir_tag, dp->tdir_tag); - if (!_TIFFMergeFields( - tif, - _TIFFCreateAnonField(tif, dp->tdir_tag, - (TIFFDataType)dp->tdir_type), - 1)) + const TIFFField *fld = _TIFFCreateAnonField( + tif, dp->tdir_tag, (TIFFDataType)dp->tdir_type); + if (fld == NULL || !_TIFFMergeFields(tif, fld, 1)) { TIFFWarningExtR(tif, module, "Registering anonymous field with tag %" PRIu16 @@ -5238,9 +5216,7 @@ */ int TIFFReadEXIFDirectory(TIFF *tif, toff_t diroff) { - const TIFFFieldArray *exifFieldArray; - exifFieldArray = _TIFFGetExifFields(); - return TIFFReadCustomDirectory(tif, diroff, exifFieldArray); + return TIFFReadCustomDirectory(tif, diroff, _TIFFGetExifFields()); } /* @@ -5248,9 +5224,7 @@ */ int TIFFReadGPSDirectory(TIFF *tif, toff_t diroff) { - const TIFFFieldArray *gpsFieldArray; - gpsFieldArray = _TIFFGetGpsFields(); - return TIFFReadCustomDirectory(tif, diroff, gpsFieldArray); + return TIFFReadCustomDirectory(tif, diroff, _TIFFGetGpsFields()); } static int EstimateStripByteCounts(TIFF *tif, TIFFDirEntry *dir, @@ -5266,6 +5240,24 @@ if (!_TIFFFillStrilesInternal(tif, 0)) return -1; + const uint64_t allocsize = (uint64_t)td->td_nstrips * sizeof(uint64_t); + uint64_t filesize = 0; + if (allocsize > 100 * 1024 * 1024) + { + /* Before allocating a huge amount of memory for corrupted files, check + * if size of requested memory is not greater than file size. */ + filesize = TIFFGetFileSize(tif); + if (allocsize > filesize) + { + TIFFWarningExtR( + tif, module, + "Requested memory size for StripByteCounts of %" PRIu64 + " is greater than filesize %" PRIu64 ". Memory not allocated", + allocsize, filesize); + return -1; + } + } + if (td->td_stripbytecount_p) _TIFFfreeExt(tif, td->td_stripbytecount_p); td->td_stripbytecount_p = (uint64_t *)_TIFFCheckMalloc( @@ -5276,9 +5268,7 @@ if (td->td_compression != COMPRESSION_NONE) { uint64_t space; - uint64_t filesize; uint16_t n; - filesize = TIFFGetFileSize(tif); if (!(tif->tif_flags & TIFF_BIGTIFF)) space = sizeof(TIFFHeaderClassic) + 2 + dircount * 12 + 4; else @@ -5314,6 +5304,8 @@ return -1; space += datasize; } + if (filesize == 0) + filesize = TIFFGetFileSize(tif); if (filesize < space) /* we should perhaps return in error ? */ space = filesize; @@ -5921,6 +5913,20 @@ "directories not supported"); return 0; } + /* Before allocating a huge amount of memory for corrupted files, check + * if size of requested memory is not greater than file size. */ + uint64_t filesize = TIFFGetFileSize(tif); + uint64_t allocsize = (uint64_t)dircount16 * dirsize; + if (allocsize > filesize) + { + TIFFWarningExtR( + tif, module, + "Requested memory size for TIFF directory of %" PRIu64 + " is greater than filesize %" PRIu64 + ". Memory not allocated, TIFF directory not read", + allocsize, filesize); + return 0; + } origdir = _TIFFCheckMalloc(tif, dircount16, dirsize, "to read TIFF directory"); if (origdir == NULL) @@ -5968,6 +5974,8 @@ } } } + /* No check against filesize needed here because "dir" should have same size + * than "origdir" checked above. */ dir = (TIFFDirEntry *)_TIFFCheckMalloc( tif, dircount16, sizeof(TIFFDirEntry), "to read TIFF directory"); if (dir == 0) @@ -6089,15 +6097,15 @@ fip->field_name); else if (mb + 1 > (uint32_t)dp->tdir_count) { - uint8_t *o; - TIFFWarningExtR( - tif, module, - "ASCII value for tag \"%s\" does not end in null byte", - fip->field_name); + TIFFWarningExtR(tif, module, + "ASCII value for tag \"%s\" does not end " + "in null byte. Forcing it to be null", + fip->field_name); /* TIFFReadDirEntryArrayWithLimit() ensures this can't be * larger than MAX_SIZE_TAG_DATA */ assert((uint32_t)dp->tdir_count + 1 == dp->tdir_count + 1); - o = _TIFFmallocExt(tif, (uint32_t)dp->tdir_count + 1); + uint8_t *o = + _TIFFmallocExt(tif, (uint32_t)dp->tdir_count + 1); if (o == NULL) { if (data != NULL) @@ -6597,12 +6605,29 @@ if (data != 0 && dp->tdir_count > 0 && data[dp->tdir_count - 1] != '\0') { - TIFFWarningExtR( - tif, 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'; + TIFFWarningExtR(tif, module, + "ASCII value for ASCII array tag " + "\"%s\" does not end in null " + "byte. Forcing it to be null", + fip->field_name); + /* Enlarge buffer and add terminating null. */ + uint8_t *o = + _TIFFmallocExt(tif, (uint32_t)dp->tdir_count + 1); + if (o == NULL) + { + if (data != NULL) + _TIFFfreeExt(tif, data); + return (0); + } + if (dp->tdir_count > 0) + { + _TIFFmemcpy(o, data, (uint32_t)dp->tdir_count); + } + o[(uint32_t)dp->tdir_count] = 0; + dp->tdir_count++; /* Increment for added null. */ + if (data != 0) + _TIFFfreeExt(tif, data); + data = o; } m = TIFFSetField(tif, dp->tdir_tag, (uint16_t)(dp->tdir_count), data); @@ -6879,11 +6904,29 @@ if (data != 0 && dp->tdir_count > 0 && data[dp->tdir_count - 1] != '\0') { - TIFFWarningExtR(tif, 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'; + TIFFWarningExtR( + tif, module, + "ASCII value for ASCII array tag \"%s\" does not end " + "in null byte. Forcing it to be null", + fip->field_name); + /* Enlarge buffer and add terminating null. */ + uint8_t *o = + _TIFFmallocExt(tif, (uint32_t)dp->tdir_count + 1); + if (o == NULL) + { + if (data != NULL) + _TIFFfreeExt(tif, data); + return (0); + } + if (dp->tdir_count > 0) + { + _TIFFmemcpy(o, data, (uint32_t)dp->tdir_count); + } + o[(uint32_t)dp->tdir_count] = 0; + dp->tdir_count++; /* Increment for added null. */ + if (data != 0) + _TIFFfreeExt(tif, data); + data = o; } m = TIFFSetField(tif, dp->tdir_tag, (uint32_t)(dp->tdir_count), data); @@ -7164,6 +7207,25 @@ return (0); } + const uint64_t allocsize = (uint64_t)nstrips * sizeof(uint64_t); + if (allocsize > 100 * 1024 * 1024) + { + /* Before allocating a huge amount of memory for corrupted files, + * check if size of requested memory is not greater than file size. + */ + const uint64_t filesize = TIFFGetFileSize(tif); + if (allocsize > filesize) + { + TIFFWarningExtR( + tif, module, + "Requested memory size for StripArray of %" PRIu64 + " is greater than filesize %" PRIu64 + ". Memory not allocated", + allocsize, filesize); + _TIFFfreeExt(tif, data); + return (0); + } + } resizeddata = (uint64_t *)_TIFFCheckMalloc( tif, nstrips, sizeof(uint64_t), "for strip array"); if (resizeddata == 0) @@ -7263,6 +7325,26 @@ } bytecount = last_offset + last_bytecount - offset; + /* Before allocating a huge amount of memory for corrupted files, check if + * size of StripByteCount and StripOffset tags is not greater than + * file size. + */ + const uint64_t allocsize = (uint64_t)nstrips * sizeof(uint64_t) * 2; + if (allocsize > 100 * 1024 * 1024) + { + const uint64_t filesize = TIFFGetFileSize(tif); + if (allocsize > filesize) + { + TIFFWarningExtR(tif, "allocChoppedUpStripArrays", + "Requested memory size for StripByteCount and " + "StripOffsets %" PRIu64 + " is greater than filesize %" PRIu64 + ". Memory not allocated", + allocsize, filesize); + return; + } + } + newcounts = (uint64_t *)_TIFFCheckMalloc(tif, nstrips, sizeof(uint64_t), "for chopped \"StripByteCounts\" array"); diff -Nru tiff-4.6.0/libtiff/tif_fax3.c tiff-4.6.1~git240130/libtiff/tif_fax3.c --- tiff-4.6.0/libtiff/tif_fax3.c 2023-09-08 09:12:35.000000000 +0000 +++ tiff-4.6.1~git240130/libtiff/tif_fax3.c 2024-03-04 19:02:20.000000000 +0000 @@ -41,6 +41,14 @@ #include "t4.h" #include +#ifndef EOF_REACHED_COUNT_THRESHOLD +/* Arbitrary threshold to avoid corrupted single-strip files with extremely + * large imageheight to cause apparently endless looping, such as in + * https://gitlab.com/libtiff/libtiff/-/issues/583 + */ +#define EOF_REACHED_COUNT_THRESHOLD 8192 +#endif + /* * Compression+decompression state blocks are * derived from this ``base state'' block. @@ -77,6 +85,8 @@ uint32_t data; /* current i/o byte/word */ int bit; /* current i/o bit in byte */ int EOLcnt; /* count of EOL codes recognized */ + int eofReachedCount; /* number of times decode has been called with + EOF already reached */ TIFFFaxFillFunc fill; /* fill routine */ uint32_t *runs; /* b&w runs for current/previous row */ uint32_t nruns; /* size of the refruns / curruns arrays */ @@ -120,6 +130,7 @@ int EOLcnt; /* # EOL codes recognized */ \ const unsigned char *bitmap = sp->bitmap; /* input data bit reverser */ \ const TIFFFaxTabEnt *TabEnt + #define DECLARE_STATE_2D(tif, sp, mod) \ DECLARE_STATE(tif, sp, mod); \ int b1; /* next change on prev line */ \ @@ -162,6 +173,7 @@ sp->bit = 0; /* force initial read */ sp->data = 0; sp->EOLcnt = 0; /* force initial scan for EOL */ + sp->eofReachedCount = 0; /* * Decoder assumes lsb-to-msb bit order. Note that we select * this here rather than in Fax3SetupState so that viewers can @@ -232,7 +244,12 @@ line, isTiled(tif) ? "tile" : "strip", (isTiled(tif) ? tif->tif_curtile : tif->tif_curstrip), a0); } -#define prematureEOF(a0) Fax3PrematureEOF(module, tif, sp->line, a0) +#define prematureEOF(a0) \ + do \ + { \ + Fax3PrematureEOF(module, tif, sp->line, a0); \ + ++sp->eofReachedCount; \ + } while (0) #define Nop @@ -252,6 +269,14 @@ TIFFErrorExtR(tif, module, "Fractional scanlines cannot be read"); return (-1); } + if (sp->eofReachedCount >= EOF_REACHED_COUNT_THRESHOLD) + { + TIFFErrorExtR( + tif, module, + "End of file has already been reached %d times within that strip", + sp->eofReachedCount); + return (-1); + } CACHE_STATE(tif, sp); thisrun = sp->curruns; while (occ > 0) @@ -302,6 +327,14 @@ TIFFErrorExtR(tif, module, "Fractional scanlines cannot be read"); return (-1); } + if (sp->eofReachedCount >= EOF_REACHED_COUNT_THRESHOLD) + { + TIFFErrorExtR( + tif, module, + "End of file has already been reached %d times within that strip", + sp->eofReachedCount); + return (-1); + } CACHE_STATE(tif, sp); while (occ > 0) { @@ -1514,6 +1547,14 @@ TIFFErrorExtR(tif, module, "Fractional scanlines cannot be read"); return (-1); } + if (sp->eofReachedCount >= EOF_REACHED_COUNT_THRESHOLD) + { + TIFFErrorExtR( + tif, module, + "End of file has already been reached %d times within that strip", + sp->eofReachedCount); + return (-1); + } CACHE_STATE(tif, sp); while (occ > 0) { diff -Nru tiff-4.6.0/libtiff/tif_getimage.c tiff-4.6.1~git240130/libtiff/tif_getimage.c --- tiff-4.6.0/libtiff/tif_getimage.c 2023-09-08 09:12:35.000000000 +0000 +++ tiff-4.6.1~git240130/libtiff/tif_getimage.c 2024-03-04 19:02:20.000000000 +0000 @@ -3224,6 +3224,13 @@ if (TIFFRGBAImageOK(tif, emsg) && TIFFRGBAImageBegin(&img, tif, stop_on_error, emsg)) { + if (row >= img.height) + { + TIFFErrorExtR(tif, TIFFFileName(tif), + "Invalid row passed to TIFFReadRGBAStrip()."); + TIFFRGBAImageEnd(&img); + return (0); + } img.row_offset = row; img.col_offset = 0; @@ -3301,6 +3308,14 @@ return (0); } + if (col >= img.width || row >= img.height) + { + TIFFErrorExtR(tif, TIFFFileName(tif), + "Invalid row/col passed to TIFFReadRGBATile()."); + TIFFRGBAImageEnd(&img); + return (0); + } + /* * The TIFFRGBAImageGet() function doesn't allow us to get off the * edge of the image, even to fill an otherwise valid tile. So we diff -Nru tiff-4.6.0/libtiff/tif_jpeg.c tiff-4.6.1~git240130/libtiff/tif_jpeg.c --- tiff-4.6.0/libtiff/tif_jpeg.c 2023-09-08 09:12:35.000000000 +0000 +++ tiff-4.6.1~git240130/libtiff/tif_jpeg.c 2024-03-04 19:02:20.000000000 +0000 @@ -73,43 +73,6 @@ int scheme, int is_encode); int TIFFJPEGIsFullStripRequired_12(TIFF *tif); -/* We undefine FAR to avoid conflict with JPEG definition */ - -#ifdef FAR -#undef FAR -#endif - -/* - Libjpeg's jmorecfg.h defines INT16 and INT32, but only if XMD_H is - not defined. Unfortunately, the MinGW and Borland compilers include - a typedef for INT32, which causes a conflict. MSVC does not include - a conflicting typedef given the headers which are included. -*/ -#if defined(__BORLANDC__) || defined(__MINGW32__) -#define XMD_H 1 -#endif - -/* - The windows RPCNDR.H file defines boolean, but defines it with the - unsigned char size. You should compile JPEG library using appropriate - definitions in jconfig.h header, but many users compile library in wrong - way. That causes errors of the following type: - - "JPEGLib: JPEG parameter struct mismatch: library thinks size is 432, - caller expects 464" - - For such users we will fix the problem here. See install.doc file from - the JPEG library distribution for details. -*/ - -/* Define "boolean" as unsigned char, not int, per Windows custom. */ -#if defined(__WIN32__) && !defined(__MINGW32__) -#ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */ -typedef unsigned char boolean; -#endif -#define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */ -#endif - #include "jerror.h" #include "jpeglib.h" @@ -182,9 +145,20 @@ #define LONGJMP(jbuf, code) longjmp(jbuf, code) #define JMP_BUF jmp_buf +#ifndef TIFF_jpeg_destination_mgr_defined +#define TIFF_jpeg_destination_mgr_defined typedef struct jpeg_destination_mgr jpeg_destination_mgr; +#endif + +#ifndef TIFF_jpeg_source_mgr_defined +#define TIFF_jpeg_source_mgr_defined typedef struct jpeg_source_mgr jpeg_source_mgr; +#endif + +#ifndef TIFF_jpeg_error_mgr_defined +#define TIFF_jpeg_error_mgr_defined typedef struct jpeg_error_mgr jpeg_error_mgr; +#endif /* * State block for each open TIFF file using diff -Nru tiff-4.6.0/libtiff/tif_lerc.c tiff-4.6.1~git240130/libtiff/tif_lerc.c --- tiff-4.6.0/libtiff/tif_lerc.c 2023-09-08 09:12:35.000000000 +0000 +++ tiff-4.6.1~git240130/libtiff/tif_lerc.c 2024-03-04 19:02:20.000000000 +0000 @@ -86,9 +86,9 @@ TIFFVSetMethod vsetparent; /* super-class method */ } LERCState; -#define LState(tif) ((LERCState *)(tif)->tif_data) -#define DecoderState(tif) LState(tif) -#define EncoderState(tif) LState(tif) +#define GetLERCState(tif) ((LERCState *)(tif)->tif_data) +#define LERCDecoderState(tif) GetLERCState(tif) +#define LERCEncoderState(tif) GetLERCState(tif) static int LERCEncode(TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s); static int LERCDecode(TIFF *tif, uint8_t *op, tmsize_t occ, uint16_t s); @@ -101,7 +101,7 @@ static int LERCSetupDecode(TIFF *tif) { - LERCState *sp = DecoderState(tif); + LERCState *sp = LERCDecoderState(tif); assert(sp != NULL); @@ -277,7 +277,7 @@ static const char module[] = "LERCPreDecode"; lerc_status lerc_ret; TIFFDirectory *td = &tif->tif_dir; - LERCState *sp = DecoderState(tif); + LERCState *sp = LERCDecoderState(tif); int lerc_data_type; unsigned int infoArray[8]; unsigned nomask_bands = td->td_samplesperpixel; @@ -553,7 +553,7 @@ static int LERCDecode(TIFF *tif, uint8_t *op, tmsize_t occ, uint16_t s) { static const char module[] = "LERCDecode"; - LERCState *sp = DecoderState(tif); + LERCState *sp = LERCDecoderState(tif); (void)s; assert(sp != NULL); @@ -580,7 +580,7 @@ static int LERCSetupEncode(TIFF *tif) { - LERCState *sp = EncoderState(tif); + LERCState *sp = LERCEncoderState(tif); assert(sp != NULL); if (sp->state & LSTATE_INIT_DECODE) @@ -599,7 +599,7 @@ static int LERCPreEncode(TIFF *tif, uint16_t s) { static const char module[] = "LERCPreEncode"; - LERCState *sp = EncoderState(tif); + LERCState *sp = LERCEncoderState(tif); int lerc_data_type; (void)s; @@ -623,7 +623,7 @@ static int LERCEncode(TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s) { static const char module[] = "LERCEncode"; - LERCState *sp = EncoderState(tif); + LERCState *sp = LERCEncoderState(tif); (void)s; assert(sp != NULL); @@ -649,7 +649,7 @@ { lerc_status lerc_ret; static const char module[] = "LERCPostEncode"; - LERCState *sp = EncoderState(tif); + LERCState *sp = LERCEncoderState(tif); unsigned int numBytes = 0; unsigned int numBytesWritten = 0; TIFFDirectory *td = &tif->tif_dir; @@ -950,7 +950,7 @@ static void LERCCleanup(TIFF *tif) { - LERCState *sp = LState(tif); + LERCState *sp = GetLERCState(tif); assert(sp != 0); @@ -995,7 +995,7 @@ static int LERCVSetFieldBase(TIFF *tif, uint32_t tag, ...) { - LERCState *sp = LState(tif); + LERCState *sp = GetLERCState(tif); int ret; va_list ap; va_start(ap, tag); @@ -1007,7 +1007,7 @@ static int LERCVSetField(TIFF *tif, uint32_t tag, va_list ap) { static const char module[] = "LERCVSetField"; - LERCState *sp = LState(tif); + LERCState *sp = GetLERCState(tif); switch (tag) { @@ -1115,7 +1115,7 @@ static int LERCVGetField(TIFF *tif, uint32_t tag, va_list ap) { - LERCState *sp = LState(tif); + LERCState *sp = GetLERCState(tif); switch (tag) { @@ -1163,7 +1163,7 @@ tif->tif_data = (uint8_t *)_TIFFcallocExt(tif, 1, sizeof(LERCState)); if (tif->tif_data == NULL) goto bad; - sp = LState(tif); + sp = GetLERCState(tif); /* * Override parent get/set field methods. diff -Nru tiff-4.6.0/libtiff/tif_lzma.c tiff-4.6.1~git240130/libtiff/tif_lzma.c --- tiff-4.6.0/libtiff/tif_lzma.c 2023-09-08 09:12:35.000000000 +0000 +++ tiff-4.6.1~git240130/libtiff/tif_lzma.c 2024-03-04 19:02:20.000000000 +0000 @@ -58,9 +58,9 @@ TIFFVSetMethod vsetparent; /* super-class method */ } LZMAState; -#define LState(tif) ((LZMAState *)(tif)->tif_data) -#define DecoderState(tif) LState(tif) -#define EncoderState(tif) LState(tif) +#define GetLZMAState(tif) ((LZMAState *)(tif)->tif_data) +#define LZMADecoderState(tif) GetLZMAState(tif) +#define LZMAEncoderState(tif) GetLZMAState(tif) static int LZMAEncode(TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s); static int LZMADecode(TIFF *tif, uint8_t *op, tmsize_t occ, uint16_t s); @@ -106,7 +106,7 @@ static int LZMASetupDecode(TIFF *tif) { - LZMAState *sp = DecoderState(tif); + LZMAState *sp = LZMADecoderState(tif); assert(sp != NULL); @@ -127,7 +127,7 @@ static int LZMAPreDecode(TIFF *tif, uint16_t s) { static const char module[] = "LZMAPreDecode"; - LZMAState *sp = DecoderState(tif); + LZMAState *sp = LZMADecoderState(tif); lzma_ret ret; (void)s; @@ -162,7 +162,7 @@ static int LZMADecode(TIFF *tif, uint8_t *op, tmsize_t occ, uint16_t s) { static const char module[] = "LZMADecode"; - LZMAState *sp = DecoderState(tif); + LZMAState *sp = LZMADecoderState(tif); (void)s; assert(sp != NULL); @@ -232,7 +232,7 @@ static int LZMASetupEncode(TIFF *tif) { - LZMAState *sp = EncoderState(tif); + LZMAState *sp = LZMAEncoderState(tif); assert(sp != NULL); if (sp->state & LSTATE_INIT_DECODE) @@ -251,7 +251,7 @@ static int LZMAPreEncode(TIFF *tif, uint16_t s) { static const char module[] = "LZMAPreEncode"; - LZMAState *sp = EncoderState(tif); + LZMAState *sp = LZMAEncoderState(tif); lzma_ret ret; (void)s; @@ -283,7 +283,7 @@ static int LZMAEncode(TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s) { static const char module[] = "LZMAEncode"; - LZMAState *sp = EncoderState(tif); + LZMAState *sp = LZMAEncoderState(tif); assert(sp != NULL); assert(sp->state == LSTATE_INIT_ENCODE); @@ -329,7 +329,7 @@ static int LZMAPostEncode(TIFF *tif) { static const char module[] = "LZMAPostEncode"; - LZMAState *sp = EncoderState(tif); + LZMAState *sp = LZMAEncoderState(tif); lzma_ret ret; sp->stream.avail_in = 0; @@ -365,7 +365,7 @@ static void LZMACleanup(TIFF *tif) { - LZMAState *sp = LState(tif); + LZMAState *sp = GetLZMAState(tif); assert(sp != 0); @@ -388,7 +388,7 @@ static int LZMAVSetField(TIFF *tif, uint32_t tag, va_list ap) { static const char module[] = "LZMAVSetField"; - LZMAState *sp = LState(tif); + LZMAState *sp = GetLZMAState(tif); switch (tag) { @@ -414,7 +414,7 @@ static int LZMAVGetField(TIFF *tif, uint32_t tag, va_list ap) { - LZMAState *sp = LState(tif); + LZMAState *sp = GetLZMAState(tif); switch (tag) { @@ -457,7 +457,7 @@ tif->tif_data = (uint8_t *)_TIFFmallocExt(tif, sizeof(LZMAState)); if (tif->tif_data == NULL) goto bad; - sp = LState(tif); + sp = GetLZMAState(tif); memcpy(&sp->stream, &tmp_stream, sizeof(lzma_stream)); /* diff -Nru tiff-4.6.0/libtiff/tif_lzw.c tiff-4.6.1~git240130/libtiff/tif_lzw.c --- tiff-4.6.0/libtiff/tif_lzw.c 2023-09-08 09:12:35.000000000 +0000 +++ tiff-4.6.1~git240130/libtiff/tif_lzw.c 2024-03-04 19:02:20.000000000 +0000 @@ -161,8 +161,8 @@ } LZWCodecState; #define LZWState(tif) ((LZWBaseState *)(tif)->tif_data) -#define DecoderState(tif) ((LZWCodecState *)LZWState(tif)) -#define EncoderState(tif) ((LZWCodecState *)LZWState(tif)) +#define LZWDecoderState(tif) ((LZWCodecState *)LZWState(tif)) +#define LZWEncoderState(tif) ((LZWCodecState *)LZWState(tif)) static int LZWDecode(TIFF *tif, uint8_t *op0, tmsize_t occ0, uint16_t s); #ifdef LZW_COMPAT @@ -183,7 +183,7 @@ static int LZWSetupDecode(TIFF *tif) { static const char module[] = "LZWSetupDecode"; - LZWCodecState *sp = DecoderState(tif); + LZWCodecState *sp = LZWDecoderState(tif); int code; if (sp == NULL) @@ -199,7 +199,7 @@ return (0); } - sp = DecoderState(tif); + sp = LZWDecoderState(tif); sp->dec_codetab = NULL; sp->dec_decode = NULL; @@ -245,7 +245,7 @@ static int LZWPreDecode(TIFF *tif, uint16_t s) { static const char module[] = "LZWPreDecode"; - LZWCodecState *sp = DecoderState(tif); + LZWCodecState *sp = LZWDecoderState(tif); (void)s; assert(sp != NULL); @@ -329,10 +329,7 @@ #ifdef WORDS_BIGENDIAN #define GetNextData(nextdata, bp) memcpy(&nextdata, bp, sizeof(nextdata)) #elif SIZEOF_WORDTYPE == 8 -#if defined(__GNUC__) && defined(__x86_64__) -#define GetNextData(nextdata, bp) \ - nextdata = __builtin_bswap64(*(uint64_t *)(bp)) -#elif defined(_M_X64) +#if defined(_M_X64) #define GetNextData(nextdata, bp) nextdata = _byteswap_uint64(*(uint64_t *)(bp)) #elif defined(__GNUC__) #define GetNextData(nextdata, bp) \ @@ -346,10 +343,7 @@ (((uint64_t)bp[6]) << 8) | (((uint64_t)bp[7])) #endif #elif SIZEOF_WORDTYPE == 4 -#if defined(__GNUC__) && defined(__i386__) -#define GetNextData(nextdata, bp) \ - nextdata = __builtin_bswap32(*(uint32_t *)(bp)) -#elif defined(_M_X86) +#if defined(_M_X86) #define GetNextData(nextdata, bp) \ nextdata = _byteswap_ulong(*(unsigned long *)(bp)) #elif defined(__GNUC__) @@ -409,7 +403,7 @@ static int LZWDecode(TIFF *tif, uint8_t *op0, tmsize_t occ0, uint16_t s) { static const char module[] = "LZWDecode"; - LZWCodecState *sp = DecoderState(tif); + LZWCodecState *sp = LZWDecoderState(tif); uint8_t *op = (uint8_t *)op0; tmsize_t occ = occ0; uint8_t *bp; @@ -800,7 +794,7 @@ static int LZWDecodeCompat(TIFF *tif, uint8_t *op0, tmsize_t occ0, uint16_t s) { static const char module[] = "LZWDecodeCompat"; - LZWCodecState *sp = DecoderState(tif); + LZWCodecState *sp = LZWDecoderState(tif); uint8_t *op = (uint8_t *)op0; tmsize_t occ = occ0; uint8_t *tp; @@ -1026,7 +1020,7 @@ static int LZWSetupEncode(TIFF *tif) { static const char module[] = "LZWSetupEncode"; - LZWCodecState *sp = EncoderState(tif); + LZWCodecState *sp = LZWEncoderState(tif); assert(sp != NULL); sp->enc_hashtab = (hash_t *)_TIFFmallocExt(tif, HSIZE * sizeof(hash_t)); @@ -1043,7 +1037,7 @@ */ static int LZWPreEncode(TIFF *tif, uint16_t s) { - LZWCodecState *sp = EncoderState(tif); + LZWCodecState *sp = LZWEncoderState(tif); (void)s; assert(sp != NULL); @@ -1114,7 +1108,7 @@ */ static int LZWEncode(TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s) { - register LZWCodecState *sp = EncoderState(tif); + register LZWCodecState *sp = LZWEncoderState(tif); register long fcode; register hash_t *hp; register int h, c; @@ -1299,7 +1293,7 @@ */ static int LZWPostEncode(TIFF *tif) { - register LZWCodecState *sp = EncoderState(tif); + register LZWCodecState *sp = LZWEncoderState(tif); uint8_t *op = tif->tif_rawcp; long nextbits = sp->lzw_nextbits; WordType nextdata = sp->lzw_nextdata; @@ -1381,11 +1375,11 @@ assert(tif->tif_data != 0); - if (DecoderState(tif)->dec_codetab) - _TIFFfreeExt(tif, DecoderState(tif)->dec_codetab); + if (LZWDecoderState(tif)->dec_codetab) + _TIFFfreeExt(tif, LZWDecoderState(tif)->dec_codetab); - if (EncoderState(tif)->enc_hashtab) - _TIFFfreeExt(tif, EncoderState(tif)->enc_hashtab); + if (LZWEncoderState(tif)->enc_hashtab) + _TIFFfreeExt(tif, LZWEncoderState(tif)->enc_hashtab); _TIFFfreeExt(tif, tif->tif_data); tif->tif_data = NULL; @@ -1404,9 +1398,9 @@ tif->tif_data = (uint8_t *)_TIFFmallocExt(tif, sizeof(LZWCodecState)); if (tif->tif_data == NULL) goto bad; - DecoderState(tif)->dec_codetab = NULL; - DecoderState(tif)->dec_decode = NULL; - EncoderState(tif)->enc_hashtab = NULL; + LZWDecoderState(tif)->dec_codetab = NULL; + LZWDecoderState(tif)->dec_decode = NULL; + LZWEncoderState(tif)->enc_hashtab = NULL; LZWState(tif)->rw_mode = tif->tif_mode; /* diff -Nru tiff-4.6.0/libtiff/tif_ojpeg.c tiff-4.6.1~git240130/libtiff/tif_ojpeg.c --- tiff-4.6.0/libtiff/tif_ojpeg.c 2023-09-08 09:12:35.000000000 +0000 +++ tiff-4.6.1~git240130/libtiff/tif_ojpeg.c 2024-03-04 19:02:20.000000000 +0000 @@ -207,37 +207,21 @@ #include #endif -/* We undefine FAR to avoid conflict with JPEG definition */ - -#ifdef FAR -#undef FAR -#endif +#include "jerror.h" +#include "jpeglib.h" -/* - Libjpeg's jmorecfg.h defines INT16 and INT32, but only if XMD_H is - not defined. Unfortunately, the MinGW and Borland compilers include - a typedef for INT32, which causes a conflict. MSVC does not include - a conflicting typedef given the headers which are included. -*/ -#if defined(__BORLANDC__) || defined(__MINGW32__) -#define XMD_H 1 +#ifndef TIFF_jpeg_source_mgr_defined +#define TIFF_jpeg_source_mgr_defined +typedef struct jpeg_source_mgr jpeg_source_mgr; #endif -/* Define "boolean" as unsigned char, not int, per Windows custom. */ -#if defined(__WIN32__) && !defined(__MINGW32__) -#ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */ -typedef unsigned char boolean; -#endif -#define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */ +#ifndef TIFF_jpeg_error_mgr_defined +#define TIFF_jpeg_error_mgr_defined +typedef struct jpeg_error_mgr jpeg_error_mgr; #endif -#include "jerror.h" -#include "jpeglib.h" - -typedef struct jpeg_error_mgr jpeg_error_mgr; typedef struct jpeg_common_struct jpeg_common_struct; typedef struct jpeg_decompress_struct jpeg_decompress_struct; -typedef struct jpeg_source_mgr jpeg_source_mgr; typedef enum { diff -Nru tiff-4.6.0/libtiff/tif_open.c tiff-4.6.1~git240130/libtiff/tif_open.c --- tiff-4.6.0/libtiff/tif_open.c 2023-09-08 09:12:35.000000000 +0000 +++ tiff-4.6.1~git240130/libtiff/tif_open.c 2024-03-04 19:02:20.000000000 +0000 @@ -25,7 +25,13 @@ /* * TIFF Library. */ + +#ifdef TIFF_DO_NOT_USE_NON_EXT_ALLOC_FUNCTIONS +#undef TIFF_DO_NOT_USE_NON_EXT_ALLOC_FUNCTIONS +#endif + #include "tiffiop.h" +#include #include /* @@ -81,8 +87,9 @@ void TIFFOpenOptionsFree(TIFFOpenOptions *opts) { _TIFFfree(opts); } /** Define a limit in bytes for a single memory allocation done by libtiff. - * If max_single_mem_alloc is set to 0, no other limit that the underlying - * _TIFFmalloc() will be applied, which is the default. + * If max_single_mem_alloc is set to 0, which is the default, no other limit + * that the underlying _TIFFmalloc() or + * TIFFOpenOptionsSetMaxCumulatedMemAlloc() will be applied. */ void TIFFOpenOptionsSetMaxSingleMemAlloc(TIFFOpenOptions *opts, tmsize_t max_single_mem_alloc) @@ -90,6 +97,18 @@ opts->max_single_mem_alloc = max_single_mem_alloc; } +/** Define a limit in bytes for the cumulated memory allocations done by libtiff + * on a given TIFF handle. + * If max_cumulated_mem_alloc is set to 0, which is the default, no other limit + * that the underlying _TIFFmalloc() or + * TIFFOpenOptionsSetMaxSingleMemAlloc() will be applied. + */ +void TIFFOpenOptionsSetMaxCumulatedMemAlloc(TIFFOpenOptions *opts, + tmsize_t max_cumulated_mem_alloc) +{ + opts->max_cumulated_mem_alloc = max_cumulated_mem_alloc; +} + void TIFFOpenOptionsSetErrorHandlerExtR(TIFFOpenOptions *opts, TIFFErrorHandlerExtR handler, void *errorhandler_user_data) @@ -117,6 +136,30 @@ (uint64_t)s, (uint64_t)tif->tif_max_single_mem_alloc); } +static void _TIFFEmitErrorAboveMaxCumulatedMemAlloc(TIFF *tif, + const char *pszFunction, + tmsize_t s) +{ + TIFFErrorExtR(tif, pszFunction, + "Cumulated memory allocation of %" PRIu64 " + %" PRIu64 + " bytes is beyond the %" PRIu64 + " cumulated byte limit defined in open options", + (uint64_t)tif->tif_cur_cumulated_mem_alloc, (uint64_t)s, + (uint64_t)tif->tif_max_cumulated_mem_alloc); +} + +/* When allocating memory, we write at the beginning of the buffer it size. + * This allows us to keep track of the total memory allocated when we + * malloc/calloc/realloc and free. In theory we need just SIZEOF_SIZE_T bytes + * for that, but on x86_64, allocations of more than 16 bytes are aligned on + * 16 bytes. Hence using 2 * SIZEOF_SIZE_T. + * It is critical that _TIFFmallocExt/_TIFFcallocExt/_TIFFreallocExt are + * paired with _TIFFfreeExt. + * CMakeLists.txt defines TIFF_DO_NOT_USE_NON_EXT_ALLOC_FUNCTIONS, which in + * turn disables the definition of the non Ext version in tiffio.h + */ +#define LEADING_AREA_TO_STORE_ALLOC_SIZE (2 * SIZEOF_SIZE_T) + /** malloc() version that takes into account memory-specific open options */ void *_TIFFmallocExt(TIFF *tif, tmsize_t s) { @@ -126,16 +169,32 @@ _TIFFEmitErrorAboveMaxSingleMemAlloc(tif, "_TIFFmallocExt", s); return NULL; } + if (tif != NULL && tif->tif_max_cumulated_mem_alloc > 0) + { + if (s > tif->tif_max_cumulated_mem_alloc - + tif->tif_cur_cumulated_mem_alloc || + s > TIFF_TMSIZE_T_MAX - LEADING_AREA_TO_STORE_ALLOC_SIZE) + { + _TIFFEmitErrorAboveMaxCumulatedMemAlloc(tif, "_TIFFmallocExt", s); + return NULL; + } + void *ptr = _TIFFmalloc(LEADING_AREA_TO_STORE_ALLOC_SIZE + s); + if (!ptr) + return NULL; + tif->tif_cur_cumulated_mem_alloc += s; + memcpy(ptr, &s, sizeof(s)); + return (char *)ptr + LEADING_AREA_TO_STORE_ALLOC_SIZE; + } return _TIFFmalloc(s); } /** calloc() version that takes into account memory-specific open options */ void *_TIFFcallocExt(TIFF *tif, tmsize_t nmemb, tmsize_t siz) { + if (nmemb <= 0 || siz <= 0 || nmemb > TIFF_TMSIZE_T_MAX / siz) + return NULL; if (tif != NULL && tif->tif_max_single_mem_alloc > 0) { - if (nmemb <= 0 || siz <= 0 || nmemb > TIFF_TMSIZE_T_MAX / siz) - return NULL; if (nmemb * siz > tif->tif_max_single_mem_alloc) { _TIFFEmitErrorAboveMaxSingleMemAlloc(tif, "_TIFFcallocExt", @@ -143,6 +202,23 @@ return NULL; } } + if (tif != NULL && tif->tif_max_cumulated_mem_alloc > 0) + { + const tmsize_t s = nmemb * siz; + if (s > tif->tif_max_cumulated_mem_alloc - + tif->tif_cur_cumulated_mem_alloc || + s > TIFF_TMSIZE_T_MAX - LEADING_AREA_TO_STORE_ALLOC_SIZE) + { + _TIFFEmitErrorAboveMaxCumulatedMemAlloc(tif, "_TIFFcallocExt", s); + return NULL; + } + void *ptr = _TIFFcalloc(LEADING_AREA_TO_STORE_ALLOC_SIZE + s, 1); + if (!ptr) + return NULL; + tif->tif_cur_cumulated_mem_alloc += s; + memcpy(ptr, &s, sizeof(s)); + return (char *)ptr + LEADING_AREA_TO_STORE_ALLOC_SIZE; + } return _TIFFcalloc(nmemb, siz); } @@ -155,13 +231,49 @@ _TIFFEmitErrorAboveMaxSingleMemAlloc(tif, "_TIFFreallocExt", s); return NULL; } + if (tif != NULL && tif->tif_max_cumulated_mem_alloc > 0) + { + void *oldPtr = p; + tmsize_t oldSize = 0; + if (p) + { + oldPtr = (char *)p - LEADING_AREA_TO_STORE_ALLOC_SIZE; + memcpy(&oldSize, oldPtr, sizeof(oldSize)); + assert(oldSize <= tif->tif_cur_cumulated_mem_alloc); + } + if (s > oldSize && + (s > tif->tif_max_cumulated_mem_alloc - + (tif->tif_cur_cumulated_mem_alloc - oldSize) || + s > TIFF_TMSIZE_T_MAX - LEADING_AREA_TO_STORE_ALLOC_SIZE)) + { + _TIFFEmitErrorAboveMaxCumulatedMemAlloc(tif, "_TIFFreallocExt", + s - oldSize); + return NULL; + } + void *newPtr = + _TIFFrealloc(oldPtr, LEADING_AREA_TO_STORE_ALLOC_SIZE + s); + if (newPtr == NULL) + return NULL; + tif->tif_cur_cumulated_mem_alloc -= oldSize; + tif->tif_cur_cumulated_mem_alloc += s; + memcpy(newPtr, &s, sizeof(s)); + return (char *)newPtr + LEADING_AREA_TO_STORE_ALLOC_SIZE; + } return _TIFFrealloc(p, s); } /** free() version that takes into account memory-specific open options */ void _TIFFfreeExt(TIFF *tif, void *p) { - (void)tif; + if (p != NULL && tif != NULL && tif->tif_max_cumulated_mem_alloc > 0) + { + void *oldPtr = (char *)p - LEADING_AREA_TO_STORE_ALLOC_SIZE; + tmsize_t oldSize; + memcpy(&oldSize, oldPtr, sizeof(oldSize)); + assert(oldSize <= tif->tif_cur_cumulated_mem_alloc); + tif->tif_cur_cumulated_mem_alloc -= oldSize; + p = oldPtr; + } _TIFFfree(p); } @@ -231,6 +343,17 @@ (uint64_t)opts->max_single_mem_alloc); goto bad2; } + if (opts && opts->max_cumulated_mem_alloc > 0 && + size_to_alloc > opts->max_cumulated_mem_alloc) + { + _TIFFErrorEarly(opts, clientdata, module, + "%s: Memory allocation of %" PRIu64 + " bytes is beyond the %" PRIu64 + " cumulated byte limit defined in open options", + name, (uint64_t)size_to_alloc, + (uint64_t)opts->max_cumulated_mem_alloc); + goto bad2; + } tif = (TIFF *)_TIFFmallocExt(NULL, size_to_alloc); if (tif == NULL) { @@ -261,6 +384,7 @@ tif->tif_warnhandler = opts->warnhandler; tif->tif_warnhandler_user_data = opts->warnhandler_user_data; tif->tif_max_single_mem_alloc = opts->max_single_mem_alloc; + tif->tif_max_cumulated_mem_alloc = opts->max_cumulated_mem_alloc; } if (!readproc || !writeproc || !seekproc || !closeproc || !sizeproc) diff -Nru tiff-4.6.0/libtiff/tif_pixarlog.c tiff-4.6.1~git240130/libtiff/tif_pixarlog.c --- tiff-4.6.0/libtiff/tif_pixarlog.c 2023-09-08 09:12:35.000000000 +0000 +++ tiff-4.6.1~git240130/libtiff/tif_pixarlog.c 2024-03-04 19:02:20.000000000 +0000 @@ -670,8 +670,8 @@ return 1; } -#define DecoderState(tif) ((PixarLogState *)(tif)->tif_data) -#define EncoderState(tif) ((PixarLogState *)(tif)->tif_data) +#define PixarLogDecoderState(tif) ((PixarLogState *)(tif)->tif_data) +#define PixarLogEncoderState(tif) ((PixarLogState *)(tif)->tif_data) static int PixarLogEncode(TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s); static int PixarLogDecode(TIFF *tif, uint8_t *op, tmsize_t occ, uint16_t s); @@ -740,7 +740,7 @@ { static const char module[] = "PixarLogSetupDecode"; TIFFDirectory *td = &tif->tif_dir; - PixarLogState *sp = DecoderState(tif); + PixarLogState *sp = PixarLogDecoderState(tif); tmsize_t tbuf_size; uint32_t strip_height; @@ -813,7 +813,7 @@ static int PixarLogPreDecode(TIFF *tif, uint16_t s) { static const char module[] = "PixarLogPreDecode"; - PixarLogState *sp = DecoderState(tif); + PixarLogState *sp = PixarLogDecoderState(tif); (void)s; assert(sp != NULL); @@ -835,7 +835,7 @@ { static const char module[] = "PixarLogDecode"; TIFFDirectory *td = &tif->tif_dir; - PixarLogState *sp = DecoderState(tif); + PixarLogState *sp = PixarLogDecoderState(tif); tmsize_t i; tmsize_t nsamples; int llen; @@ -988,7 +988,7 @@ { static const char module[] = "PixarLogSetupEncode"; TIFFDirectory *td = &tif->tif_dir; - PixarLogState *sp = EncoderState(tif); + PixarLogState *sp = PixarLogEncoderState(tif); tmsize_t tbuf_size; assert(sp != NULL); @@ -1038,7 +1038,7 @@ static int PixarLogPreEncode(TIFF *tif, uint16_t s) { static const char module[] = "PixarLogPreEncode"; - PixarLogState *sp = EncoderState(tif); + PixarLogState *sp = PixarLogEncoderState(tif); (void)s; assert(sp != NULL); @@ -1294,7 +1294,7 @@ { static const char module[] = "PixarLogEncode"; TIFFDirectory *td = &tif->tif_dir; - PixarLogState *sp = EncoderState(tif); + PixarLogState *sp = PixarLogEncoderState(tif); tmsize_t i; tmsize_t n; int llen; @@ -1401,7 +1401,7 @@ static int PixarLogPostEncode(TIFF *tif) { static const char module[] = "PixarLogPostEncode"; - PixarLogState *sp = EncoderState(tif); + PixarLogState *sp = PixarLogEncoderState(tif); int state; sp->stream.avail_in = 0; diff -Nru tiff-4.6.0/libtiff/tif_read.c tiff-4.6.1~git240130/libtiff/tif_read.c --- tiff-4.6.0/libtiff/tif_read.c 2023-09-08 09:12:35.000000000 +0000 +++ tiff-4.6.1~git240130/libtiff/tif_read.c 2024-03-04 19:02:20.000000000 +0000 @@ -105,8 +105,8 @@ TIFFErrorExtR(tif, module, "Invalid buffer size"); return 0; } - new_rawdata = - (uint8_t *)_TIFFrealloc(tif->tif_rawdata, tif->tif_rawdatasize); + new_rawdata = (uint8_t *)_TIFFreallocExt(tif, tif->tif_rawdata, + tif->tif_rawdatasize); if (new_rawdata == 0) { TIFFErrorExtR(tif, module, diff -Nru tiff-4.6.0/libtiff/tif_unix.c tiff-4.6.1~git240130/libtiff/tif_unix.c --- tiff-4.6.0/libtiff/tif_unix.c 2023-09-08 09:12:35.000000000 +0000 +++ tiff-4.6.1~git240130/libtiff/tif_unix.c 2024-03-04 19:02:20.000000000 +0000 @@ -27,6 +27,10 @@ * Windows Common RunTime Library. */ +#ifdef TIFF_DO_NOT_USE_NON_EXT_ALLOC_FUNCTIONS +#undef TIFF_DO_NOT_USE_NON_EXT_ALLOC_FUNCTIONS +#endif + #include "tif_config.h" #ifdef HAVE_SYS_TYPES_H @@ -258,7 +262,7 @@ return tif; } -#ifdef __WIN32__ +#ifdef _WIN32 #include /* * Open a TIFF file with a Unicode filename, for read/writing. diff -Nru tiff-4.6.0/libtiff/tif_win32.c tiff-4.6.1~git240130/libtiff/tif_win32.c --- tiff-4.6.0/libtiff/tif_win32.c 2023-09-08 09:12:35.000000000 +0000 +++ tiff-4.6.1~git240130/libtiff/tif_win32.c 2024-03-04 19:02:20.000000000 +0000 @@ -27,6 +27,10 @@ * Scott Wagner (wagner@itek.com), Itek Graphix, Rochester, NY USA */ +#ifdef TIFF_DO_NOT_USE_NON_EXT_ALLOC_FUNCTIONS +#undef TIFF_DO_NOT_USE_NON_EXT_ALLOC_FUNCTIONS +#endif + #include "tiffiop.h" #include diff -Nru tiff-4.6.0/libtiff/tif_zip.c tiff-4.6.1~git240130/libtiff/tif_zip.c --- tiff-4.6.0/libtiff/tif_zip.c 2023-09-08 09:12:35.000000000 +0000 +++ tiff-4.6.1~git240130/libtiff/tif_zip.c 2024-03-04 19:02:20.000000000 +0000 @@ -83,9 +83,9 @@ TIFFVSetMethod vsetparent; /* super-class method */ } ZIPState; -#define ZState(tif) ((ZIPState *)(tif)->tif_data) -#define DecoderState(tif) ZState(tif) -#define EncoderState(tif) ZState(tif) +#define GetZIPState(tif) ((ZIPState *)(tif)->tif_data) +#define ZIPDecoderState(tif) GetZIPState(tif) +#define ZIPEncoderState(tif) GetZIPState(tif) static int ZIPEncode(TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s); static int ZIPDecode(TIFF *tif, uint8_t *op, tmsize_t occ, uint16_t s); @@ -99,7 +99,7 @@ static int ZIPSetupDecode(TIFF *tif) { static const char module[] = "ZIPSetupDecode"; - ZIPState *sp = DecoderState(tif); + ZIPState *sp = ZIPDecoderState(tif); assert(sp != NULL); @@ -131,7 +131,7 @@ */ static int ZIPPreDecode(TIFF *tif, uint16_t s) { - ZIPState *sp = DecoderState(tif); + ZIPState *sp = ZIPDecoderState(tif); (void)s; assert(sp != NULL); @@ -156,7 +156,7 @@ static int ZIPDecode(TIFF *tif, uint8_t *op, tmsize_t occ, uint16_t s) { static const char module[] = "ZIPDecode"; - ZIPState *sp = DecoderState(tif); + ZIPState *sp = ZIPDecoderState(tif); (void)s; assert(sp != NULL); @@ -290,7 +290,7 @@ static int ZIPSetupEncode(TIFF *tif) { static const char module[] = "ZIPSetupEncode"; - ZIPState *sp = EncoderState(tif); + ZIPState *sp = ZIPEncoderState(tif); int cappedQuality; assert(sp != NULL); @@ -321,7 +321,7 @@ */ static int ZIPPreEncode(TIFF *tif, uint16_t s) { - ZIPState *sp = EncoderState(tif); + ZIPState *sp = ZIPEncoderState(tif); (void)s; assert(sp != NULL); @@ -348,7 +348,7 @@ static int ZIPEncode(TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s) { static const char module[] = "ZIPEncode"; - ZIPState *sp = EncoderState(tif); + ZIPState *sp = ZIPEncoderState(tif); assert(sp != NULL); assert(sp->state == ZSTATE_INIT_ENCODE); @@ -487,7 +487,7 @@ static int ZIPPostEncode(TIFF *tif) { static const char module[] = "ZIPPostEncode"; - ZIPState *sp = EncoderState(tif); + ZIPState *sp = ZIPEncoderState(tif); int state; #if LIBDEFLATE_SUPPORT @@ -526,7 +526,7 @@ static void ZIPCleanup(TIFF *tif) { - ZIPState *sp = ZState(tif); + ZIPState *sp = GetZIPState(tif); assert(sp != 0); @@ -562,7 +562,7 @@ static int ZIPVSetField(TIFF *tif, uint32_t tag, va_list ap) { static const char module[] = "ZIPVSetField"; - ZIPState *sp = ZState(tif); + ZIPState *sp = GetZIPState(tif); switch (tag) { @@ -628,7 +628,7 @@ static int ZIPVGetField(TIFF *tif, uint32_t tag, va_list ap) { - ZIPState *sp = ZState(tif); + ZIPState *sp = GetZIPState(tif); switch (tag) { @@ -680,7 +680,7 @@ tif->tif_data = (uint8_t *)_TIFFcallocExt(tif, sizeof(ZIPState), 1); if (tif->tif_data == NULL) goto bad; - sp = ZState(tif); + sp = GetZIPState(tif); sp->stream.zalloc = NULL; sp->stream.zfree = NULL; sp->stream.opaque = NULL; diff -Nru tiff-4.6.0/libtiff/tif_zstd.c tiff-4.6.1~git240130/libtiff/tif_zstd.c --- tiff-4.6.0/libtiff/tif_zstd.c 2023-09-08 09:12:35.000000000 +0000 +++ tiff-4.6.1~git240130/libtiff/tif_zstd.c 2024-03-04 19:02:20.000000000 +0000 @@ -54,9 +54,9 @@ TIFFVSetMethod vsetparent; /* super-class method */ } ZSTDState; -#define LState(tif) ((ZSTDState *)(tif)->tif_data) -#define DecoderState(tif) LState(tif) -#define EncoderState(tif) LState(tif) +#define GetZSTDState(tif) ((ZSTDState *)(tif)->tif_data) +#define ZSTDDecoderState(tif) GetZSTDState(tif) +#define ZSTDEncoderState(tif) GetZSTDState(tif) static int ZSTDEncode(TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s); static int ZSTDDecode(TIFF *tif, uint8_t *op, tmsize_t occ, uint16_t s); @@ -69,7 +69,7 @@ static int ZSTDSetupDecode(TIFF *tif) { - ZSTDState *sp = DecoderState(tif); + ZSTDState *sp = ZSTDDecoderState(tif); assert(sp != NULL); @@ -91,7 +91,7 @@ static int ZSTDPreDecode(TIFF *tif, uint16_t s) { static const char module[] = "ZSTDPreDecode"; - ZSTDState *sp = DecoderState(tif); + ZSTDState *sp = ZSTDDecoderState(tif); size_t zstd_ret; (void)s; @@ -124,7 +124,7 @@ static int ZSTDDecode(TIFF *tif, uint8_t *op, tmsize_t occ, uint16_t s) { static const char module[] = "ZSTDDecode"; - ZSTDState *sp = DecoderState(tif); + ZSTDState *sp = ZSTDDecoderState(tif); ZSTD_inBuffer in_buffer; ZSTD_outBuffer out_buffer; size_t zstd_ret; @@ -170,7 +170,7 @@ static int ZSTDSetupEncode(TIFF *tif) { - ZSTDState *sp = EncoderState(tif); + ZSTDState *sp = ZSTDEncoderState(tif); assert(sp != NULL); if (sp->state & LSTATE_INIT_DECODE) @@ -190,7 +190,7 @@ static int ZSTDPreEncode(TIFF *tif, uint16_t s) { static const char module[] = "ZSTDPreEncode"; - ZSTDState *sp = EncoderState(tif); + ZSTDState *sp = ZSTDEncoderState(tif); size_t zstd_ret; (void)s; @@ -229,7 +229,7 @@ static int ZSTDEncode(TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s) { static const char module[] = "ZSTDEncode"; - ZSTDState *sp = EncoderState(tif); + ZSTDState *sp = ZSTDEncoderState(tif); ZSTD_inBuffer in_buffer; size_t zstd_ret; @@ -271,7 +271,7 @@ static int ZSTDPostEncode(TIFF *tif) { static const char module[] = "ZSTDPostEncode"; - ZSTDState *sp = EncoderState(tif); + ZSTDState *sp = ZSTDEncoderState(tif); size_t zstd_ret; do @@ -297,7 +297,7 @@ static void ZSTDCleanup(TIFF *tif) { - ZSTDState *sp = LState(tif); + ZSTDState *sp = GetZSTDState(tif); assert(sp != 0); @@ -325,7 +325,7 @@ static int ZSTDVSetField(TIFF *tif, uint32_t tag, va_list ap) { static const char module[] = "ZSTDVSetField"; - ZSTDState *sp = LState(tif); + ZSTDState *sp = GetZSTDState(tif); switch (tag) { @@ -347,7 +347,7 @@ static int ZSTDVGetField(TIFF *tif, uint32_t tag, va_list ap) { - ZSTDState *sp = LState(tif); + ZSTDState *sp = GetZSTDState(tif); switch (tag) { @@ -389,7 +389,7 @@ tif->tif_data = (uint8_t *)_TIFFmallocExt(tif, sizeof(ZSTDState)); if (tif->tif_data == NULL) goto bad; - sp = LState(tif); + sp = GetZSTDState(tif); /* * Override parent get/set field methods. diff -Nru tiff-4.6.0/libtiff/tiffio.h tiff-4.6.1~git240130/libtiff/tiffio.h --- tiff-4.6.0/libtiff/tiffio.h 2023-09-08 09:12:35.000000000 +0000 +++ tiff-4.6.1~git240130/libtiff/tiffio.h 2024-03-04 19:02:20.000000000 +0000 @@ -77,10 +77,6 @@ typedef tmsize_t tsize_t; /* i/o size in bytes */ typedef void *tdata_t; /* image data ref */ -#if !defined(__WIN32__) && (defined(_WIN32) || defined(WIN32)) -#define __WIN32__ -#endif - /* * On windows you should define USE_WIN32_FILEIO if you are using tif_win32.c * or AVOID_WIN32_FILEIO if you are using something else (like tif_unix.c). @@ -88,7 +84,7 @@ * By default tif_unix.c is assumed. */ -#if defined(_WINDOWS) || defined(__WIN32__) || defined(_Windows) +#if defined(_WIN32) #if !defined(__CYGWIN) && !defined(AVOID_WIN32_FILEIO) && \ !defined(USE_WIN32_FILEIO) #define AVOID_WIN32_FILEIO @@ -98,11 +94,11 @@ #if defined(USE_WIN32_FILEIO) #define VC_EXTRALEAN #include -#ifdef __WIN32__ +#ifdef _WIN32 DECLARE_HANDLE(thandle_t); /* Win32 file handle */ #else typedef HFILE thandle_t; /* client data handle */ -#endif /* __WIN32__ */ +#endif /* _WIN32 */ #else typedef void *thandle_t; /* client data handle */ #endif /* USE_WIN32_FILEIO */ @@ -311,14 +307,15 @@ /* * Auxiliary functions. */ - +#ifndef TIFF_DO_NOT_USE_NON_EXT_ALLOC_FUNCTIONS extern void *_TIFFmalloc(tmsize_t s); extern void *_TIFFcalloc(tmsize_t nmemb, tmsize_t siz); extern void *_TIFFrealloc(void *p, tmsize_t s); + extern void _TIFFfree(void *p); +#endif extern void _TIFFmemset(void *p, int v, tmsize_t c); extern void _TIFFmemcpy(void *d, const void *s, tmsize_t c); extern int _TIFFmemcmp(const void *p1, const void *p2, tmsize_t c); - extern void _TIFFfree(void *p); /* ** Stuff, related to tag handling and creating custom tags. @@ -508,6 +505,9 @@ TIFFOpenOptionsSetMaxSingleMemAlloc(TIFFOpenOptions *opts, tmsize_t max_single_mem_alloc); extern void + TIFFOpenOptionsSetMaxCumulatedMemAlloc(TIFFOpenOptions *opts, + tmsize_t max_cumulated_mem_alloc); + extern void TIFFOpenOptionsSetErrorHandlerExtR(TIFFOpenOptions *opts, TIFFErrorHandlerExtR handler, void *errorhandler_user_data); @@ -518,11 +518,11 @@ extern TIFF *TIFFOpen(const char *, const char *); extern TIFF *TIFFOpenExt(const char *, const char *, TIFFOpenOptions *opts); -#ifdef __WIN32__ +#ifdef _WIN32 extern TIFF *TIFFOpenW(const wchar_t *, const char *); extern TIFF *TIFFOpenWExt(const wchar_t *, const char *, TIFFOpenOptions *opts); -#endif /* __WIN32__ */ +#endif /* _WIN32 */ extern TIFF *TIFFFdOpen(int, const char *, const char *); extern TIFF *TIFFFdOpenExt(int, const char *, const char *, TIFFOpenOptions *opts); diff -Nru tiff-4.6.0/libtiff/tiffiop.h tiff-4.6.1~git240130/libtiff/tiffiop.h --- tiff-4.6.0/libtiff/tiffiop.h 2023-09-08 09:12:35.000000000 +0000 +++ tiff-4.6.1~git240130/libtiff/tiffiop.h 2024-03-04 19:02:20.000000000 +0000 @@ -233,7 +233,9 @@ void *tif_errorhandler_user_data; TIFFErrorHandlerExtR tif_warnhandler; void *tif_warnhandler_user_data; - tmsize_t tif_max_single_mem_alloc; /* in bytes. 0 for unlimited */ + tmsize_t tif_max_single_mem_alloc; /* in bytes. 0 for unlimited */ + tmsize_t tif_max_cumulated_mem_alloc; /* in bytes. 0 for unlimited */ + tmsize_t tif_cur_cumulated_mem_alloc; /* in bytes */ }; struct TIFFOpenOptions @@ -243,6 +245,7 @@ TIFFErrorHandlerExtR warnhandler; /* may be NULL */ void *warnhandler_user_data; /* may be NULL */ tmsize_t max_single_mem_alloc; /* in bytes. 0 for unlimited */ + tmsize_t max_cumulated_mem_alloc; /* in bytes. 0 for unlimited */ }; #define isPseudoTag(t) (t > 0xffff) /* is tag value normal or pseudo */ @@ -331,7 +334,7 @@ #define ftell(stream, offset, whence) ftello(stream, offset, whence) #endif #endif -#if defined(__WIN32__) && !(defined(_MSC_VER) && _MSC_VER < 1400) && \ +#if defined(_WIN32) && \ !(defined(__MSVCRT_VERSION__) && __MSVCRT_VERSION__ < 0x800) typedef unsigned int TIFFIOSize_t; #define _TIFF_lseek_f(fildes, offset, whence) \ @@ -437,9 +440,6 @@ extern void *_TIFFCheckRealloc(TIFF *, void *, tmsize_t, tmsize_t, const char *); - extern double _TIFFUInt64ToDouble(uint64_t); - extern float _TIFFUInt64ToFloat(uint64_t); - extern float _TIFFClampDoubleToFloat(double); extern uint32_t _TIFFClampDoubleToUInt32(double); diff -Nru tiff-4.6.0/test/rational_precision2double.c tiff-4.6.1~git240130/test/rational_precision2double.c --- tiff-4.6.0/test/rational_precision2double.c 2023-09-08 09:12:35.000000000 +0000 +++ tiff-4.6.1~git240130/test/rational_precision2double.c 2024-03-04 19:02:20.000000000 +0000 @@ -67,8 +67,6 @@ #include "tiffiop.h" #include "tifftest.h" -#include "tif_dirwrite.c" - int write_test_tiff(TIFF *tif, const char *filenameRead, int blnAllCustomTags); #define SPP 3 /* Samples per pixel */ diff -Nru tiff-4.6.0/test/raw_decode.c tiff-4.6.1~git240130/test/raw_decode.c --- tiff-4.6.0/test/raw_decode.c 2023-09-08 09:12:35.000000000 +0000 +++ tiff-4.6.1~git240130/test/raw_decode.c 2024-03-04 19:02:20.000000000 +0000 @@ -40,36 +40,6 @@ #include "tiffio.h" -/* - Libjpeg's jmorecfg.h defines INT16 and INT32, but only if XMD_H is - not defined. Unfortunately, the MinGW and Borland compilers include - a typedef for INT32, which causes a conflict. MSVC does not include - a conficting typedef given the headers which are included. -*/ -#if defined(__BORLANDC__) || defined(__MINGW32__) -#define XMD_H 1 -#endif - -/* - The windows RPCNDR.H file defines boolean, but defines it with the - unsigned char size. You should compile JPEG library using appropriate - definitions in jconfig.h header, but many users compile library in wrong - way. That causes errors of the following type: - - "JPEGLib: JPEG parameter struct mismatch: library thinks size is 432, - caller expects 464" - - For such users we will fix the problem here. See install.doc file from - the JPEG library distribution for details. -*/ - -/* Define "boolean" as unsigned char, not int, per Windows custom. */ -#if defined(__WIN32__) && !defined(__MINGW32__) -#ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */ -typedef unsigned char boolean; -#endif -#define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */ -#endif #include "jpeglib.h" /* Needed for JPEG_LIB_VERSION */ static unsigned char cluster_0[] = {0, 0, 2, 0, 138, 139}; diff -Nru tiff-4.6.0/test/rewrite_tag.c tiff-4.6.1~git240130/test/rewrite_tag.c --- tiff-4.6.0/test/rewrite_tag.c 2023-09-08 09:12:35.000000000 +0000 +++ tiff-4.6.1~git240130/test/rewrite_tag.c 2024-03-04 19:02:20.000000000 +0000 @@ -39,7 +39,6 @@ #include "tiffio.h" #include "tiffiop.h" -const uint32_t length = 40; const uint32_t rows_per_strip = 1; int test_packbits() diff -Nru tiff-4.6.0/test/test_directory.c tiff-4.6.1~git240130/test/test_directory.c --- tiff-4.6.0/test/test_directory.c 2023-09-08 09:12:35.000000000 +0000 +++ tiff-4.6.1~git240130/test/test_directory.c 2024-03-04 19:02:20.000000000 +0000 @@ -758,7 +758,7 @@ } tdir_t numberOfMainIFDs = TIFFNumberOfDirectories(tif); - if (numberOfMainIFDs != N_DIRECTORIES - number_of_sub_IFDs) + if (numberOfMainIFDs != (tdir_t)N_DIRECTORIES - number_of_sub_IFDs) { fprintf(stderr, "Unexpected number of directories in %s. Expected %i, " diff -Nru tiff-4.6.0/test/test_open_options.c tiff-4.6.1~git240130/test/test_open_options.c --- tiff-4.6.0/test/test_open_options.c 2023-09-08 09:12:35.000000000 +0000 +++ tiff-4.6.1~git240130/test/test_open_options.c 2024-03-04 19:02:20.000000000 +0000 @@ -214,6 +214,63 @@ return ret; } +static int test_TIFFOpenOptionsSetMaxCumulatedMemAlloc( + tmsize_t limit, int expected_to_fail_in_open, + int expected_to_fail_in_write_directory) +{ + int ret = 0; + TIFFOpenOptions *opts = TIFFOpenOptionsAlloc(); + assert(opts); + TIFFOpenOptionsSetMaxCumulatedMemAlloc(opts, limit); + TIFF *tif = TIFFOpenExt("test_error_handler.tif", "w", opts); + TIFFOpenOptionsFree(opts); + if (expected_to_fail_in_open) + { + if (tif != NULL) + { + fprintf( + stderr, + "Expected TIFFOpenExt() to fail due to memory limitation\n"); + ret = 1; + TIFFClose(tif); + } + } + else + { + if (tif == NULL) + { + fprintf(stderr, "Expected TIFFOpenExt() to succeed\n"); + ret = 1; + } + else + { +#define VALUE_SAMPLESPERPIXEL 10000 + TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, VALUE_SAMPLESPERPIXEL); + TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8); + if (TIFFWriteDirectory(tif) == 0) + { + if (!expected_to_fail_in_write_directory) + { + fprintf(stderr, + "Expected TIFFWriteDirectory() to succeed\n"); + ret = 1; + } + } + else + { + if (expected_to_fail_in_write_directory) + { + fprintf(stderr, "Expected TIFFWriteDirectory() to fail\n"); + ret = 1; + } + } + TIFFClose(tif); + } + } + unlink("test_error_handler.tif"); + return ret; +} + int main() { int ret = 0; @@ -234,5 +291,14 @@ sizeof(TIFF) + strlen("test_error_handler.tif") + 1, FALSE, TRUE, TRUE); ret += test_TIFFOpenOptionsSetMaxSingleMemAlloc( VALUE_SAMPLESPERPIXEL * sizeof(short), FALSE, FALSE, TRUE); + + fprintf(stderr, "---- test_TIFFOpenOptionsSetMaxCumulatedMemAlloc ---- \n"); + ret += test_TIFFOpenOptionsSetMaxCumulatedMemAlloc(1, TRUE, -1); + ret += test_TIFFOpenOptionsSetMaxCumulatedMemAlloc( + sizeof(TIFF) + strlen("test_error_handler.tif") + 1, FALSE, TRUE); + ret += test_TIFFOpenOptionsSetMaxCumulatedMemAlloc( + sizeof(TIFF) + strlen("test_error_handler.tif") + 1 + 30000, FALSE, + FALSE); + return ret; } diff -Nru tiff-4.6.0/test/test_transferfunction_write_read.c tiff-4.6.1~git240130/test/test_transferfunction_write_read.c --- tiff-4.6.0/test/test_transferfunction_write_read.c 2023-09-08 09:12:35.000000000 +0000 +++ tiff-4.6.1~git240130/test/test_transferfunction_write_read.c 2024-03-04 19:02:20.000000000 +0000 @@ -39,7 +39,6 @@ const uint16_t photometric = PHOTOMETRIC_RGB; const uint16_t rows_per_strip = 100; /* up to 2**32-1 */ const uint16_t planarconfig = PLANARCONFIG_CONTIG; -const char *filename = "test_transferfunction_write_read.tif"; /* Data and pointer to three transfer functions. */ uint16_t *pTransferFunctionData; @@ -266,6 +265,9 @@ /*==== main() ====*/ int main() { + + const char *filename = "test_transferfunction_write_read.tif"; + if (setup_transfer_functions()) return 1; diff -Nru tiff-4.6.0/test/test_write_read_tags.c tiff-4.6.1~git240130/test/test_write_read_tags.c --- tiff-4.6.0/test/test_write_read_tags.c 2023-09-08 09:12:35.000000000 +0000 +++ tiff-4.6.1~git240130/test/test_write_read_tags.c 2024-03-04 19:02:20.000000000 +0000 @@ -158,14 +158,14 @@ int check_tag_definitions(void); int write_test_tiff(TIFF *tif, const char *filenameRead); int write_all_tags(TIFF *tif, const TIFFFieldArray *tFieldArray, - uint32_t *listTagsNotToWrite, uint32_t nTagsInList, + uint32_t *plistTagsNotToWrite, uint32_t nTagsInList, uint32_t *iCnt); int tagIsInList(uint32_t tTag, uint32_t *list, uint32_t nTagsInList); int testPasscountFlag(const char *szMsg, const TIFFFieldArray *tFieldArray, - uint32_t *listTagsNotFollowPasscountRules, + uint32_t *plistTagsNotFollowPasscountRules, uint32_t nTagsInList); int read_all_tags(TIFF *tif, const TIFFFieldArray *tFieldArray, - uint32_t *listTagsNotToWrite, uint32_t nTagsNotToWrite, + uint32_t *plistTagsNotToWrite, uint32_t nTagsNotToWrite, uint32_t *iCnt); /* ==== main() ======================================================== @@ -686,7 +686,7 @@ * */ int testPasscountFlag(const char *szMsg, const TIFFFieldArray *tFieldArray, - uint32_t *listTagsNotFollowPasscountRules, + uint32_t *plistTagsNotFollowPasscountRules, uint32_t nTagsInList) { uint32_t t; @@ -699,7 +699,7 @@ for (t = 0; t < nTags; t++) { if (tagIsInList(tFieldArray->fields[t].field_tag, - listTagsNotFollowPasscountRules, nTagsInList)) + plistTagsNotFollowPasscountRules, nTagsInList)) continue; if (tFieldArray->fields[t].field_writecount != @@ -728,7 +728,7 @@ for (t = 0; t < nTags; t++) { if (tagIsInList(tFieldArray->fields[t].field_tag, - listTagsNotFollowPasscountRules, nTagsInList)) + plistTagsNotFollowPasscountRules, nTagsInList)) continue; if (tFieldArray->fields[t].field_writecount < 0) @@ -828,7 +828,7 @@ for (t = 0; t < nTags; t++) { if (tagIsInList(tFieldArray->fields[t].field_tag, - listTagsNotFollowPasscountRules, nTagsInList)) + plistTagsNotFollowPasscountRules, nTagsInList)) continue; /* TIFF_SETGET_UNDEFINED tags FIELD_IGNORE tags are not written to file. @@ -935,7 +935,7 @@ * iCnt is an index into predefined arrays for the values to write. */ int write_all_tags(TIFF *tif, const TIFFFieldArray *tFieldArray, - uint32_t *listTagsNotToWrite, uint32_t nTagsInList, + uint32_t *plistTagsNotToWrite, uint32_t nTagsInList, uint32_t *iCnt) { @@ -950,7 +950,7 @@ uint32_t variableArrayCount = VARIABLE_ARRAY_SIZE; uint32_t tTag = tFieldArray->fields[t].field_tag; - if (tagIsInList(tTag, listTagsNotToWrite, nTagsInList)) + if (tagIsInList(tTag, plistTagsNotToWrite, nTagsInList)) continue; TIFFDataType tType = @@ -1271,7 +1271,7 @@ * The read values are compared to the written ones. */ int read_all_tags(TIFF *tif, const TIFFFieldArray *tFieldArray, - uint32_t *listTagsNotToWrite, uint32_t nTagsNotToWrite, + uint32_t *plistTagsNotToWrite, uint32_t nTagsNotToWrite, uint32_t *iCnt) { @@ -1315,7 +1315,7 @@ tFieldArray->fields[t] .set_field_type; /* e.g. TIFF_SETGET_C0_FLOAT */ char *tFieldName = tFieldArray->fields[t].field_name; - if (tagIsInList(tTag, listTagsNotToWrite, nTagsNotToWrite)) + if (tagIsInList(tTag, plistTagsNotToWrite, nTagsNotToWrite)) continue; /*-- dependent on set_field_type read value --*/ diff -Nru tiff-4.6.0/tools/CMakeLists.txt tiff-4.6.1~git240130/tools/CMakeLists.txt --- tiff-4.6.0/tools/CMakeLists.txt 2023-09-08 09:12:35.000000000 +0000 +++ tiff-4.6.1~git240130/tools/CMakeLists.txt 2024-03-04 19:02:20.000000000 +0000 @@ -22,8 +22,8 @@ # LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE # OF THIS SOFTWARE. -# MSVC specific resource preparation -if (WIN32 AND MSVC) +# Windows specific resource preparation +if (WIN32) message(STATUS "Include resource version information for TOOLS") set(MSVC_RESSOURCE_FILE tif_tools_versioninfo.rc) source_group("Resource Files" FILES tif_tools_versioninfo.rc) diff -Nru tiff-4.6.0/tools/tiffcp.c tiff-4.6.1~git240130/tools/tiffcp.c --- tiff-4.6.0/tools/tiffcp.c 2023-09-08 09:12:35.000000000 +0000 +++ tiff-4.6.1~git240130/tools/tiffcp.c 2024-03-04 19:02:20.000000000 +0000 @@ -87,7 +87,7 @@ static int ignore = FALSE; /* if true, ignore read errors */ static uint32_t defg3opts = (uint32_t)-1; static int quality = 75; /* JPEG quality */ -static int jpegcolormode = JPEGCOLORMODE_RGB; +static int jpeg_photometric = PHOTOMETRIC_YCBCR; static uint16_t defcompression = (uint16_t)-1; static uint16_t defpredictor = (uint16_t)-1; static int defpreset = -1; @@ -490,7 +490,7 @@ if (isdigit((int)cp[1])) quality = atoi(cp + 1); else if (cp[1] == 'r') - jpegcolormode = JPEGCOLORMODE_RAW; + jpeg_photometric = PHOTOMETRIC_RGB; else usage(EXIT_FAILURE); @@ -808,10 +808,6 @@ {TIFFTAG_DOTRANGE, 2, TIFF_SHORT}, {TIFFTAG_TARGETPRINTER, 1, TIFF_ASCII}, {TIFFTAG_SAMPLEFORMAT, 1, TIFF_SHORT}, - {TIFFTAG_YCBCRCOEFFICIENTS, (uint16_t)-1, TIFF_RATIONAL}, - {TIFFTAG_YCBCRSUBSAMPLING, 2, TIFF_SHORT}, - {TIFFTAG_YCBCRPOSITIONING, 1, TIFF_SHORT}, - {TIFFTAG_REFERENCEBLACKWHITE, (uint16_t)-1, TIFF_RATIONAL}, {TIFFTAG_EXTRASAMPLES, (uint16_t)-1, TIFF_SHORT}, {TIFFTAG_SMINSAMPLEVALUE, 1, TIFF_DOUBLE}, {TIFFTAG_SMAXSAMPLEVALUE, 1, TIFF_DOUBLE}, @@ -846,6 +842,8 @@ if (!TIFFIsCODECConfigured(compression)) return FALSE; TIFFGetFieldDefaulted(in, TIFFTAG_COMPRESSION, &input_compression); + if (!TIFFIsCODECConfigured(input_compression)) + return FALSE; TIFFGetFieldDefaulted(in, TIFFTAG_PHOTOMETRIC, &input_photometric); if (input_compression == COMPRESSION_JPEG) { @@ -869,9 +867,29 @@ } if (compression == COMPRESSION_JPEG) { - if (input_photometric == PHOTOMETRIC_RGB && - jpegcolormode == JPEGCOLORMODE_RGB) - TIFFSetField(out, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_YCBCR); + if (input_photometric == PHOTOMETRIC_RGB || + input_photometric == PHOTOMETRIC_YCBCR) + { + TIFFSetField(out, TIFFTAG_PHOTOMETRIC, jpeg_photometric); + if (jpeg_photometric == PHOTOMETRIC_YCBCR) + { + uint16_t subsamplinghor = 2, subsamplingver = 2; + if (input_compression == COMPRESSION_JPEG && + input_photometric == PHOTOMETRIC_YCBCR) + { + TIFFGetFieldDefaulted(in, TIFFTAG_YCBCRSUBSAMPLING, + &subsamplinghor, &subsamplingver); + + float *refBW = NULL; + if (TIFFGetField(in, TIFFTAG_REFERENCEBLACKWHITE, &refBW)) + { + TIFFSetField(out, TIFFTAG_REFERENCEBLACKWHITE, refBW); + } + } + TIFFSetField(out, TIFFTAG_YCBCRSUBSAMPLING, subsamplinghor, + subsamplingver); + } + } else TIFFSetField(out, TIFFTAG_PHOTOMETRIC, input_photometric); } @@ -880,14 +898,13 @@ TIFFSetField(out, TIFFTAG_PHOTOMETRIC, samplesperpixel == 1 ? PHOTOMETRIC_LOGL : PHOTOMETRIC_LOGLUV); - else if (input_compression == COMPRESSION_JPEG && samplesperpixel == 3) + else { - /* RGB conversion was forced above - hence the output will be of the same type */ - TIFFSetField(out, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB); + if (input_photometric == PHOTOMETRIC_YCBCR) + TIFFSetField(out, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB); + else + CopyTag(TIFFTAG_PHOTOMETRIC, 1, TIFF_SHORT); } - else - CopyTag(TIFFTAG_PHOTOMETRIC, 1, TIFF_SHORT); if (fillorder != 0) TIFFSetField(out, TIFFTAG_FILLORDER, fillorder); else @@ -952,7 +969,9 @@ { case COMPRESSION_JPEG: TIFFSetField(out, TIFFTAG_JPEGQUALITY, quality); - TIFFSetField(out, TIFFTAG_JPEGCOLORMODE, jpegcolormode); + /* For 3 sample images, the input data provided to libtiff is + * always RGB, not YCbCr subsampled. */ + TIFFSetField(out, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB); break; case COMPRESSION_JBIG: CopyTag(TIFFTAG_FAXRECVPARAMS, 1, TIFF_LONG); @@ -1112,7 +1131,9 @@ } for (p = tags; p < &tags[NTAGS]; p++) + { CopyTag(p->tag, p->count, p->type); + } cf = pickCopyFunc(in, out, bitspersample, samplesperpixel); return (cf ? (*cf)(in, out, length, width, samplesperpixel) : FALSE); @@ -1178,11 +1199,11 @@ static void subtract##bits(void *i, void *b, uint32_t pixels) \ { \ uint##bits##_t *image = i; \ - uint##bits##_t *bias = b; \ + uint##bits##_t *biasx = b; \ while (pixels--) \ { \ - *image = *image > *bias ? *image - *bias : 0; \ - image++, bias++; \ + *image = *image > *biasx ? *image - *biasx : 0; \ + image++, biasx++; \ } \ } @@ -1833,7 +1854,7 @@ DECLAREwriteFunc(writeBufferToContigStrips) { - uint32_t row, rowsperstrip; + uint32_t row; tstrip_t strip = 0; (void)imagewidth; @@ -1858,7 +1879,6 @@ DECLAREwriteFunc(writeBufferToSeparateStrips) { uint32_t rowsize = imagewidth * spp; - uint32_t rowsperstrip; tsize_t stripsize = TIFFStripSize(out); tdata_t obuf; tstrip_t strip = 0; @@ -1894,7 +1914,7 @@ uint32_t nrows = (row + rowsperstrip > imagelength) ? imagelength - row : rowsperstrip; - tsize_t stripsize = TIFFVStripSize(out, nrows); + stripsize = TIFFVStripSize(out, nrows); cpContigBufToSeparateBuf(obuf, (uint8_t *)buf + row * rowsize + s, nrows, imagewidth, 0, 0, spp, diff -Nru tiff-4.6.0/tools/tiffset.c tiff-4.6.1~git240130/tools/tiffset.c --- tiff-4.6.0/tools/tiffset.c 2023-09-08 09:12:35.000000000 +0000 +++ tiff-4.6.1~git240130/tools/tiffset.c 2024-03-04 19:02:20.000000000 +0000 @@ -55,7 +55,7 @@ does not distribute the CRT (it is supplied by Microsoft) so the correct CRT must be available on the target computer in order for the program to run. */ -#if defined(__WIN32__) && !(defined(_MSC_VER) && _MSC_VER < 1400) && \ +#if defined(_WIN32) && !(defined(_MSC_VER) && _MSC_VER < 1400) && \ !(defined(__MSVCRT_VERSION__) && __MSVCRT_VERSION__ < 0x800) #define TIFFfseek(stream, offset, whence) \ _fseeki64(stream, /* __int64 */ offset, whence) diff -Nru tiff-4.6.0/tools/unsupported/CMakeLists.txt tiff-4.6.1~git240130/tools/unsupported/CMakeLists.txt --- tiff-4.6.0/tools/unsupported/CMakeLists.txt 2023-09-08 09:12:35.000000000 +0000 +++ tiff-4.6.1~git240130/tools/unsupported/CMakeLists.txt 2024-03-04 19:02:20.000000000 +0000 @@ -24,8 +24,8 @@ message(STATUS "==== Tools - Unsupported =========") -# MSVC specific resource preparation -if (WIN32 AND MSVC) +# Windows specific resource preparation +if (WIN32) message(STATUS "Include resource version information for TOOLS-UNSUPPORTED") set(MSVC_RESSOURCE_FILE tif_tools-unsupported_versioninfo.rc) source_group("Resource Files" FILES tif_tools-unsupported_versioninfo.rc) diff -Nru tiff-4.6.0/tools/unsupported/tiff2ps.c tiff-4.6.1~git240130/tools/unsupported/tiff2ps.c --- tiff-4.6.0/tools/unsupported/tiff2ps.c 2023-09-08 09:12:35.000000000 +0000 +++ tiff-4.6.1~git240130/tools/unsupported/tiff2ps.c 2024-03-04 19:02:20.000000000 +0000 @@ -181,7 +181,7 @@ * disabled when set to 0 */ static tmsize_t maxMalloc = DEFAULT_MAX_MALLOC; -int ascii85 = FALSE; /* use ASCII85 encoding */ +int ascii85_g = FALSE; /* use ASCII85 encoding */ int interpolate = TRUE; /* interpolate level2 image */ int level2 = FALSE; /* generate PostScript level 2 */ int level3 = FALSE; /* generate PostScript level 3 */ @@ -195,8 +195,8 @@ double maxPageWidth = 0; /* maximum width to select from image and print per page */ double splitOverlap = 0; /* amount for split pages to overlag */ -int rotation = 0; /* optional value for rotation angle */ -int auto_rotate = 0; /* rotate image for best fit on the page */ +int rotation_g = 0; /* optional value for rotation angle */ +int auto_rotate_g = 0; /* rotate image for best fit on the page */ char *filename = NULL; /* input filename */ char *title = NULL; /* optional document title string */ char *creator = NULL; /* optional document creator string */ @@ -390,15 +390,15 @@ case 'r': if (strcmp(optarg, "auto") == 0) { - rotation = 0; - auto_rotate = TRUE; + rotation_g = 0; + auto_rotate_g = TRUE; } else { - rotation = atoi(optarg); - auto_rotate = FALSE; + rotation_g = atoi(optarg); + auto_rotate_g = FALSE; } - switch (rotation) + switch (rotation_g) { case 0: case 90: @@ -426,18 +426,18 @@ case '1': level2 = FALSE; level3 = FALSE; - ascii85 = FALSE; + ascii85_g = FALSE; break; case '2': level2 = TRUE; - ascii85 = TRUE; /* default to yes */ + ascii85_g = TRUE; /* default to yes */ break; case '3': level3 = TRUE; - ascii85 = TRUE; /* default to yes */ + ascii85_g = TRUE; /* default to yes */ break; case '8': - ascii85 = FALSE; + ascii85_g = FALSE; break; case 'x': res_unit = RESUNIT_CENTIMETER; @@ -467,7 +467,7 @@ } /* auto rotate requires a specified page width and height */ - if (auto_rotate == TRUE) + if (auto_rotate_g == TRUE) { /* if ((pageWidth == 0) || (pageHeight == 0)) @@ -1438,7 +1438,7 @@ TIFFError("exportMaskedImage", "Invalid image parameters."); return (-1); } - PSpage(fd, tif, pixwidth, pixheight); + PSpage(fd, tif, (uint32_t)pixwidth, (uint32_t)pixheight); fprintf(fd, "end\n"); fprintf(fd, "grestore\n"); fprintf(fd, "showpage\n"); @@ -1768,7 +1768,7 @@ view_height = psheight; if (get_viewport(pgwidth, pgheight, pswidth, psheight, &view_width, - &view_height, rotation)) + &view_height, rotation_g)) { TIFFError("get_viewport", "Unable to set image viewport"); return (1); @@ -1776,9 +1776,9 @@ /* Write the Postscript file header with Bounding Box and Page Size * definitions */ - if (psStart(fd, npages, auto_rotate, &rotation, &scale, ox, oy, pgwidth, - pgheight, view_width, view_height, pswidth, psheight, - left_offset, bottom_offset)) + if (psStart(fd, npages, auto_rotate_g, &rotation_g, &scale, ox, oy, + pgwidth, pgheight, view_width, view_height, pswidth, + psheight, left_offset, bottom_offset)) return (-1); if (checkImage(tif)) /* Aborts if unsupported image parameters */ @@ -1792,7 +1792,7 @@ if ((maxPageHeight) || (maxPageWidth)) /* used -H or -W option */ { - if (psMaskImage(fd, tif, rotation, center, &npages, + if (psMaskImage(fd, tif, rotation_g, center, &npages, pixwidth, pixheight, left_offset, bottom_offset, pgwidth, pgheight, pswidth, psheight, scale) < 0) @@ -1812,14 +1812,14 @@ if (!generateEPSF && (level2 || level3)) { /* Write out the PageSize info for non EPS files */ - if (psPageSize(fd, rotation, pgwidth, pgheight, + if (psPageSize(fd, rotation_g, pgwidth, pgheight, view_width, view_height, pswidth, psheight)) return (-1); } fprintf(fd, "gsave\n"); fprintf(fd, "100 dict begin\n"); - if (psScaleImage(fd, scale, rotation, center, + if (psScaleImage(fd, scale, rotation_g, center, view_width, view_height, pswidth, psheight, left_offset, bottom_offset)) return (-1); @@ -1839,14 +1839,14 @@ if (!generateEPSF && (level2 || level3)) { /* Write out the PageSize info for non EPS files */ - if (psPageSize(fd, rotation, pgwidth, pgheight, view_width, - view_height, pswidth, psheight)) + if (psPageSize(fd, rotation_g, pgwidth, pgheight, + view_width, view_height, pswidth, psheight)) return (-1); } fprintf(fd, "gsave\n"); fprintf(fd, "100 dict begin\n"); - if (psRotateImage(fd, rotation, pswidth, psheight, left_offset, - bottom_offset)) + if (psRotateImage(fd, rotation_g, pswidth, psheight, + left_offset, bottom_offset)) return (-1); PSpage(fd, tif, pixwidth, pixheight); @@ -1857,8 +1857,8 @@ } if (generateEPSF) break; - if (auto_rotate) - rotation = 0.0; + if (auto_rotate_g) + rotation_g = 0; TIFFGetFieldDefaulted(tif, TIFFTAG_SUBFILETYPE, &subfiletype); } while (((subfiletype & FILETYPE_PAGE) || printAll) && TIFFReadDirectory(tif)); @@ -2013,7 +2013,7 @@ #undef CVT } fprintf(fd, "[ /Indexed /DeviceRGB %d", num_colors - 1); - if (ascii85) + if (ascii85_g) { Ascii85Init(); fputs("\n<~", fd); @@ -2023,7 +2023,7 @@ fputs(" <", fd); for (i = 0; i < num_colors; i++) { - if (ascii85) + if (ascii85_g) { Ascii85Put((unsigned char)rmap[i], fd); Ascii85Put((unsigned char)gmap[i], fd); @@ -2036,7 +2036,7 @@ gmap[i], bmap[i]); } } - if (ascii85) + if (ascii85_g) Ascii85Flush(fd); else fputs(">\n", fd); @@ -2111,7 +2111,7 @@ /* * Output filter options and image dictionary. */ - if (ascii85) + if (ascii85_g) fputs(" /im_stream currentfile /ASCII85Decode filter def\n", fd); fputs(" <<\n", fd); fputs(" /ImageType 1\n", fd); @@ -2209,7 +2209,7 @@ fputs(" /DataSource", fd); if (planarconfiguration == PLANARCONFIG_SEPARATE && samplesperpixel > 1) fputs(" [", fd); - if (ascii85) + if (ascii85_g) fputs(" im_stream", fd); else fputs(" currentfile /ASCIIHexDecode filter", fd); @@ -2344,7 +2344,7 @@ } fprintf(fd, "\n >> %s\n", imageOp); - if (ascii85) + if (ascii85_g) fputs(" im_stream status { im_stream flushfile } if\n", fd); if (repeat_count > 1) { @@ -2463,7 +2463,7 @@ } #if defined(EXP_ASCII85ENCODER) - if (ascii85) + if (ascii85_g) { /* * Allocate a buffer to hold the ASCII85 encoded data. Note @@ -2489,7 +2489,7 @@ TIFFGetFieldDefaulted(tif, TIFFTAG_FILLORDER, &fillorder); for (chunk_no = 0; chunk_no < num_chunks; chunk_no++) { - if (ascii85) + if (ascii85_g) Ascii85Init(); else breaklen = MAXLINE; @@ -2517,7 +2517,7 @@ { TIFFError(filename, "Can't read %s %" PRIu32 ".", tiled_image ? "tile" : "strip", chunk_no); - if (ascii85) + if (ascii85_g) Ascii85Put('\0', fd); } /* @@ -2561,7 +2561,7 @@ byte_count -= j; } - if (ascii85) + if (ascii85_g) { #if defined(EXP_ASCII85ENCODER) ascii85_l = Ascii85EncodeBlock(ascii85_p, 1, buf_data, byte_count); @@ -2589,7 +2589,7 @@ } } - if (!ascii85) + if (!ascii85_g) { if (level2 || level3) putc('>', fd); @@ -2966,7 +2966,7 @@ memset(tf_buf, 0, stripsize); #if defined(EXP_ASCII85ENCODER) - if (ascii85) + if (ascii85_g) { /* * Allocate a buffer to hold the ASCII85 encoded data. Note @@ -2989,7 +2989,7 @@ } #endif - if (ascii85) + if (ascii85_g) Ascii85Init(); for (s = 0; s < TIFFNumberOfStrips(tif); s++) @@ -3015,7 +3015,7 @@ { PS_FlipBytes(cp, cc); } - if (ascii85) + if (ascii85_g) { #if defined(EXP_ASCII85ENCODER) if (alpha) @@ -3072,7 +3072,7 @@ } } - if (!ascii85) + if (!ascii85_g) { if (level2 || level3) fputs(">\n", fd); @@ -3129,7 +3129,7 @@ } #if defined(EXP_ASCII85ENCODER) - if (ascii85) + if (ascii85_g) { /* * Allocate a buffer to hold the ASCII85 encoded data. Note @@ -3162,7 +3162,7 @@ } if (fillorder == FILLORDER_LSB2MSB) TIFFReverseBits(tf_buf, cc); - if (!ascii85) + if (!ascii85_g) { for (cp = tf_buf; cc > 0; cc--) {