summaryrefslogtreecommitdiff
blob: 6e1011b072dc49c3174f9a9eb06d392aea0990c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
From 101253c74cde97203dab28c4f3bd0994cea5804c Mon Sep 17 00:00:00 2001
From: Even Rouault <even.rouault@spatialys.com>
Date: Sat, 14 Jan 2017 13:12:33 +0000
Subject: [PATCH] * tools/raw2tiff.c: avoid integer division by zero. Fixes
 http://bugzilla.maptools.org/show_bug.cgi?id=2631

---
 ChangeLog        |  5 +++++
 tools/raw2tiff.c | 10 ++++++++--
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/tools/raw2tiff.c b/tools/raw2tiff.c
index 7298e80a95c9..083e9ee73f0f 100644
--- a/tools/raw2tiff.c
+++ b/tools/raw2tiff.c
@@ -408,8 +408,14 @@ guessSize(int fd, TIFFDataType dtype, _TIFF_off_t hdr_size, uint32 nbands,
 	} else if (*width == 0 && *length == 0) {
                 unsigned int fail = 0;
 		fprintf(stderr,	"Image width and height are not specified.\n");
+                w = (uint32) sqrt(imagesize / longt);
+                if( w == 0 )
+                {
+                    fprintf(stderr, "Too small image size.\n");
+                    return -1;
+                }
 
-		for (w = (uint32) sqrt(imagesize / longt);
+		for (;
 		     w < sqrt(imagesize * longt);
 		     w++) {
 			if (imagesize % w == 0) {
-- 
2.12.0