From e7d43b94a339fc76ea0ca6a2dfef96dc384e8094 Mon Sep 17 00:00:00 2001 From: Kevin Backhouse Date: Mon, 2 Aug 2021 23:04:13 +0100 Subject: [PATCH 1/2] Regression test for https://github.com/Exiv2/exiv2/issues/1830 (cherry picked from commit 8b844c2dceab3ffd9bf423ffc4672bda5ee7cc8d) --- test/data/issue_1830_poc.tiff | Bin 0 -> 1021 bytes tests/bugfixes/github/test_issue_1830.py | 17 +++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 test/data/issue_1830_poc.tiff create mode 100644 tests/bugfixes/github/test_issue_1830.py diff --git a/test/data/issue_1830_poc.tiff b/test/data/issue_1830_poc.tiff new file mode 100644 index 0000000000000000000000000000000000000000..c939dfb2d942b7f8feba41a639dfa619f6beac4c GIT binary patch literal 1021 zcmcIjOKTKC5U%dbx~>XpR0J1I`3OD^3&}4K(Zd`BAt>HryUxzGkm+S+b~k&F4IVT< z!IK9;$VHDHL&ryvgktCsl*-}V)zTy%@3npUaSQ@xx+ zd0PQL|8A`cp*E!LXX32MGC@7YmyK|w20_c7{BgCPJa$syVbzF!^C-N*un9+iuM4V9 z)T6Me7F9A8iHU5A%U##e2Ux)$GTEw%Ww z8H~8sb>(HpcSn2!%%!>Mb(8%4i-NBkc}lOYt=hq&-`w{Nq=SKlaW6jT0Xm3ZqXG65 zatM46^af;B&4jm>2Rfl@fxiTAs+x>#1j8}toxy%RzKFTUgrB`Kw;T??g6{%?NE*4Z vh~Ouo-%j{ZXrhmFL|2J$=*dGZSDP|*Um*6eq#?S4<@tv?-S=Bz{= Date: Mon, 2 Aug 2021 23:04:58 +0100 Subject: [PATCH 2/2] Safer casting from double to long. (cherry picked from commit 372e28c41044a9e8b65d7d7093e028e30a7c8c8a) --- include/exiv2/value.hpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/include/exiv2/value.hpp b/include/exiv2/value.hpp index 788a65b446..486da9704c 100644 --- a/include/exiv2/value.hpp +++ b/include/exiv2/value.hpp @@ -1628,6 +1628,24 @@ namespace Exiv2 { } // #55 crash when value_.at(n).first == LONG_MIN #define LARGE_INT 1000000 + // Specialization for double + template<> + inline long ValueType::toLong(long n) const + { + const double v = value_.at(n); + ok_ = (INT_MIN <= v && v <= INT_MAX); + if (!ok_) return 0; + return static_cast(v); + } + // Specialization for float + template<> + inline long ValueType::toLong(long n) const + { + const double v = value_.at(n); + ok_ = (INT_MIN <= v && v <= INT_MAX); + if (!ok_) return 0; + return static_cast(v); + } // Specialization for rational template<> inline long ValueType::toLong(long n) const