From 78dab0996f74644381c9d5c4461208abd9923351 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Fri, 2 Dec 2016 22:13:32 +0000 Subject: [PATCH] * tools/tiffcp.c: avoid uint32 underflow in cpDecodedStrips that can cause various issues, such as buffer overflows in the library. Reported by Agostino Sarubbo. Fixes http://bugzilla.maptools.org/show_bug.cgi?id=2598 --- ChangeLog | 7 +++++++ tools/tiffcp.c | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 668b66ad..0f154d66 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2016-12-02 Even Rouault + + * tools/tiffcp.c: avoid uint32 underflow in cpDecodedStrips that + can cause various issues, such as buffer overflows in the library. + Reported by Agostino Sarubbo. + Fixes http://bugzilla.maptools.org/show_bug.cgi?id=2598 + 2016-12-02 Even Rouault * libtiff/tif_read.c, libtiff/tiffiop.h: fix uint32 overflow in diff --git a/tools/tiffcp.c b/tools/tiffcp.c index 338a3d11..6dfb9a91 100644 --- a/tools/tiffcp.c +++ b/tools/tiffcp.c @@ -1,4 +1,4 @@ -/* $Id: tiffcp.c,v 1.55 2016-10-08 15:54:57 erouault Exp $ */ +/* $Id: tiffcp.c,v 1.56 2016-12-02 22:13:32 erouault Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -985,7 +985,7 @@ DECLAREcpFunc(cpDecodedStrips) tstrip_t s, ns = TIFFNumberOfStrips(in); uint32 row = 0; _TIFFmemset(buf, 0, stripsize); - for (s = 0; s < ns; s++) { + for (s = 0; s < ns && row < imagelength; s++) { tsize_t cc = (row + rowsperstrip > imagelength) ? TIFFVStripSize(in, imagelength - row) : stripsize; if (TIFFReadEncodedStrip(in, s, buf, cc) < 0