X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b47c832e5529dc6c632536b4665a005f0a85aec8..a97d569cbbf90ba8bb293214055c3a8c19d447b5:/src/tiff/tif_open.c

diff --git a/src/tiff/tif_open.c b/src/tiff/tif_open.c
index a704468ec6..a981b73522 100644
--- a/src/tiff/tif_open.c
+++ b/src/tiff/tif_open.c
@@ -32,19 +32,19 @@
 void _TIFFSetDefaultCompressionState(TIFF* tif);
 
 static const long typemask[13] = {
-	0L,		/* TIFF_NOTYPE */
-	0x000000ffL,	/* TIFF_BYTE */
-	0xffffffffL,	/* TIFF_ASCII */
-	0x0000ffffL,	/* TIFF_SHORT */
-	0xffffffffL,	/* TIFF_LONG */
-	0xffffffffL,	/* TIFF_RATIONAL */
-	0x000000ffL,	/* TIFF_SBYTE */
-	0x000000ffL,	/* TIFF_UNDEFINED */
-	0x0000ffffL,	/* TIFF_SSHORT */
-	0xffffffffL,	/* TIFF_SLONG */
-	0xffffffffL,	/* TIFF_SRATIONAL */
-	0xffffffffL,	/* TIFF_FLOAT */
-	0xffffffffL,	/* TIFF_DOUBLE */
+	(long)0L,		/* TIFF_NOTYPE */
+	(long)0x000000ffL,	/* TIFF_BYTE */
+	(long)0xffffffffL,	/* TIFF_ASCII */
+	(long)0x0000ffffL,	/* TIFF_SHORT */
+	(long)0xffffffffL,	/* TIFF_LONG */
+	(long)0xffffffffL,	/* TIFF_RATIONAL */
+	(long)0x000000ffL,	/* TIFF_SBYTE */
+	(long)0x000000ffL,	/* TIFF_UNDEFINED */
+	(long)0x0000ffffL,	/* TIFF_SSHORT */
+	(long)0xffffffffL,	/* TIFF_SLONG */
+	(long)0xffffffffL,	/* TIFF_SRATIONAL */
+	(long)0xffffffffL,	/* TIFF_FLOAT */
+	(long)0xffffffffL,	/* TIFF_DOUBLE */
 };
 static const int bigTypeshift[13] = {
 	0,		/* TIFF_NOTYPE */
@@ -156,6 +156,11 @@ TIFFClientOpen(
 	tif->tif_curstrip = (tstrip_t) -1;	/* invalid strip */
 	tif->tif_row = (uint32) -1;		/* read/write pre-increment */
 	tif->tif_clientdata = clientdata;
+	if (!readproc || !writeproc || !seekproc || !closeproc
+			|| !sizeproc || !mapproc || !unmapproc) {
+		TIFFError(module, "One of the client procedures are NULL pointer");
+		goto bad3;
+	}
 	tif->tif_readproc = readproc;
 	tif->tif_writeproc = writeproc;
 	tif->tif_seekproc = seekproc;
@@ -170,11 +175,12 @@ TIFFClientOpen(
 	 * a file is opened read-only.
 	 */
 	tif->tif_flags = FILLORDER_MSB2LSB;
-	if (m == O_RDONLY)
+	if (m == O_RDONLY )
+            tif->tif_flags |= TIFF_MAPPED;
+
 #ifdef STRIPCHOP_DEFAULT
-		tif->tif_flags |= TIFF_MAPPED|STRIPCHOP_DEFAULT;
-#else
-		tif->tif_flags |= TIFF_MAPPED;
+	if (m == O_RDONLY || m == O_RDWR)
+		tif->tif_flags |= STRIPCHOP_DEFAULT;
 #endif
 
 	{ union { int32 i; char c[4]; } u; u.i = 1; bigendian = u.c[0] == 0; }
@@ -210,7 +216,7 @@ TIFFClientOpen(
 	 * The 'L', 'B', and 'H' flags are intended for applications
 	 * that can optimize operations on data by using a particular
 	 * bit order.  By default the library returns data in MSB2LSB
-	 * bit order for compatibiltiy with older versions of this
+	 * bit order for compatibility with older versions of this
 	 * library.  Returning data in the bit order of the native cpu
 	 * makes the most sense but also requires applications to check
 	 * the value of the FillOrder tag; something they probabyl do
@@ -284,6 +290,15 @@ TIFFClientOpen(
 		if (tif->tif_flags & TIFF_SWAB)
 			TIFFSwabShort(&tif->tif_header.tiff_version);
 		tif->tif_header.tiff_diroff = 0;	/* filled in later */
+
+                /*
+                 * This seek shouldn't be necessary, but I have had some
+                 * crazy problems with a failed fseek() on Solaris leaving
+                 * the current file pointer out of whack when an fwrite()
+                 * is done. 
+                 */
+                TIFFSeekFile( tif, 0, SEEK_SET );
+
 		if (!WriteOK(tif, &tif->tif_header, sizeof (TIFFHeader))) {
 			TIFFError(name, "Error writing TIFF header");
 			goto bad;
@@ -298,6 +313,8 @@ TIFFClientOpen(
 		if (!TIFFDefaultDirectory(tif))
 			goto bad;
 		tif->tif_diroff = 0;
+		tif->tif_dirlist = NULL;
+		tif->tif_dirnumber = 0;
 		return (tif);
 	}
 	/*
@@ -369,6 +386,7 @@ bad:
 	return ((TIFF*)0);
 bad2:
 	(void) (*closeproc)(clientdata);
+bad3:
 	return ((TIFF*)0);
 }