Blame SOURCES/0021-CVE-2022-0561-TIFFFetchStripThing-avoid-calling-memc.patch

ccba1e
From b94f6754796d32e204b874b3660a125973815933 Mon Sep 17 00:00:00 2001
ccba1e
From: Even Rouault <even.rouault@spatialys.com>
ccba1e
Date: Sun, 6 Feb 2022 13:08:38 +0100
ccba1e
Subject: [PATCH] (CVE-2022-0561) TIFFFetchStripThing(): avoid calling memcpy()
ccba1e
 with a null source pointer and size of zero (fixes #362)
ccba1e
ccba1e
(cherry picked from commit eecb0712f4c3a5b449f70c57988260a667ddbdef)
ccba1e
---
ccba1e
 libtiff/tif_dirread.c | 5 +++--
ccba1e
 1 file changed, 3 insertions(+), 2 deletions(-)
ccba1e
ccba1e
diff --git a/libtiff/tif_dirread.c b/libtiff/tif_dirread.c
ccba1e
index 80aaf8d1..1e6f1c2f 100644
ccba1e
--- a/libtiff/tif_dirread.c
ccba1e
+++ b/libtiff/tif_dirread.c
ccba1e
@@ -5633,8 +5633,9 @@ TIFFFetchStripThing(TIFF* tif, TIFFDirEntry* dir, uint32 nstrips, uint64** lpp)
ccba1e
 			_TIFFfree(data);
ccba1e
 			return(0);
ccba1e
 		}
ccba1e
-                _TIFFmemcpy(resizeddata,data,(uint32)dir->tdir_count*sizeof(uint64));
ccba1e
-                _TIFFmemset(resizeddata+(uint32)dir->tdir_count,0,(nstrips-(uint32)dir->tdir_count)*sizeof(uint64));
ccba1e
+		if( dir->tdir_count )
ccba1e
+			_TIFFmemcpy(resizeddata,data,(uint32)dir->tdir_count*sizeof(uint64));
ccba1e
+		_TIFFmemset(resizeddata+(uint32)dir->tdir_count,0,(nstrips-(uint32)dir->tdir_count)*sizeof(uint64));
ccba1e
 		_TIFFfree(data);
ccba1e
 		data=resizeddata;
ccba1e
 	}