From 37388c3fd7cbbee7f5d9cdeab1d748b21986aef7 Mon Sep 17 00:00:00 2001 From: Kevin Backhouse Date: Sat, 18 Sep 2021 14:32:48 +0100 Subject: [PATCH 1/2] Regression test for https://github.com/Exiv2/exiv2/issues/1912 --- test/data/issue_1912_poc.jpg | Bin 0 -> 3754 bytes tests/bugfixes/github/test_issue_1912.py | 17 +++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 test/data/issue_1912_poc.jpg create mode 100644 tests/bugfixes/github/test_issue_1912.py diff --git a/test/data/issue_1912_poc.jpg b/test/data/issue_1912_poc.jpg new file mode 100644 index 0000000000000000000000000000000000000000..837d2ebb015d636d47c9ff44b2b002ee4896ebba GIT binary patch literal 3754 zcmeHKYi!$86u#F^`kKVrGPbd0!t>Uxj3sv5rcJD-WlNVX6Dg%BZ8ss1+c>RhVh6`- z(h3li!3IL23uV9rsB~q(#2;XTF_3tT=Re*935oF>{NeqYgvzBwg~1+C1rU@TL2)#laMf_EV0Xo+3t7mKW4j#d&?Q=yLSwqTAsc z#d3RJh*7c9#?^qU9M1LAC4c-pKaFh;oO7BgMG8+&(+=J|bDpzy&&*N>-#JrluZ4)u zteD4#Ec=+GY_?>dV9MqYOrL{Yj?JmrvUxqwNCVI4Ga$_@E|i6ZbilVN2H`fqOldtx z(nwZUK(ByKstvA>fPgjb_+KDbS~}1#v5|`+m5I%aQJnw*kvfE3=nXKES*nldtTc8UOw1UdXQSAxRz8> zWB);NPAd|UWfKZ$A%h&`owE~9pi@V!%wk)Nz+wazBd{2O#R&Y5A^@*oF%RB_=+$){ z9(dcN5aprT&=NirXcU5%@X$O|E2<#>hJ1hzdZ^}eFIxV=M8U1GxT_9qB2+zg_IO(C z2-M#-b*yHn{?lvbUP3h$cr%`)@mfUHV7dm+okSPGJE0q!&0Gcpe5|RZDCeCT@~f}EIrHszKmPRdFTeiw`yYRvCFg=K6zf Date: Mon, 20 Sep 2021 22:06:07 +0100 Subject: [PATCH 2/2] Do the calculation in floating point to avoid integer overflow. --- src/tags_int.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/tags_int.cpp b/src/tags_int.cpp index 53b28ba0..e7cb50cd 100644 --- a/src/tags_int.cpp +++ b/src/tags_int.cpp @@ -2767,15 +2767,18 @@ namespace Exiv2 { } std::ostringstream oss; oss.copyfmt(os); - const float sec = 3600 * value.toFloat(0) - + 60 * value.toFloat(1) - + value.toFloat(2); + const double t = 3600 * value.toFloat(0) + + 60 * value.toFloat(1) + + value.toFloat(2); + enforce(std::isfinite(t), "Non-finite time value"); int p = 0; - if (sec != static_cast(sec)) p = 1; - - const int hh = static_cast(sec / 3600); - const int mm = static_cast((sec - 3600 * hh) / 60); - const float ss = sec - 3600 * hh - 60 * mm; + const double fraction = std::fmod(t,1); + if (fraction != 0) p = 1; + const double ss = std::fmod(t, 60); + const double minutes = (t - ss)/60; + const int mm = static_cast(std::fmod(minutes, 60)); + const double hours = (minutes - mm)/60; + const int hh = static_cast(std::fmod(hours, 24)); os << std::setw(2) << std::setfill('0') << std::right << hh << ":" << std::setw(2) << std::setfill('0') << std::right << mm << ":"