From 20499fa9b1423d70252aa5289a6156d948976143 Mon Sep 17 00:00:00 2001 From: Frank Warmerdam Date: Fri, 9 Dec 2011 03:29:10 +0000 Subject: [PATCH] more cautious testing of _TIFFFillStriles() results (gdal #4372) --- ChangeLog | 5 +++++ libtiff/tif_dirread.c | 7 ++++--- libtiff/tif_read.c | 26 +++++++++++++++++--------- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 44b86f57..35051ef3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-12-08 Frank Warmerdam + + * libtiff/tif_dirread.c, libtiff/tif_read.c: more cautious checking + of _TIFFFillStriles() results (#gdal 4372) + 2011-12-07 Frank Warmerdam * libtiff/tif_dirread.c: fixes to deal with invalid files where diff --git a/libtiff/tif_dirread.c b/libtiff/tif_dirread.c index 81d0dd36..5db51478 100644 --- a/libtiff/tif_dirread.c +++ b/libtiff/tif_dirread.c @@ -1,4 +1,4 @@ -/* $Id: tif_dirread.c,v 1.171 2011-12-08 05:48:39 fwarmerdam Exp $ */ +/* $Id: tif_dirread.c,v 1.172 2011-12-09 03:29:10 fwarmerdam Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -3592,7 +3592,8 @@ TIFFReadDirectory(TIFF* tif) if ((tif->tif_dir.td_compression==COMPRESSION_OJPEG)&& (tif->tif_dir.td_planarconfig==PLANARCONFIG_SEPARATE)) { - _TIFFFillStriles(tif); + if (!_TIFFFillStriles(tif)) + goto bad; dp=TIFFReadDirectoryFindEntry(tif,dir,dircount,TIFFTAG_STRIPOFFSETS); if ((dp!=0)&&(dp->tdir_count==1)) { @@ -4269,7 +4270,7 @@ EstimateStripByteCounts(TIFF* tif, TIFFDirEntry* dir, uint16 dircount) TIFFDirectory *td = &tif->tif_dir; uint32 strip; - _TIFFFillStriles( tif ); + _TIFFFillStriles( tif ); if (td->td_stripbytecount) _TIFFfree(td->td_stripbytecount); diff --git a/libtiff/tif_read.c b/libtiff/tif_read.c index 9f7641a6..594733f8 100644 --- a/libtiff/tif_read.c +++ b/libtiff/tif_read.c @@ -1,4 +1,4 @@ -/* $Id: tif_read.c,v 1.37 2011-04-02 20:54:09 bfriesen Exp $ */ +/* $Id: tif_read.c,v 1.38 2011-12-09 03:29:10 fwarmerdam Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -52,7 +52,8 @@ TIFFFillStripPartial( TIFF *tif, int strip, tmsize_t read_ahead, int restart ) tmsize_t cc, to_read; tmsize_t bytecountm; - _TIFFFillStriles( tif ); + if (!_TIFFFillStriles( tif ) || !tif->tif_dir.td_stripbytecount) + return 0; /* * Expand raw data buffer, if needed, to hold data @@ -199,7 +200,8 @@ TIFFSeek(TIFF* tif, uint32 row, uint16 sample ) * read it a few lines at a time? */ #if defined(CHUNKY_STRIP_READ_SUPPORT) - _TIFFFillStriles( tif ); + if (!_TIFFFillStriles( tif ) || !tif->tif_dir.td_stripbytecount) + return 0; whole_strip = tif->tif_dir.td_stripbytecount[strip] < 10 || isMapped(tif); #else @@ -360,7 +362,8 @@ TIFFReadRawStrip1(TIFF* tif, uint32 strip, void* buf, tmsize_t size, { TIFFDirectory *td = &tif->tif_dir; - _TIFFFillStriles( tif ); + if (!_TIFFFillStriles( tif )) + return ((tmsize_t)(-1)); assert((tif->tif_flags&TIFF_NOREADRAW)==0); if (!isMapped(tif)) { @@ -485,7 +488,8 @@ TIFFFillStrip(TIFF* tif, uint32 strip) static const char module[] = "TIFFFillStrip"; TIFFDirectory *td = &tif->tif_dir; - _TIFFFillStriles( tif ); + if (!_TIFFFillStriles( tif ) || !tif->tif_dir.td_stripbytecount) + return 0; if ((tif->tif_flags&TIFF_NOREADRAW)==0) { @@ -654,7 +658,8 @@ TIFFReadRawTile1(TIFF* tif, uint32 tile, void* buf, tmsize_t size, const char* m { TIFFDirectory *td = &tif->tif_dir; - _TIFFFillStriles( tif ); + if (!_TIFFFillStriles( tif )) + return ((tmsize_t)(-1)); assert((tif->tif_flags&TIFF_NOREADRAW)==0); if (!isMapped(tif)) { @@ -770,7 +775,8 @@ TIFFFillTile(TIFF* tif, uint32 tile) static const char module[] = "TIFFFillTile"; TIFFDirectory *td = &tif->tif_dir; - _TIFFFillStriles( tif ); + if (!_TIFFFillStriles( tif ) || !tif->tif_dir.td_stripbytecount) + return 0; if ((tif->tif_flags&TIFF_NOREADRAW)==0) { @@ -915,7 +921,8 @@ TIFFStartStrip(TIFF* tif, uint32 strip) { TIFFDirectory *td = &tif->tif_dir; - _TIFFFillStriles( tif ); + if (!_TIFFFillStriles( tif ) || !tif->tif_dir.td_stripbytecount) + return 0; if ((tif->tif_flags & TIFF_CODERSETUP) == 0) { if (!(*tif->tif_setupdecode)(tif)) @@ -949,7 +956,8 @@ TIFFStartTile(TIFF* tif, uint32 tile) { TIFFDirectory *td = &tif->tif_dir; - _TIFFFillStriles( tif ); + if (!_TIFFFillStriles( tif ) || !tif->tif_dir.td_stripbytecount) + return 0; if ((tif->tif_flags & TIFF_CODERSETUP) == 0) { if (!(*tif->tif_setupdecode)(tif))