From b3199a072073ac6292e5bbbd5cce2167f1932ea8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan=20=C4=8Cerm=C3=A1k?= Date: Mon, 3 Sep 2018 21:14:16 +0200 Subject: [PATCH] Fix division by zero in BigTiffImage::printIFD This fixes #262 --- src/bigtiffimage.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/bigtiffimage.cpp b/src/bigtiffimage.cpp index d80e2c51..26165231 100644 --- a/src/bigtiffimage.cpp +++ b/src/bigtiffimage.cpp @@ -251,8 +251,12 @@ namespace Exiv2 // size * count > std::numeric_limits::max() // => // size > std::numeric_limits::max() / count - if (size > std::numeric_limits::max() / count) - throw Error(kerInvalidMalloc); // we got number bigger than 2^64 + // (don't perform that check when count == 0 => will cause a division by zero exception) + if (count != 0) { + if (size > std::numeric_limits::max() / count) { + throw Error(kerInvalidMalloc); // we got number bigger than 2^64 + } + } // more than we can handle if (size * count > std::numeric_limits::max() - pad)