File tiff-CVE-2023-38289.patch of Package tiff.34105

Index: tiff-4.0.9/tools/raw2tiff.c
===================================================================
--- tiff-4.0.9.orig/tools/raw2tiff.c
+++ tiff-4.0.9/tools/raw2tiff.c
@@ -36,6 +36,7 @@
 #include <sys/types.h>
 #include <math.h>
 #include <ctype.h>
+#include <limits.h>
 
 #ifdef HAVE_UNISTD_H
 # include <unistd.h>
@@ -102,6 +103,7 @@ main(int argc, char* argv[])
 	int	fd;
 	char	*outfilename = NULL;
 	TIFF	*out;
+	uint32 temp_limit_check = 0;     /* temp for integer overflow checking*/
 
 	uint32 row, col, band;
 	int	c;
@@ -213,6 +215,33 @@ main(int argc, char* argv[])
 	if (guessSize(fd, dtype, hdr_size, nbands, swab, &width, &length) < 0)
 		return 1;
 
+    /* check for integer overflow in */
+    /* hdr_size + (*width) * (*length) * nbands * depth */
+
+    if ((width == 0) || (length == 0) ){
+        fprintf(stderr, "Too large nbands value specified.\n");
+        return (EXIT_FAILURE);
+    }
+
+    temp_limit_check = nbands * depth;
+
+    if ( !temp_limit_check || length > ( UINT_MAX / temp_limit_check ) )  {
+        fprintf(stderr, "Too large length size specified.\n");
+        return (EXIT_FAILURE);
+    }
+    temp_limit_check = temp_limit_check * length;
+
+    if ( !temp_limit_check || width > ( UINT_MAX / temp_limit_check ) )  {
+        fprintf(stderr, "Too large width size specified.\n");
+        return (EXIT_FAILURE);
+    }
+    temp_limit_check = temp_limit_check * width;
+
+    if ( !temp_limit_check || hdr_size > ( UINT_MAX - temp_limit_check ) )  {
+        fprintf(stderr, "Too large header size specified.\n");
+        return (EXIT_FAILURE);
+    }
+
 	if (outfilename == NULL)
 		outfilename = argv[optind+1];
 	out = TIFFOpen(outfilename, "w");
openSUSE Build Service is sponsored by