summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuli Suominen <ssuominen@gentoo.org>2010-02-05 21:04:44 +0000
committerSamuli Suominen <ssuominen@gentoo.org>2010-02-05 21:04:44 +0000
commitf77b0c5c1b8541ef3a8358ad201753c3bcb487cb (patch)
tree3a246f29e720541a87aa73743b9885cc9be6bf51 /media-libs/tiff/files
parentFix LICENSE (#301969). Maintenance (diff)
downloadhistorical-f77b0c5c1b8541ef3a8358ad201753c3bcb487cb.tar.gz
historical-f77b0c5c1b8541ef3a8358ad201753c3bcb487cb.tar.bz2
historical-f77b0c5c1b8541ef3a8358ad201753c3bcb487cb.zip
old
Package-Manager: portage-2.2_rc62/cvs/Linux x86_64
Diffstat (limited to 'media-libs/tiff/files')
-rw-r--r--media-libs/tiff/files/tiff-3.8.2-CVE-2008-2327.patch64
-rw-r--r--media-libs/tiff/files/tiff-3.8.2-CVE-2009-2285.patch6
-rw-r--r--media-libs/tiff/files/tiff-3.8.2-CVE-2009-2347.patch170
-rw-r--r--media-libs/tiff/files/tiff-3.8.2-opengl.patch19
-rw-r--r--media-libs/tiff/files/tiff-3.8.2-tiffsplit.patch20
-rw-r--r--media-libs/tiff/files/tiff-jbig.patch510
6 files changed, 2 insertions, 787 deletions
diff --git a/media-libs/tiff/files/tiff-3.8.2-CVE-2008-2327.patch b/media-libs/tiff/files/tiff-3.8.2-CVE-2008-2327.patch
deleted file mode 100644
index e6d74a67ab05..000000000000
--- a/media-libs/tiff/files/tiff-3.8.2-CVE-2008-2327.patch
+++ /dev/null
@@ -1,64 +0,0 @@
-Fixes security issues in libTIFF's handling of LZW-encoded
-images. The use of uninitialized data could lead to a buffer
-underflow and a crash or arbitrary code execution.
-
-CVE-ID: CVE-2008-2327
-Security bug: https://bugs.gentoo.org/show_bug.cgi?id=234080
-
-Index: tiff-3.8.2/libtiff/tif_lzw.c
-===================================================================
---- tiff-3.8.2.orig/libtiff/tif_lzw.c
-+++ tiff-3.8.2/libtiff/tif_lzw.c
-@@ -237,6 +237,12 @@ LZWSetupDecode(TIFF* tif)
- sp->dec_codetab[code].length = 1;
- sp->dec_codetab[code].next = NULL;
- } while (code--);
-+ /*
-+ * Zero-out the unused entries
-+ */
-+ _TIFFmemset(&sp->dec_codetab[CODE_CLEAR], 0,
-+ (CODE_FIRST-CODE_CLEAR)*sizeof (code_t));
-+
- }
- return (1);
- }
-@@ -408,12 +414,19 @@ LZWDecode(TIFF* tif, tidata_t op0, tsize
- break;
- if (code == CODE_CLEAR) {
- free_entp = sp->dec_codetab + CODE_FIRST;
-+ _TIFFmemset(free_entp, 0, (CSIZE-CODE_FIRST)*sizeof (code_t));
- nbits = BITS_MIN;
- nbitsmask = MAXCODE(BITS_MIN);
- maxcodep = sp->dec_codetab + nbitsmask-1;
- NextCode(tif, sp, bp, code, GetNextCode);
- if (code == CODE_EOI)
- break;
-+ if (code == CODE_CLEAR) {
-+ TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
-+ "LZWDecode: Corrupted LZW table at scanline %d",
-+ tif->tif_row);
-+ return (0);
-+ }
- *op++ = (char)code, occ--;
- oldcodep = sp->dec_codetab + code;
- continue;
-@@ -604,12 +617,19 @@ LZWDecodeCompat(TIFF* tif, tidata_t op0,
- break;
- if (code == CODE_CLEAR) {
- free_entp = sp->dec_codetab + CODE_FIRST;
-+ _TIFFmemset(free_entp, 0, (CSIZE-CODE_FIRST)*sizeof (code_t));
- nbits = BITS_MIN;
- nbitsmask = MAXCODE(BITS_MIN);
- maxcodep = sp->dec_codetab + nbitsmask;
- NextCode(tif, sp, bp, code, GetNextCodeCompat);
- if (code == CODE_EOI)
- break;
-+ if (code == CODE_CLEAR) {
-+ TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
-+ "LZWDecode: Corrupted LZW table at scanline %d",
-+ tif->tif_row);
-+ return (0);
-+ }
- *op++ = code, occ--;
- oldcodep = sp->dec_codetab + code;
- continue;
diff --git a/media-libs/tiff/files/tiff-3.8.2-CVE-2009-2285.patch b/media-libs/tiff/files/tiff-3.8.2-CVE-2009-2285.patch
index 3eeb75668362..6cca90184d9f 100644
--- a/media-libs/tiff/files/tiff-3.8.2-CVE-2009-2285.patch
+++ b/media-libs/tiff/files/tiff-3.8.2-CVE-2009-2285.patch
@@ -1,7 +1,5 @@
-Index: tiff-3.8.2/libtiff/tif_lzw.c
-===================================================================
---- tiff-3.8.2.orig/libtiff/tif_lzw.c
-+++ tiff-3.8.2/libtiff/tif_lzw.c
+--- libtiff/tif_lzw.c
++++ libtiff/tif_lzw.c
@@ -421,7 +421,7 @@ LZWDecode(TIFF* tif, tidata_t op0, tsize
NextCode(tif, sp, bp, code, GetNextCode);
if (code == CODE_EOI)
diff --git a/media-libs/tiff/files/tiff-3.8.2-CVE-2009-2347.patch b/media-libs/tiff/files/tiff-3.8.2-CVE-2009-2347.patch
deleted file mode 100644
index 039d7336a27b..000000000000
--- a/media-libs/tiff/files/tiff-3.8.2-CVE-2009-2347.patch
+++ /dev/null
@@ -1,170 +0,0 @@
-Fix several places in tiff2rgba and rgb2ycbcr that were being careless about
-possible integer overflow in calculation of buffer sizes.
-
-CVE-2009-2347
-
-
-diff -Naur tiff-3.8.2.orig/tools/rgb2ycbcr.c tiff-3.8.2/tools/rgb2ycbcr.c
---- tiff-3.8.2.orig/tools/rgb2ycbcr.c 2004-09-03 03:57:13.000000000 -0400
-+++ tiff-3.8.2/tools/rgb2ycbcr.c 2009-07-10 17:12:32.000000000 -0400
-@@ -202,6 +202,17 @@
- #undef LumaBlue
- #undef V2Code
-
-+static tsize_t
-+multiply(tsize_t m1, tsize_t m2)
-+{
-+ tsize_t prod = m1 * m2;
-+
-+ if (m1 && prod / m1 != m2)
-+ prod = 0; /* overflow */
-+
-+ return prod;
-+}
-+
- /*
- * Convert a strip of RGB data to YCbCr and
- * sample to generate the output data.
-@@ -278,10 +289,19 @@
- float floatv;
- char *stringv;
- uint32 longv;
-+ tsize_t raster_size;
-
- TIFFGetField(in, TIFFTAG_IMAGEWIDTH, &width);
- TIFFGetField(in, TIFFTAG_IMAGELENGTH, &height);
-- raster = (uint32*)_TIFFmalloc(width * height * sizeof (uint32));
-+
-+ raster_size = multiply(multiply(width, height), sizeof (uint32));
-+ if (!raster_size) {
-+ TIFFError(TIFFFileName(in),
-+ "Can't allocate buffer for raster of size %lux%lu",
-+ (unsigned long) width, (unsigned long) height);
-+ return (0);
-+ }
-+ raster = (uint32*)_TIFFmalloc(raster_size);
- if (raster == 0) {
- TIFFError(TIFFFileName(in), "No space for raster buffer");
- return (0);
-diff -Naur tiff-3.8.2.orig/tools/tiff2rgba.c tiff-3.8.2/tools/tiff2rgba.c
---- tiff-3.8.2.orig/tools/tiff2rgba.c 2004-11-07 06:08:37.000000000 -0500
-+++ tiff-3.8.2/tools/tiff2rgba.c 2009-07-10 17:06:42.000000000 -0400
-@@ -124,6 +124,17 @@
- return (0);
- }
-
-+static tsize_t
-+multiply(tsize_t m1, tsize_t m2)
-+{
-+ tsize_t prod = m1 * m2;
-+
-+ if (m1 && prod / m1 != m2)
-+ prod = 0; /* overflow */
-+
-+ return prod;
-+}
-+
- static int
- cvt_by_tile( TIFF *in, TIFF *out )
-
-@@ -133,6 +144,7 @@
- uint32 tile_width, tile_height;
- uint32 row, col;
- uint32 *wrk_line;
-+ tsize_t raster_size;
- int ok = 1;
-
- TIFFGetField(in, TIFFTAG_IMAGEWIDTH, &width);
-@@ -150,7 +162,14 @@
- /*
- * Allocate tile buffer
- */
-- raster = (uint32*)_TIFFmalloc(tile_width * tile_height * sizeof (uint32));
-+ raster_size = multiply(multiply(tile_width, tile_height), sizeof (uint32));
-+ if (!raster_size) {
-+ TIFFError(TIFFFileName(in),
-+ "Can't allocate buffer for raster of size %lux%lu",
-+ (unsigned long) tile_width, (unsigned long) tile_height);
-+ return (0);
-+ }
-+ raster = (uint32*)_TIFFmalloc(raster_size);
- if (raster == 0) {
- TIFFError(TIFFFileName(in), "No space for raster buffer");
- return (0);
-@@ -158,7 +177,7 @@
-
- /*
- * Allocate a scanline buffer for swapping during the vertical
-- * mirroring pass.
-+ * mirroring pass. (Request can't overflow given prior checks.)
- */
- wrk_line = (uint32*)_TIFFmalloc(tile_width * sizeof (uint32));
- if (!wrk_line) {
-@@ -226,6 +245,7 @@
- uint32 width, height; /* image width & height */
- uint32 row;
- uint32 *wrk_line;
-+ tsize_t raster_size;
- int ok = 1;
-
- TIFFGetField(in, TIFFTAG_IMAGEWIDTH, &width);
-@@ -241,7 +261,14 @@
- /*
- * Allocate strip buffer
- */
-- raster = (uint32*)_TIFFmalloc(width * rowsperstrip * sizeof (uint32));
-+ raster_size = multiply(multiply(width, rowsperstrip), sizeof (uint32));
-+ if (!raster_size) {
-+ TIFFError(TIFFFileName(in),
-+ "Can't allocate buffer for raster of size %lux%lu",
-+ (unsigned long) width, (unsigned long) rowsperstrip);
-+ return (0);
-+ }
-+ raster = (uint32*)_TIFFmalloc(raster_size);
- if (raster == 0) {
- TIFFError(TIFFFileName(in), "No space for raster buffer");
- return (0);
-@@ -249,7 +276,7 @@
-
- /*
- * Allocate a scanline buffer for swapping during the vertical
-- * mirroring pass.
-+ * mirroring pass. (Request can't overflow given prior checks.)
- */
- wrk_line = (uint32*)_TIFFmalloc(width * sizeof (uint32));
- if (!wrk_line) {
-@@ -328,14 +355,22 @@
- uint32* raster; /* retrieve RGBA image */
- uint32 width, height; /* image width & height */
- uint32 row;
--
-+ tsize_t raster_size;
-+
- TIFFGetField(in, TIFFTAG_IMAGEWIDTH, &width);
- TIFFGetField(in, TIFFTAG_IMAGELENGTH, &height);
-
- rowsperstrip = TIFFDefaultStripSize(out, rowsperstrip);
- TIFFSetField(out, TIFFTAG_ROWSPERSTRIP, rowsperstrip);
-
-- raster = (uint32*)_TIFFmalloc(width * height * sizeof (uint32));
-+ raster_size = multiply(multiply(width, height), sizeof (uint32));
-+ if (!raster_size) {
-+ TIFFError(TIFFFileName(in),
-+ "Can't allocate buffer for raster of size %lux%lu",
-+ (unsigned long) width, (unsigned long) height);
-+ return (0);
-+ }
-+ raster = (uint32*)_TIFFmalloc(raster_size);
- if (raster == 0) {
- TIFFError(TIFFFileName(in), "No space for raster buffer");
- return (0);
-@@ -353,7 +388,7 @@
- */
- if( no_alpha )
- {
-- int pixel_count = width * height;
-+ tsize_t pixel_count = (tsize_t) width * (tsize_t) height;
- unsigned char *src, *dst;
-
- src = (unsigned char *) raster;
-
diff --git a/media-libs/tiff/files/tiff-3.8.2-opengl.patch b/media-libs/tiff/files/tiff-3.8.2-opengl.patch
deleted file mode 100644
index c743376b4aba..000000000000
--- a/media-libs/tiff/files/tiff-3.8.2-opengl.patch
+++ /dev/null
@@ -1,19 +0,0 @@
---- tools/tiffgt.c.orig 2009-06-20 17:40:46.366090451 -0700
-+++ tools/tiffgt.c 2009-06-20 17:48:04.042265738 -0700
-@@ -31,12 +31,12 @@
- #include <string.h>
- #include <unistd.h>
-
--#if HAVE_APPLE_OPENGL_FRAMEWORK
--# include <OpenGL/gl.h>
--# include <GLUT/glut.h>
--#else
-+#ifdef HAVE_APPLE_OPENGL_FRAMEWORK
- # include <GL/gl.h>
- # include <GL/glut.h>
-+#else
-+# include <OpenGL/gl.h>
-+# include <GLUT/glut.h>
- #endif
-
- #include "tiffio.h"
diff --git a/media-libs/tiff/files/tiff-3.8.2-tiffsplit.patch b/media-libs/tiff/files/tiff-3.8.2-tiffsplit.patch
deleted file mode 100644
index 5422e74fba63..000000000000
--- a/media-libs/tiff/files/tiff-3.8.2-tiffsplit.patch
+++ /dev/null
@@ -1,20 +0,0 @@
-diff -ruN tiff-3.7.4-old/tools/tiffsplit.c tiff-3.7.4/tools/tiffsplit.c
---- tiff-3.7.4-old/tools/tiffsplit.c 2005-05-26 20:38:48.000000000 +0200
-+++ tiff-3.7.4/tools/tiffsplit.c 2006-06-01 16:00:11.000000000 +0200
-@@ -60,14 +60,13 @@
- return (-3);
- }
- if (argc > 2)
-- strcpy(fname, argv[2]);
-+ snprintf(fname, sizeof(fname), "%s", argv[2]);
- in = TIFFOpen(argv[1], "r");
- if (in != NULL) {
- do {
- char path[1024+1];
- newfilename();
-- strcpy(path, fname);
-- strcat(path, ".tif");
-+ snprintf(path, sizeof(path), "%s.tif", fname);
- out = TIFFOpen(path, TIFFIsBigEndian(in)?"wb":"wl");
- if (out == NULL)
- return (-2);
diff --git a/media-libs/tiff/files/tiff-jbig.patch b/media-libs/tiff/files/tiff-jbig.patch
deleted file mode 100644
index 58d079d63bf9..000000000000
--- a/media-libs/tiff/files/tiff-jbig.patch
+++ /dev/null
@@ -1,510 +0,0 @@
---- configure.orig 2005-09-12 06:52:41.000000000 -0700
-+++ configure 2006-06-06 19:41:22.000000000 -0700
-@@ -23648,6 +23648,25 @@
- fi
-
-
-+HAVE_JBIG=no
-+# Check whether --enable-jbig or --disable-jbig was given.
-+if test "${enable_jbig+set}" = set; then
-+ enableval="$enable_jbig"
-+ HAVE_JBIG=$enableval
-+else
-+ HAVE_JBIG=no
-+fi;
-+
-+if test "$HAVE_JBIG" = "yes" ; then
-+
-+cat >>confdefs.h <<\_ACEOF
-+#define JBIG_SUPPORT 1
-+_ACEOF
-+
-+ LIBS="-ljbig $LIBS"
-+fi
-+
-+
- # Check whether --enable-cxx or --disable-cxx was given.
- if test "${enable_cxx+set}" = set; then
- enableval="$enable_cxx"
-@@ -27680,6 +27699,7 @@
- echo " Pixar log-format algorithm: ${HAVE_PIXARLOG}"
- echo " JPEG support: ${HAVE_JPEG}"
- echo " Old JPEG support: ${HAVE_OJPEG}"
-+echo " JBIG support: ${HAVE_JBIG}"
- echo ""
- echo " C++ support: ${HAVE_CXX}"
- echo ""
---- configure.ac.orig 2005-09-12 06:52:41.000000000 -0700
-+++ configure.ac 2006-06-06 19:35:23.000000000 -0700
-@@ -387,6 +387,22 @@
- fi
-
- dnl ---------------------------------------------------------------------------
-+dnl Check for JBIG.
-+dnl ---------------------------------------------------------------------------
-+
-+HAVE_JBIG=no
-+AC_ARG_ENABLE(jbig,
-+ AS_HELP_STRING([--disable-jbig],
-+ [disable support for JBIG]),
-+ [HAVE_JBIG=$enableval], [HAVE_JBIG=no])
-+
-+if test "$HAVE_JBIG" = "yes" ; then
-+ AC_DEFINE(JBIG_SUPPORT, 1,
-+ [Support JBIG])
-+ LIBS="-ljbig $LIBS"
-+fi
-+
-+dnl ---------------------------------------------------------------------------
- dnl Check for C++.
- dnl ---------------------------------------------------------------------------
-
---- libtiff/Makefile.in.orig 2005-09-12 09:33:05.000000000 -0700
-+++ libtiff/Makefile.in 2006-06-06 19:35:23.000000000 -0700
-@@ -97,7 +97,7 @@
- tif_compress.lo tif_dir.lo tif_dirinfo.lo tif_dirread.lo \
- tif_dirwrite.lo tif_dumpmode.lo tif_error.lo tif_extension.lo \
- tif_fax3.lo tif_fax3sm.lo tif_flush.lo tif_getimage.lo \
-- tif_jpeg.lo tif_luv.lo tif_lzw.lo tif_next.lo tif_ojpeg.lo \
-+ tif_jpeg.lo tif_jbig.lo tif_luv.lo tif_lzw.lo tif_next.lo tif_ojpeg.lo \
- tif_open.lo tif_packbits.lo tif_pixarlog.lo tif_predict.lo \
- tif_print.lo tif_read.lo tif_strip.lo tif_swab.lo \
- tif_thunder.lo tif_tile.lo tif_unix.lo tif_version.lo \
-@@ -306,6 +306,7 @@
- tif_flush.c \
- tif_getimage.c \
- tif_jpeg.c \
-+ tif_jbig.c \
- tif_luv.c \
- tif_lzw.c \
- tif_next.c \
-@@ -480,6 +481,7 @@
- @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_flush.Plo@am__quote@
- @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_getimage.Plo@am__quote@
- @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_jpeg.Plo@am__quote@
-+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_jbig.Plo@am__quote@
- @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_luv.Plo@am__quote@
- @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_lzw.Plo@am__quote@
- @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tif_next.Plo@am__quote@
---- libtiff/tif_config.h.in.orig 2005-07-12 09:02:04.000000000 -0700
-+++ libtiff/tif_config.h.in 2006-06-06 19:35:23.000000000 -0700
-@@ -146,6 +146,9 @@
- /* Support JPEG compression (requires IJG JPEG library) */
- #undef JPEG_SUPPORT
-
-+/* Support JBIG compression (requires JBIG-KIT library) */
-+#undef JBIG_SUPPORT
-+
- /* Support LogLuv high dynamic range encoding */
- #undef LOGLUV_SUPPORT
-
---- libtiff/tif_jbig.c.orig 2006-06-06 19:32:40.000000000 -0700
-+++ libtiff/tif_jbig.c 2006-06-06 19:35:23.000000000 -0700
-@@ -0,0 +1,340 @@
-+/*
-+ * Copyright (c) 1988-1997 Sam Leffler
-+ * Copyright (c) 1991-1997 Silicon Graphics, Inc.
-+ *
-+ * Permission to use, copy, modify, distribute, and sell this software and
-+ * its documentation for any purpose is hereby granted without fee, provided
-+ * that (i) the above copyright notices and this permission notice appear in
-+ * all copies of the software and related documentation, and (ii) the names of
-+ * Sam Leffler and Silicon Graphics may not be used in any advertising or
-+ * publicity relating to the software without the specific, prior written
-+ * permission of Sam Leffler and Silicon Graphics.
-+ *
-+ * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
-+ * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
-+ * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
-+ *
-+ * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
-+ * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
-+ * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
-+ * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
-+ * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
-+ * OF THIS SOFTWARE.
-+ */
-+
-+/*
-+ * TIFF Library.
-+ *
-+ * JBIG Compression Algorithm Support.
-+ */
-+
-+#include "tiffio.h"
-+#include "tiffiop.h"
-+
-+#ifdef JBIG_SUPPORT
-+#include "jbig.h"
-+
-+struct JBIGState
-+{
-+ uint32 recvparams; /* encoded Class 2 session params */
-+ char* subaddress; /* subaddress string */
-+ uint32 recvtime; /* time spend receiving in seconds */
-+ char* faxdcs; /* encoded fax parameters (DCS, Table 2/T.30) */
-+
-+ TIFFVGetMethod vgetparent;
-+ TIFFVSetMethod vsetparent;
-+};
-+
-+#define GetJBIGState(tif) ((struct JBIGState*)(tif)->tif_data)
-+#define N(a) (sizeof (a) / sizeof (a[0]))
-+
-+#define FIELD_RECVPARAMS (FIELD_CODEC+0)
-+#define FIELD_SUBADDRESS (FIELD_CODEC+1)
-+#define FIELD_RECVTIME (FIELD_CODEC+2)
-+#define FIELD_FAXDCS (FIELD_CODEC+3)
-+
-+static const TIFFFieldInfo jbigFieldInfo[] =
-+{
-+ {TIFFTAG_FAXRECVPARAMS, 1, 1, TIFF_LONG, FIELD_RECVPARAMS, TRUE, FALSE, "FaxRecvParams"},
-+ {TIFFTAG_FAXSUBADDRESS, -1, -1, TIFF_ASCII, FIELD_SUBADDRESS, TRUE, FALSE, "FaxSubAddress"},
-+ {TIFFTAG_FAXRECVTIME, 1, 1, TIFF_LONG, FIELD_RECVTIME, TRUE, FALSE, "FaxRecvTime"},
-+ {TIFFTAG_FAXDCS, -1, -1, TIFF_ASCII, FIELD_FAXDCS, TRUE, FALSE, "FaxDcs"},
-+};
-+
-+static int JBIGSetupDecode(TIFF* tif)
-+{
-+ if (TIFFNumberOfStrips(tif) != 1)
-+ {
-+ TIFFError("JBIG", "Multistrip images not supported in decoder");
-+ return 0;
-+ }
-+
-+ return 1;
-+}
-+
-+static int JBIGDecode(TIFF* tif, tidata_t buffer, tsize_t size, tsample_t s)
-+{
-+ struct jbg_dec_state decoder;
-+ int decodeStatus = 0;
-+ unsigned char* pImage = NULL;
-+
-+ if (isFillOrder(tif, tif->tif_dir.td_fillorder))
-+ {
-+ TIFFReverseBits(tif->tif_rawdata, tif->tif_rawdatasize);
-+ }
-+
-+ jbg_dec_init(&decoder);
-+ jbg_newlen(tif->tif_rawdata, tif->tif_rawdatasize);
-+ /*
-+ * I do not check the return status of jbg_newlen because even if this function
-+ * fails it does not necessarily mean that decoding the image will fail. It is
-+ * generally only needed for received fax images that do not contain the actual
-+ * length of the image in the BIE header. I do not log when an error occurs
-+ * because that will cause problems when converting JBIG encoded TIFF's to
-+ * PostScript. As long as the actual image length is contained in the BIE header
-+ * jbg_dec_in should succeed.
-+ */
-+
-+ decodeStatus = jbg_dec_in(&decoder, tif->tif_rawdata, tif->tif_rawdatasize, NULL);
-+ if (JBG_EOK != decodeStatus)
-+ {
-+ TIFFError("JBIG", "Error (%d) decoding: %s", decodeStatus, jbg_strerror(decodeStatus, JBG_EN));
-+ return 0;
-+ }
-+
-+ pImage = jbg_dec_getimage(&decoder, 0);
-+ _TIFFmemcpy(buffer, pImage, jbg_dec_getsize(&decoder));
-+ jbg_dec_free(&decoder);
-+ return 1;
-+}
-+
-+static int JBIGSetupEncode(TIFF* tif)
-+{
-+ TIFFDirectory* dir = &tif->tif_dir;
-+
-+ if (TIFFNumberOfStrips(tif) != 1)
-+ {
-+ TIFFError("JBIG", "Multistrip images not supported in encoder");
-+ return 0;
-+ }
-+
-+ return 1;
-+}
-+
-+static int JBIGCopyEncodedData(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s)
-+{
-+ (void) s;
-+ while (cc > 0)
-+ {
-+ tsize_t n = cc;
-+
-+ if (tif->tif_rawcc + n > tif->tif_rawdatasize)
-+ {
-+ n = tif->tif_rawdatasize - tif->tif_rawcc;
-+ }
-+
-+ assert(n > 0);
-+ _TIFFmemcpy(tif->tif_rawcp, pp, n);
-+ tif->tif_rawcp += n;
-+ tif->tif_rawcc += n;
-+ pp += n;
-+ cc -= n;
-+ if (tif->tif_rawcc >= tif->tif_rawdatasize &&
-+ !TIFFFlushData1(tif))
-+ {
-+ return (-1);
-+ }
-+ }
-+
-+ return (1);
-+}
-+
-+static void JBIGOutputBie(unsigned char* buffer, size_t len, void *userData)
-+{
-+ TIFF* tif = (TIFF*)userData;
-+
-+ if (isFillOrder(tif, tif->tif_dir.td_fillorder))
-+ {
-+ TIFFReverseBits(buffer, len);
-+ }
-+
-+ JBIGCopyEncodedData(tif, buffer, len, 0);
-+}
-+
-+static int JBIGEncode(TIFF* tif, tidata_t buffer, tsize_t size, tsample_t s)
-+{
-+ TIFFDirectory* dir = &tif->tif_dir;
-+ struct jbg_enc_state encoder;
-+
-+ jbg_enc_init(&encoder,
-+ dir->td_imagewidth,
-+ dir->td_imagelength,
-+ 1,
-+ &buffer,
-+ JBIGOutputBie,
-+ tif);
-+ /*
-+ * jbg_enc_out does the "real" encoding. As data is encoded, JBIGOutputBie
-+ * is called, which writes the data to the directory.
-+ */
-+ jbg_enc_out(&encoder);
-+ jbg_enc_free(&encoder);
-+
-+ return 1;
-+}
-+
-+static void JBIGCleanup(TIFF* tif)
-+{
-+ if (NULL != tif->tif_data)
-+ {
-+ _TIFFfree(tif->tif_data);
-+ tif->tif_data = NULL;
-+ }
-+}
-+
-+static void JBIGPrintDir(TIFF* tif, FILE* fd, long flags)
-+{
-+ struct JBIGState* codec = GetJBIGState(tif);
-+ (void)flags;
-+
-+ if (TIFFFieldSet(tif, FIELD_RECVPARAMS))
-+ {
-+ fprintf(fd,
-+ " Fax Receive Parameters: %08lx\n",
-+ (unsigned long)codec->recvparams);
-+ }
-+
-+ if (TIFFFieldSet(tif, FIELD_SUBADDRESS))
-+ {
-+ fprintf(fd,
-+ " Fax SubAddress: %s\n",
-+ codec->subaddress);
-+ }
-+
-+ if (TIFFFieldSet(tif, FIELD_RECVTIME))
-+ {
-+ fprintf(fd,
-+ " Fax Receive Time: %lu secs\n",
-+ (unsigned long)codec->recvtime);
-+ }
-+
-+ if (TIFFFieldSet(tif, FIELD_FAXDCS))
-+ {
-+ fprintf(fd,
-+ " Fax DCS: %s\n",
-+ codec->faxdcs);
-+ }
-+}
-+
-+static int JBIGVGetField(TIFF* tif, ttag_t tag, va_list ap)
-+{
-+ struct JBIGState* codec = GetJBIGState(tif);
-+
-+ switch (tag)
-+ {
-+ case TIFFTAG_FAXRECVPARAMS:
-+ *va_arg(ap, uint32*) = codec->recvparams;
-+ break;
-+
-+ case TIFFTAG_FAXSUBADDRESS:
-+ *va_arg(ap, char**) = codec->subaddress;
-+ break;
-+
-+ case TIFFTAG_FAXRECVTIME:
-+ *va_arg(ap, uint32*) = codec->recvtime;
-+ break;
-+
-+ case TIFFTAG_FAXDCS:
-+ *va_arg(ap, char**) = codec->faxdcs;
-+ break;
-+
-+ default:
-+ return (*codec->vgetparent)(tif, tag, ap);
-+ }
-+
-+ return 1;
-+}
-+
-+static int JBIGVSetField(TIFF* tif, ttag_t tag, va_list ap)
-+{
-+ struct JBIGState* codec = GetJBIGState(tif);
-+
-+ switch (tag)
-+ {
-+ case TIFFTAG_FAXRECVPARAMS:
-+ codec->recvparams = va_arg(ap, uint32);
-+ break;
-+
-+ case TIFFTAG_FAXSUBADDRESS:
-+ _TIFFsetString(&codec->subaddress, va_arg(ap, char*));
-+ break;
-+
-+ case TIFFTAG_FAXRECVTIME:
-+ codec->recvtime = va_arg(ap, uint32);
-+ break;
-+
-+ case TIFFTAG_FAXDCS:
-+ _TIFFsetString(&codec->faxdcs, va_arg(ap, char*));
-+ break;
-+
-+ default:
-+ return (*codec->vsetparent)(tif, tag, ap);
-+ }
-+
-+ TIFFSetFieldBit(tif, _TIFFFieldWithTag(tif, tag)->field_bit);
-+ tif->tif_flags |= TIFF_DIRTYDIRECT;
-+ return 1;
-+}
-+
-+int TIFFInitJBIG(TIFF* tif, int scheme)
-+{
-+ struct JBIGState* codec = NULL;
-+
-+ /* Allocate memory for the JBIGState structure.*/
-+ tif->tif_data = (tdata_t)_TIFFmalloc(sizeof(struct JBIGState));
-+ if (tif->tif_data == NULL)
-+ {
-+ TIFFError("TIFFInitJBIG", "Not enough memory for JBIGState");
-+ return 0;
-+ }
-+ _TIFFmemset(tif->tif_data, 0, sizeof(struct JBIGState));
-+ codec = GetJBIGState(tif);
-+
-+ /* Initialize codec private fields */
-+ codec->recvparams = 0;
-+ codec->subaddress = NULL;
-+ codec->faxdcs = NULL;
-+ codec->recvtime = 0;
-+
-+ /* Register codec private fields with libtiff and setup function pointers*/
-+ _TIFFMergeFieldInfo(tif, jbigFieldInfo, N(jbigFieldInfo));
-+
-+ codec->vgetparent = tif->tif_tagmethods.vgetfield;
-+ codec->vsetparent = tif->tif_tagmethods.vsetfield;
-+
-+ tif->tif_tagmethods.vgetfield = JBIGVGetField;
-+ tif->tif_tagmethods.vsetfield = JBIGVSetField;
-+ tif->tif_tagmethods.printdir = JBIGPrintDir;
-+
-+
-+ /*
-+ * These flags are set so the JBIG Codec can control when to reverse bits and when
-+ * not to and to allow the jbig decoder and bit reverser to write to memory
-+ * when necessary.
-+ */
-+ tif->tif_flags |= TIFF_NOBITREV;
-+ tif->tif_flags &= ~TIFF_MAPPED;
-+
-+ /* Setup the function pointers for encode, decode, and cleanup. */
-+ tif->tif_setupdecode = JBIGSetupDecode;
-+ tif->tif_decodestrip = JBIGDecode;
-+
-+ tif->tif_setupencode = JBIGSetupEncode;
-+ tif->tif_encodestrip = JBIGEncode;
-+
-+ tif->tif_cleanup = JBIGCleanup;
-+
-+ return 1;
-+}
-+
-+#endif /* JBIG_SUPPORT */
---- libtiff/tiffconf.h.in.orig 2005-07-28 01:49:24.000000000 -0700
-+++ libtiff/tiffconf.h.in 2006-06-06 19:35:23.000000000 -0700
-@@ -40,6 +40,9 @@
- /* Support JPEG compression (requires IJG JPEG library) */
- #undef JPEG_SUPPORT
-
-+/* Support JBIG compression (requires JBIG-KIT library) */
-+#undef JBIG_SUPPORT
-+
- /* Support LogLuv high dynamic range encoding */
- #undef LOGLUV_SUPPORT
-
---- libtiff/tiffconf.h.vc.orig 2005-07-28 01:49:24.000000000 -0700
-+++ libtiff/tiffconf.h.vc 2006-06-06 19:35:23.000000000 -0700
-@@ -41,6 +41,9 @@
- /* Support JPEG compression (requires IJG JPEG library) */
- /* #undef JPEG_SUPPORT */
-
-+/* Support JBIG compression (requires JBIG-KIT library) */
-+#undef JBIG_SUPPORT
-+
- /* Support LogLuv high dynamic range encoding */
- #define LOGLUV_SUPPORT 1
-
---- tools/tiffcp.c.orig 2005-07-08 02:03:49.000000000 -0700
-+++ tools/tiffcp.c 2006-06-06 19:44:44.000000000 -0700
-@@ -349,6 +349,8 @@
- if (cp)
- defpredictor = atoi(cp+1);
- defcompression = COMPRESSION_ADOBE_DEFLATE;
-+ } else if (strneq(opt, "jbig", 4)) {
-+ defcompression = COMPRESSION_JBIG;
- } else
- return (0);
- return (1);
-@@ -648,6 +650,12 @@
- TIFFSetField(out, TIFFTAG_JPEGQUALITY, quality);
- TIFFSetField(out, TIFFTAG_JPEGCOLORMODE, jpegcolormode);
- break;
-+ case COMPRESSION_JBIG:
-+ CopyTag(TIFFTAG_FAXRECVPARAMS, 1, TIFF_LONG);
-+ CopyTag(TIFFTAG_FAXRECVTIME, 1, TIFF_LONG);
-+ CopyTag(TIFFTAG_FAXSUBADDRESS, 1, TIFF_ASCII);
-+ CopyTag(TIFFTAG_FAXDCS, 1, TIFF_ASCII);
-+ break;
- case COMPRESSION_LZW:
- case COMPRESSION_ADOBE_DEFLATE:
- case COMPRESSION_DEFLATE:
---- libtiff/Makefile.vc.orig 2006-06-06 19:58:40.000000000 -0700
-+++ libtiff/Makefile.vc 2006-06-06 19:59:32.000000000 -0700
-@@ -29,7 +29,7 @@
-
- !INCLUDE ..\nmake.opt
-
--INCL = -I. $(JPEG_INCLUDE) $(ZLIB_INCLUDE)
-+INCL = -I. $(JPEG_INCLUDE) $(ZLIB_INCLUDE) $(JBIG_INCLUDE)
-
- !IFDEF USE_WIN_CRT_LIB
- OBJ_SYSDEP_MODULE = tif_unix.obj
-@@ -74,6 +74,7 @@
- tif_warning.obj \
- tif_write.obj \
- tif_zip.obj \
-+ tif_jbig.obj \
- $(OBJ_SYSDEP_MODULE)
-
- all: libtiff.lib $(DLLNAME)