summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--archive/tools/ras2tiff.c8
-rw-r--r--libtiff/tif_write.c31
-rw-r--r--tools/tiffinfo.c2
-rw-r--r--tools/tiffsplit.c10
4 files changed, 35 insertions, 16 deletions
diff --git a/archive/tools/ras2tiff.c b/archive/tools/ras2tiff.c
index 30104f06..d3ae889d 100644
--- a/archive/tools/ras2tiff.c
+++ b/archive/tools/ras2tiff.c
@@ -163,11 +163,15 @@ main(int argc, char* argv[])
buf = (unsigned char *)_TIFFmalloc(h.ras_maplength);
if (buf == NULL) {
fprintf(stderr, "No space to read in colormap.\n");
+ fclose(in);
+ (void) TIFFClose(out);
return (-5);
}
if (fread(buf, h.ras_maplength, 1, in) != 1) {
fprintf(stderr, "%s: Read error on colormap.\n",
argv[optind]);
+ fclose(in);
+ (void) TIFFClose(out);
return (-6);
}
mapsize = 1<<h.ras_depth;
@@ -175,11 +179,15 @@ main(int argc, char* argv[])
fprintf(stderr,
"%s: Huh, %d colormap entries, should be %d?\n",
argv[optind], h.ras_maplength, mapsize*3);
+ fclose(in);
+ (void) TIFFClose(out);
return (-7);
}
red = (uint16_t*)_TIFFmalloc(mapsize * 3 * sizeof (uint16_t));
if (red == NULL) {
fprintf(stderr, "No space for colormap.\n");
+ fclose(in);
+ (void) TIFFClose(out);
return (-8);
}
map = red;
diff --git a/libtiff/tif_write.c b/libtiff/tif_write.c
index 3b548efa..46e07763 100644
--- a/libtiff/tif_write.c
+++ b/libtiff/tif_write.c
@@ -128,14 +128,8 @@ TIFFWriteScanline(TIFF* tif, void* buf, uint32_t row, uint16_t sample)
tif->tif_rawcc = 0;
tif->tif_rawcp = tif->tif_rawdata;
- if( td->td_stripbytecount_p[strip] > 0 )
- {
- /* if we are writing over existing tiles, zero length */
- td->td_stripbytecount_p[strip] = 0;
-
- /* this forces TIFFAppendToStrip() to do a seek */
- tif->tif_curoff = 0;
- }
+ /* this informs TIFFAppendToStrip() we have changed strip */
+ tif->tif_curoff = 0;
if (!(*tif->tif_preencode)(tif, sample))
return (-1);
@@ -194,10 +188,6 @@ static int _TIFFReserveLargeEnoughWriteBuffer(TIFF* tif, uint32_t strip_or_tile)
(tmsize_t)TIFFroundup_64(safe_buffer_size, 1024))) )
return 0;
}
-
- /* Force TIFFAppendToStrip() to consider placing data at end
- of file. */
- tif->tif_curoff = 0;
}
return 1;
}
@@ -246,8 +236,12 @@ TIFFWriteEncodedStrip(TIFF* tif, uint32_t strip, void* data, tmsize_t cc)
return ((tmsize_t) -1);
tif->tif_flags |= TIFF_BUF4WRITE;
+
tif->tif_curstrip = strip;
+ /* this informs TIFFAppendToStrip() we have changed or reset strip */
+ tif->tif_curoff = 0;
+
if( !_TIFFReserveLargeEnoughWriteBuffer(tif, strip) ) {
return ((tmsize_t)(-1));
}
@@ -346,7 +340,12 @@ TIFFWriteRawStrip(TIFF* tif, uint32_t strip, void* data, tmsize_t cc)
if (!TIFFGrowStrips(tif, 1, module))
return ((tmsize_t) -1);
}
+
tif->tif_curstrip = strip;
+
+ /* this informs TIFFAppendToStrip() we have changed or reset strip */
+ tif->tif_curoff = 0;
+
if (td->td_stripsperimage == 0) {
TIFFErrorExt(tif->tif_clientdata, module,"Zero strips per image");
return ((tmsize_t) -1);
@@ -412,8 +411,12 @@ TIFFWriteEncodedTile(TIFF* tif, uint32_t tile, void* data, tmsize_t cc)
return ((tmsize_t)(-1));
tif->tif_flags |= TIFF_BUF4WRITE;
+
tif->tif_curtile = tile;
+ /* this informs TIFFAppendToStrip() we have changed or reset tile */
+ tif->tif_curoff = 0;
+
if( !_TIFFReserveLargeEnoughWriteBuffer(tif, tile) ) {
return ((tmsize_t)(-1));
}
@@ -797,7 +800,8 @@ TIFFAppendToStrip(TIFF* tif, uint32_t strip, uint8_t* data, tmsize_t cc)
return (0);
}
- if( tif->tif_lastvalidoff != 0 && m > tif->tif_lastvalidoff )
+ if( tif->tif_lastvalidoff != 0 && m > tif->tif_lastvalidoff &&
+ td->td_stripbytecount_p[strip] > 0 )
{
/* Ouch: we have detected that we are rewriting in place a strip/tile */
/* with several calls to TIFFAppendToStrip(). The first call was with */
@@ -927,6 +931,7 @@ void
TIFFSetWriteOffset(TIFF* tif, toff_t off)
{
tif->tif_curoff = off;
+ tif->tif_lastvalidoff = 0;
}
/* vim: set ts=8 sts=8 sw=8 noet: */
diff --git a/tools/tiffinfo.c b/tools/tiffinfo.c
index 12cd108c..0ab8ca95 100644
--- a/tools/tiffinfo.c
+++ b/tools/tiffinfo.c
@@ -476,7 +476,7 @@ TIFFReadRawDataTiled(TIFF* tif, int bitrev)
{
const char* what = "Tile";
uint32_t ntiles = TIFFNumberOfTiles(tif);
- uint64_t *tilebc;
+ uint64_t *tilebc = NULL;
TIFFGetField(tif, TIFFTAG_TILEBYTECOUNTS, &tilebc);
if (tilebc != NULL && ntiles > 0) {
diff --git a/tools/tiffsplit.c b/tools/tiffsplit.c
index 296d6bf9..ffcd00f2 100644
--- a/tools/tiffsplit.c
+++ b/tools/tiffsplit.c
@@ -91,10 +91,16 @@ main(int argc, char* argv[])
out = TIFFOpen(path, TIFFIsBigEndian(in)?"wb":"wl");
_TIFFfree(path);
- if (out == NULL)
+ if (out == NULL) {
+ TIFFClose(in);
return (EXIT_FAILURE);
- if (!tiffcp(in, out))
+ }
+ if (!tiffcp(in, out)) {
+ TIFFClose(in);
+ TIFFClose(out);
return (EXIT_FAILURE);
+
+ }
TIFFClose(out);
} while (TIFFReadDirectory(in));