From 3e540b2d3852b03adf46c3b12956ed918d00835c Mon Sep 17 00:00:00 2001 From: Andrey Kiselev Date: Thu, 4 Apr 2002 14:35:35 +0000 Subject: [PATCH] Assertions in LXWDecode and LZWDecodeCompat replaced by warnings. Now libtiff should read corrupted LZW-compressed files by skipping bad strips. Closes http://bugzilla.remotesensing.org/show_bug.cgi?id=100 --- libtiff/tif_lzw.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/libtiff/tif_lzw.c b/libtiff/tif_lzw.c index 53b2703d..db43a37f 100644 --- a/libtiff/tif_lzw.c +++ b/libtiff/tif_lzw.c @@ -1,4 +1,4 @@ -/* $Header: /cvs/maptools/cvsroot/libtiff/libtiff/tif_lzw.c,v 1.10 2002-04-03 20:18:16 warmerda Exp $ */ +/* $Header: /cvs/maptools/cvsroot/libtiff/libtiff/tif_lzw.c,v 1.11 2002-04-04 14:35:35 dron Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -396,7 +396,11 @@ LZWDecode(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s) /* * Add the new entry to the code table. */ - assert(&sp->dec_codetab[0] <= free_entp && free_entp < &sp->dec_codetab[CSIZE]); + if (&sp->dec_codetab[0] > free_entp || free_entp >= &sp->dec_codetab[CSIZE]) { + TIFFError(tif->tif_name, "LZWDecode: Unexpected end of code table"); + return (0); + } + free_entp->next = oldcodep; free_entp->firstchar = free_entp->next->firstchar; free_entp->length = free_entp->next->length+1; @@ -571,7 +575,11 @@ LZWDecodeCompat(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s) /* * Add the new entry to the code table. */ - assert(&sp->dec_codetab[0] <= free_entp && free_entp < &sp->dec_codetab[CSIZE]); + if (&sp->dec_codetab[0] > free_entp || free_entp >= &sp->dec_codetab[CSIZE]) { + TIFFError(tif->tif_name, "LZWDecode: Unexpected end of code table"); + return (0); + } + free_entp->next = oldcodep; free_entp->firstchar = free_entp->next->firstchar; free_entp->length = free_entp->next->length+1;