From 92c680cdf13fec90bcfd2d3d77cf208cfa1dbf3a Mon Sep 17 00:00:00 2001 From: Frank Warmerdam Date: Mon, 20 Nov 2006 02:11:39 +0000 Subject: [PATCH] clear sorted flag if we move a strip/tile - bug 1359 --- ChangeLog | 6 +++ libtiff/tif_write.c | 117 ++++++++++++++++++++++---------------------- 2 files changed, 65 insertions(+), 58 deletions(-) diff --git a/ChangeLog b/ChangeLog index a2f2dd7c..58e72726 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2006-11-19 Frank Warmerdam + + * libtiff/tif_write.c: TIFFAppendToStrip() - clear sorted flag if + we move a strip. + http://bugzilla.remotesensing.org/show_bug.cgi?id=1359 + 2006-10-13 Andrey Kiselev * libtiff/tif_dir.c: More fixes for vulnerabilities, reported diff --git a/libtiff/tif_write.c b/libtiff/tif_write.c index 5dd2ae66..85b17314 100644 --- a/libtiff/tif_write.c +++ b/libtiff/tif_write.c @@ -1,4 +1,4 @@ -/* $Id: tif_write.c,v 1.21 2006-02-27 14:29:20 dron Exp $ */ +/* $Id: tif_write.c,v 1.22 2006-11-20 02:11:41 fwarmerdam Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -625,66 +625,67 @@ TIFFGrowStrips(TIFF* tif, int delta, const char* module) static int TIFFAppendToStrip(TIFF* tif, tstrip_t strip, tidata_t data, tsize_t cc) { - TIFFDirectory *td = &tif->tif_dir; - static const char module[] = "TIFFAppendToStrip"; + TIFFDirectory *td = &tif->tif_dir; + static const char module[] = "TIFFAppendToStrip"; - if (td->td_stripoffset[strip] == 0 || tif->tif_curoff == 0) { - /* - * No current offset, set the current strip. - */ - assert(td->td_nstrips > 0); - if (td->td_stripoffset[strip] != 0) { - /* - * Prevent overlapping of the data chunks. We need - * this to enable in place updating of the compressed - * images. Larger blocks will be moved at the end of - * the file without any optimization of the spare - * space, so such scheme is not too much effective. - */ - if (td->td_stripbytecountsorted) { - if (strip == td->td_nstrips - 1 - || td->td_stripoffset[strip + 1] < - td->td_stripoffset[strip] + cc) { - td->td_stripoffset[strip] = - TIFFSeekFile(tif, (toff_t)0, - SEEK_END); - } - } else { - tstrip_t i; - for (i = 0; i < td->td_nstrips; i++) { - if (td->td_stripoffset[i] > - td->td_stripoffset[strip] - && td->td_stripoffset[i] < - td->td_stripoffset[strip] + cc) { - td->td_stripoffset[strip] = - TIFFSeekFile(tif, - (toff_t)0, - SEEK_END); - } - } - } + if (td->td_stripoffset[strip] == 0 || tif->tif_curoff == 0) { + /* + * No current offset, set the current strip. + */ + assert(td->td_nstrips > 0); + if (td->td_stripoffset[strip] != 0) { + /* + * Prevent overlapping of the data chunks. We need + * this to enable in place updating of the compressed + * images. Larger blocks will be moved at the end of + * the file without any optimization of the spare + * space, so such scheme is not too much effective. + */ + if (td->td_stripbytecountsorted) { + if (strip == td->td_nstrips - 1 + || td->td_stripoffset[strip + 1] < + td->td_stripoffset[strip] + cc) { + td->td_stripoffset[strip] = + TIFFSeekFile(tif, (toff_t)0, + SEEK_END); + td->td_stripbytecountsorted = 0; + } + } else { + tstrip_t i; + for (i = 0; i < td->td_nstrips; i++) { + if (td->td_stripoffset[i] > + td->td_stripoffset[strip] + && td->td_stripoffset[i] < + td->td_stripoffset[strip] + cc) { + td->td_stripoffset[strip] = + TIFFSeekFile(tif, + (toff_t)0, + SEEK_END); + } + } + } - if (!SeekOK(tif, td->td_stripoffset[strip])) { - TIFFErrorExt(tif->tif_clientdata, module, - "%s: Seek error at scanline %lu", - tif->tif_name, - (unsigned long)tif->tif_row); - return (0); - } - } else - td->td_stripoffset[strip] = - TIFFSeekFile(tif, (toff_t) 0, SEEK_END); - tif->tif_curoff = td->td_stripoffset[strip]; - } + if (!SeekOK(tif, td->td_stripoffset[strip])) { + TIFFErrorExt(tif->tif_clientdata, module, + "%s: Seek error at scanline %lu", + tif->tif_name, + (unsigned long)tif->tif_row); + return (0); + } + } else + td->td_stripoffset[strip] = + TIFFSeekFile(tif, (toff_t) 0, SEEK_END); + tif->tif_curoff = td->td_stripoffset[strip]; + } - if (!WriteOK(tif, data, cc)) { - TIFFErrorExt(tif->tif_clientdata, module, "%s: Write error at scanline %lu", - tif->tif_name, (unsigned long) tif->tif_row); - return (0); - } - tif->tif_curoff += cc; - td->td_stripbytecount[strip] += cc; - return (1); + if (!WriteOK(tif, data, cc)) { + TIFFErrorExt(tif->tif_clientdata, module, "%s: Write error at scanline %lu", + tif->tif_name, (unsigned long) tif->tif_row); + return (0); + } + tif->tif_curoff += cc; + td->td_stripbytecount[strip] += cc; + return (1); } /*