2010-08-31  Juan Manuel Guerrero  <juan.guerrero@gmx.de>

	* libtiff/tif_jpeg.c (JPEGCleanup, JPEGPrintDir): Assertion did not
	hold true, resulting in the client application calling abort().

	* libtiff/tif_dirinfo.c (_TIFFFieldWithTag, _TIFFFieldWithName):
	Assertion did not hold true, resulting in the client application
	calling abort().


2010-08-21  Juan Manuel Guerrero  <juan.guerrero@gmx.de>

	* libtiff/tiffiop.h [HAVE_SEARCH_H]: New guard HAVE_LFIND added.
	Do not assume that <search.h> provides lfind().

	* tools/tiff2pdf.c (main): Use "l" conversion specifier when printing
	long unsigned integer.
	(t2p_init): Use "l" conversion specifier when printing long unsigned
	integer.
	(t2p_read_tiff_init): Use "l" conversion specifier when printing long
	unsigned integer.
	(t2p_write_pdf): Use "l" conversion specifier when printing long
	unsigned integer.







diff -aprNU5 tiff-3.9.4.orig/libtiff/tif_dirinfo.c tiff-3.9.4/libtiff/tif_dirinfo.c
--- tiff-3.9.4.orig/libtiff/tif_dirinfo.c	2010-06-09 21:15:26 +0000
+++ tiff-3.9.4/libtiff/tif_dirinfo.c	2010-09-09 21:30:54 +0000
@@ -806,11 +806,11 @@ _TIFFFieldWithTag(TIFF* tif, ttag_t tag)
 	const TIFFFieldInfo* fip = _TIFFFindFieldInfo(tif, tag, TIFF_ANY);
 	if (!fip) {
 		TIFFErrorExt(tif->tif_clientdata, "TIFFFieldWithTag",
 			     "Internal error, unknown tag 0x%x",
 			     (unsigned int) tag);
-		assert(fip != NULL);
+		/* assert(fip != NULL); */
 		/*NOTREACHED*/
 	}
 	return (fip);
 }
 
@@ -820,11 +820,11 @@ _TIFFFieldWithName(TIFF* tif, const char
 	const TIFFFieldInfo* fip =
 		_TIFFFindFieldInfoByName(tif, field_name, TIFF_ANY);
 	if (!fip) {
 		TIFFErrorExt(tif->tif_clientdata, "TIFFFieldWithName",
 			     "Internal error, unknown tag %s", field_name);
-		assert(fip != NULL);
+		/* assert(fip != NULL); */
 		/*NOTREACHED*/
 	}
 	return (fip);
 }
 
diff -aprNU5 tiff-3.9.4.orig/libtiff/tif_jpeg.c tiff-3.9.4/libtiff/tif_jpeg.c
--- tiff-3.9.4.orig/libtiff/tif_jpeg.c	2010-06-14 14:27:50 +0000
+++ tiff-3.9.4/libtiff/tif_jpeg.c	2010-09-09 21:30:54 +0000
@@ -1570,20 +1570,22 @@ JPEGPostEncode(TIFF* tif)
 static void
 JPEGCleanup(TIFF* tif)
 {
 	JPEGState *sp = JState(tif);
 	
-	assert(sp != 0);
+	/* assert(sp != 0); */
 
 	tif->tif_tagmethods.vgetfield = sp->vgetparent;
 	tif->tif_tagmethods.vsetfield = sp->vsetparent;
 	tif->tif_tagmethods.printdir = sp->printdir;
 
-	if( sp->cinfo_initialized )
-	    TIFFjpeg_destroy(sp);	/* release libjpeg resources */
-	if (sp->jpegtables)		/* tag value */
-		_TIFFfree(sp->jpegtables);
+	if (sp != NULL) {
+		if( sp->cinfo_initialized )
+		    TIFFjpeg_destroy(sp);	/* release libjpeg resources */
+		if (sp->jpegtables)		/* tag value */
+			_TIFFfree(sp->jpegtables);
+	}
 	_TIFFfree(tif->tif_data);	/* release local state */
 	tif->tif_data = NULL;
 
 	_TIFFSetDefaultCompressionState(tif);
 }
