Store a list of opened IFD to prevent looping as per bug

http://bugzilla.remotesensing.org/show_bug.cgi?id=383
This commit is contained in:
Andrey Kiselev 2003-09-25 08:36:21 +00:00
parent bb7ac0701f
commit 136507d95a
4 changed files with 20 additions and 10 deletions

View File

@ -1,4 +1,4 @@
/* $Header: /cvs/maptools/cvsroot/libtiff/libtiff/tif_dir.c,v 1.29 2003-07-08 16:40:46 warmerda Exp $ */ /* $Header: /cvs/maptools/cvsroot/libtiff/libtiff/tif_dir.c,v 1.30 2003-09-25 08:36:21 dron Exp $ */
/* /*
* Copyright (c) 1988-1997 Sam Leffler * Copyright (c) 1988-1997 Sam Leffler
@ -1302,6 +1302,11 @@ TIFFSetDirectory(TIFF* tif, tdir_t dirn)
* tif_curdir after successfully reading the directory. * tif_curdir after successfully reading the directory.
*/ */
tif->tif_curdir = (dirn - n) - 1; tif->tif_curdir = (dirn - n) - 1;
/*
* Reset tif_dirnumber counter nad start new list of seen directories.
* We need this in order to prevent IFD loops.
*/
tif->tif_dirnumber = 0;
return (TIFFReadDirectory(tif)); return (TIFFReadDirectory(tif));
} }
@ -1315,6 +1320,11 @@ int
TIFFSetSubDirectory(TIFF* tif, uint32 diroff) TIFFSetSubDirectory(TIFF* tif, uint32 diroff)
{ {
tif->tif_nextdiroff = diroff; tif->tif_nextdiroff = diroff;
/*
* Reset tif_dirnumber counter nad start new list of seen directories.
* We need this in order to prevent IFD loops.
*/
tif->tif_dirnumber = 0;
return (TIFFReadDirectory(tif)); return (TIFFReadDirectory(tif));
} }

View File

@ -1,4 +1,4 @@
/* $Header: /cvs/maptools/cvsroot/libtiff/libtiff/tif_dirread.c,v 1.22 2003-09-25 08:02:46 dron Exp $ */ /* $Header: /cvs/maptools/cvsroot/libtiff/libtiff/tif_dirread.c,v 1.23 2003-09-25 08:36:21 dron Exp $ */
/* /*
* Copyright (c) 1988-1997 Sam Leffler * Copyright (c) 1988-1997 Sam Leffler
@ -103,20 +103,20 @@ TIFFReadDirectory(TIFF* tif)
* with looped directory pointers. We will maintain a list of already * with looped directory pointers. We will maintain a list of already
* seen directories and check every IFD offset against this list. * seen directories and check every IFD offset against this list.
*/ */
for (n = 0; n < tif->tif_dircount; n++) { for (n = 0; n < tif->tif_dirnumber; n++) {
if (tif->tif_dirlist[n] == tif->tif_diroff) if (tif->tif_dirlist[n] == tif->tif_diroff)
return (0); return (0);
} }
tif->tif_dircount++; tif->tif_dirnumber++;
tif->tif_dirlist = _TIFFrealloc(tif->tif_dirlist, tif->tif_dirlist = _TIFFrealloc(tif->tif_dirlist,
tif->tif_dircount * sizeof(toff_t)); tif->tif_dirnumber * sizeof(toff_t));
if (!tif->tif_dirlist) { if (!tif->tif_dirlist) {
TIFFError(module, TIFFError(module,
"%.1000s: Failed to allocate space for IFD list", "%.1000s: Failed to allocate space for IFD list",
tif->tif_name); tif->tif_name);
return (0); return (0);
} }
tif->tif_dirlist[tif->tif_dircount - 1] = tif->tif_diroff; tif->tif_dirlist[tif->tif_dirnumber - 1] = tif->tif_diroff;
/* /*
* Cleanup any previous compression state. * Cleanup any previous compression state.

View File

@ -1,4 +1,4 @@
/* $Header: /cvs/maptools/cvsroot/libtiff/libtiff/tif_open.c,v 1.10 2003-09-25 08:02:46 dron Exp $ */ /* $Header: /cvs/maptools/cvsroot/libtiff/libtiff/tif_open.c,v 1.11 2003-09-25 08:36:21 dron Exp $ */
/* /*
* Copyright (c) 1988-1997 Sam Leffler * Copyright (c) 1988-1997 Sam Leffler
@ -314,7 +314,7 @@ TIFFClientOpen(
goto bad; goto bad;
tif->tif_diroff = 0; tif->tif_diroff = 0;
tif->tif_dirlist = NULL; tif->tif_dirlist = NULL;
tif->tif_dircount = 0; tif->tif_dirnumber = 0;
return (tif); return (tif);
} }
/* /*

View File

@ -1,4 +1,4 @@
/* $Header: /cvs/maptools/cvsroot/libtiff/libtiff/tiffiop.h,v 1.6 2003-09-25 08:02:46 dron Exp $ */ /* $Header: /cvs/maptools/cvsroot/libtiff/libtiff/tiffiop.h,v 1.7 2003-09-25 08:36:21 dron Exp $ */
/* /*
* Copyright (c) 1988-1997 Sam Leffler * Copyright (c) 1988-1997 Sam Leffler
@ -94,7 +94,7 @@ struct tiff {
toff_t tif_nextdiroff; /* file offset of following directory */ toff_t tif_nextdiroff; /* file offset of following directory */
toff_t* tif_dirlist; /* list of offsets to already seen */ toff_t* tif_dirlist; /* list of offsets to already seen */
/* directories to prevent IFD looping */ /* directories to prevent IFD looping */
uint16 tif_dircount; /* number of already seen directories */ uint16 tif_dirnumber; /* number of already seen directories */
TIFFDirectory tif_dir; /* internal rep of current directory */ TIFFDirectory tif_dir; /* internal rep of current directory */
TIFFHeader tif_header; /* file's header block */ TIFFHeader tif_header; /* file's header block */
const int* tif_typeshift; /* data type shift counts */ const int* tif_typeshift; /* data type shift counts */