Sophie

Sophie

distrib > Mageia > 8 > i586 > media > core-updates_testing-src > by-pkgid > 0a4e82cc20594aa76c552ec815a3f474 > files > 8

libtiff-4.2.0-1.16.mga8.src.rpm

From 4cc97e3dfa6559f4d17af0d0687bcae07ca4b73d Mon Sep 17 00:00:00 2001
From: Arie Haenel <arie.haenel@jct.ac.il>
Date: Wed, 19 Jul 2023 19:40:01 +0000
Subject: raw2tiff: fix integer overflow and bypass of the check (fixes #592)

---
 tools/raw2tiff.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/tools/raw2tiff.c b/tools/raw2tiff.c
index ab36ff4e..a905da52 100644
--- a/tools/raw2tiff.c
+++ b/tools/raw2tiff.c
@@ -35,6 +35,7 @@
 #include <sys/types.h>
 #include <math.h>
 #include <ctype.h>
+#include <limits.h>
 
 #ifdef HAVE_UNISTD_H
 # include <unistd.h>
@@ -108,6 +109,7 @@ main(int argc, char* argv[])
 	int	fd;
 	char	*outfilename = NULL;
 	TIFF	*out;
+	uint32  temp_limit_check = 0;
 
 	uint32 row, col, band;
 	int	c;
@@ -212,6 +214,30 @@ main(int argc, char* argv[])
 	if (guessSize(fd, dtype, hdr_size, nbands, swab, &width, &length) < 0)
 		return EXIT_FAILURE;
 
+	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");
-- 
2.30.2