@@ -1812,11 +1814,15 @@ JPEGVGetField(TIFF* tif, ttag_t tag, va_
 static void
 JPEGPrintDir(TIFF* tif, FILE* fd, long flags)
 {
 	JPEGState* sp = JState(tif);
 
-	assert(sp != NULL);
+	/* assert(sp != NULL); */
+	if (sp == NULL) {
+		TIFFWarningExt(tif->tif_clientdata, "JPEGPrintDir", "Unknown JPEGState");
+		return;
+	}
 
 	(void) flags;
 	if (TIFFFieldSet(tif,FIELD_JPEGTABLES))
 		fprintf(fd, "  JPEG Tables: (%lu bytes)\n",
 			(unsigned long) sp->jpegtables_length);
diff -aprNU5 tiff-3.9.4.orig/libtiff/tiffiop.h tiff-3.9.4/libtiff/tiffiop.h
--- tiff-3.9.4.orig/libtiff/tiffiop.h	2010-06-12 02:55:16 +0000
+++ tiff-3.9.4/libtiff/tiffiop.h	2010-09-09 21:30:54 +0000
@@ -48,11 +48,11 @@
 # include <assert.h>
 #else
 # define assert(x) 
 #endif
 
-#ifdef HAVE_SEARCH_H
+#if defined HAVE_SEARCH_H && defined HAVE_LFIND
 # include <search.h>
 #else
 extern void *lfind(const void *, const void *, size_t *, size_t,
 		   int (*)(const void *, const void *));
 #endif
diff -aprNU5 tiff-3.9.4.orig/tools/tiff2pdf.c tiff-3.9.4/tools/tiff2pdf.c
--- tiff-3.9.4.orig/tools/tiff2pdf.c	2010-06-13 20:51:44 +0000
+++ tiff-3.9.4/tools/tiff2pdf.c	2010-09-09 21:30:54 +0000
@@ -659,11 +659,11 @@ int main(int argc, char** argv){
 			case 'c': 
 				t2p->pdf_creator = (unsigned char *)
 					_TIFFmalloc(strlen(optarg) + 1);
 				if(t2p->pdf_creator==NULL){
 					TIFFError(TIFF2PDF_MODULE, 
-				"Can't allocate %u bytes of memory for main", 
+				"Can't allocate %lu bytes of memory for main", 
 						  strlen(optarg) + 1); 
 					goto fail;
 				}
 				strcpy((char *)t2p->pdf_creator, optarg);
 				t2p->pdf_creator[strlen(optarg)] = 0;
@@ -672,11 +672,11 @@ int main(int argc, char** argv){
 				t2p->pdf_author = (unsigned char *)
 					_TIFFmalloc(strlen(optarg) + 1);
 				if(t2p->pdf_author==NULL){
 					TIFFError(
 						TIFF2PDF_MODULE, 
-				"Can't allocate %u bytes of memory for main", 
+				"Can't allocate %lu bytes of memory for main", 
 						strlen(optarg) + 1); 
 					goto fail;
 				}
 				strcpy((char *)t2p->pdf_author, optarg);
 				t2p->pdf_author[strlen(optarg)]=0;
@@ -685,11 +685,11 @@ int main(int argc, char** argv){
 				t2p->pdf_title = (unsigned char*)
 					_TIFFmalloc(strlen(optarg)+1);
 				if(t2p->pdf_title==NULL){
 					TIFFError(
 						TIFF2PDF_MODULE, 
-				"Can't allocate %u bytes of memory for main", 
+				"Can't allocate %lu bytes of memory for main", 
 						strlen(optarg) + 1); 
 					goto fail;
 				}
 				strcpy((char *)t2p->pdf_title, optarg);
 				t2p->pdf_title[strlen(optarg)] = 0;
@@ -698,11 +698,11 @@ int main(int argc, char** argv){
 				t2p->pdf_subject = (unsigned char*)
 					_TIFFmalloc(strlen(optarg) + 1);
 				if(t2p->pdf_subject==NULL){
 					TIFFError(
 						TIFF2PDF_MODULE, 
-				"Can't allocate %u bytes of memory for main", 
+				"Can't allocate %lu bytes of memory for main", 
 						strlen(optarg)+1); 
 					goto fail;
 				}
 				strcpy((char *)t2p->pdf_subject, optarg);
 				t2p->pdf_subject[strlen(optarg)]=0;
@@ -711,11 +711,11 @@ int main(int argc, char** argv){
 				t2p->pdf_keywords = (unsigned char*)
 					_TIFFmalloc(strlen(optarg) + 1);
 				if(t2p->pdf_keywords==NULL){
 					TIFFError(
 						TIFF2PDF_MODULE, 
-				"Can't allocate %u bytes of memory for main", 
+				"Can't allocate %lu bytes of memory for main", 
 						strlen(optarg) + 1); 
 					goto fail;
 				}
 				strcpy((char *)t2p->pdf_keywords, optarg);
 				t2p->pdf_keywords[strlen(optarg)] = 0;
@@ -927,11 +927,11 @@ T2P* t2p_init(){
 
 	T2P* t2p = (T2P*) _TIFFmalloc(sizeof(T2P));
 	if(t2p==NULL){
 		TIFFError(
 			TIFF2PDF_MODULE, 
-			"Can't allocate %u bytes of memory for t2p_init", 
+			"Can't allocate %lu bytes of memory for t2p_init", 
 			sizeof(T2P));
 		return( (T2P*) NULL );
 	}
 	_TIFFmemset(t2p, 0x00, sizeof(T2P));
 	t2p->pdf_majorversion=1;
@@ -1061,22 +1061,22 @@ void t2p_read_tiff_init(T2P* t2p, TIFF*
 	directorycount=TIFFNumberOfDirectories(input);
 	t2p->tiff_pages = (T2P_PAGE*) _TIFFmalloc(directorycount * sizeof(T2P_PAGE));
 	if(t2p->tiff_pages==NULL){
 		TIFFError(
 			TIFF2PDF_MODULE, 
-			"Can't allocate %u bytes of memory for tiff_pages array, %s", 
+			"Can't allocate %lu bytes of memory for tiff_pages array, %s", 
 			directorycount * sizeof(T2P_PAGE), 
 			TIFFFileName(input));
 		t2p->t2p_error = T2P_ERR_ERROR;
 		return;
 	}
 	_TIFFmemset( t2p->tiff_pages, 0x00, directorycount * sizeof(T2P_PAGE));
 	t2p->tiff_tiles = (T2P_TILES*) _TIFFmalloc(directorycount * sizeof(T2P_TILES));
 	if(t2p->tiff_tiles==NULL){
 		TIFFError(
 			TIFF2PDF_MODULE, 
-			"Can't allocate %u bytes of memory for tiff_tiles array, %s", 
+			"Can't allocate %lu bytes of memory for tiff_tiles array, %s", 
 			directorycount * sizeof(T2P_TILES), 
 			TIFFFileName(input));
 		t2p->t2p_error = T2P_ERR_ERROR;
 		return;
 	}
@@ -1204,11 +1204,11 @@ void t2p_read_tiff_init(T2P* t2p, TIFF*
 				t2p->tiff_tiles[i].tiles_tilecount 
 				* sizeof(T2P_TILE) );
 			if( t2p->tiff_tiles[i].tiles_tiles == NULL){
 				TIFFError(
 					TIFF2PDF_MODULE, 
-					"Can't allocate %u bytes of memory for t2p_read_tiff_init, %s", 
+					"Can't allocate %lu bytes of memory for t2p_read_tiff_init, %s", 
 					t2p->tiff_tiles[i].tiles_tilecount * sizeof(T2P_TILE), 
 					TIFFFileName(input));
 				t2p->t2p_error = T2P_ERR_ERROR;
 				return;
 			}
@@ -5244,11 +5244,11 @@ tsize_t t2p_write_pdf(T2P* t2p, TIFF* in
 	if(t2p->t2p_error!=T2P_ERR_OK){return(0);}
 	t2p->pdf_xrefoffsets= (uint32*) _TIFFmalloc(t2p->pdf_xrefcount * sizeof(uint32) );
 	if(t2p->pdf_xrefoffsets==NULL){
 		TIFFError(
 			TIFF2PDF_MODULE, 
-			"Can't allocate %u bytes of memory for t2p_write_pdf", 
+			"Can't allocate %lu bytes of memory for t2p_write_pdf", 
 			t2p->pdf_xrefcount * sizeof(uint32) );
 		return(written);
 	}
 	t2p->pdf_xrefcount=0;
 	t2p->pdf_catalog=1;
