From db527f446f33a7717205a6afba60f669d17ecf7f Mon Sep 17 00:00:00 2001 From: Kevin Backhouse Date: Mon, 2 Aug 2021 17:12:13 +0100 Subject: [PATCH 1/3] Regression test for https://github.com/Exiv2/exiv2/issues/1827 --- test/data/issue_1827_poc.crw | Bin 0 -> 10078 bytes tests/bugfixes/github/test_issue_1827.py | 17 +++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 test/data/issue_1827_poc.crw create mode 100644 tests/bugfixes/github/test_issue_1827.py diff --git a/test/data/issue_1827_poc.crw b/test/data/issue_1827_poc.crw new file mode 100644 index 0000000000000000000000000000000000000000..eafb76235397e63c04b7f0f196e464cf1c421ebb GIT binary patch literal 10078 zcmeHsc{r6__wc^YaSX>i98(CHhaxk{ka?bk$e1aTA)zv+5;BWY$jl)!Bq_<1A(44X zC7}?J3g`UpbLtu2=Y5{{cU|9iecvDNTG!t9T6^ui*IxVH_ulK?OIMd20HC9(W^&|+ zh8ax$3ivVnB!~eNq@?7eC<<~iax?`6B{efGH5C;#2P1}#nTK;9FAoRVUOr)IF+M>_ zL9V^x%Hoo;a*B$Iydo+Zhvn6!

Bf3JMA;G!+vS6%#EQjizO1N2A%@$1Vu{rg#t}U2M`bvi6B9uP$VR9 z&GWAiNI*i5V&IWfBV{yoBI7;HbTBeGk9?nc^%IQQz$ZQ_Xa6V)G&2h;8#}*%ppdYL zw2Z8ryn^Bp4NWa=9bG+h3rj2Oqc*lKu5KsXJv_Yv0)x&3pA89(j=30n>GGAhl+?8J zjLhp<+4*-03X6(MO3P~Q)z;NF+;4o)`n0XRqqFN-_u$K+;gQj?@rl=O-p;+7f4{J} zw6^|vWAn?_*Kgk;fc#+&od2-sr#kI3ejtP&|^P3~Hui zPNx}p4@QzRsVC=EKcUzsW%dc<>_32J=97NSzeX^LXwg3z)JQbw!{1v}`PUZxYS1tC z0Q>}?LPGEhL(&5kkjI3as1@g)n4NR97Qdo-qe=FbUC2JSUX5E}Yo^lv(fy|q4yb4C z5e+82uC}3)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-SLl>`?6Z!$dMIR>ZxC|9{qiC8r5sFh$5=_0RDfYoP?Bkb( z4X=BQOzdW#zg+PJd-x4^1a%4d9=fRHTFnxAW)CGy;nnLD?7a_}#)h8SM!N82IdJLI z501x{wB;~7UfRm!-56UMq}GoH2u6+FUpoRr&uVJ zpuW&$)S7gZ?K7z3&J!qDCdp^7AE)QdAFXvk6oAo%Uza)Pt=1(ss zq(DaP{`@{VHQ5&TZum(@_EJ#XJ5R@p;~1_8Q85DpU3RCX;)%v;u`lHxYj`E^r&a}U zmjuTaG#8}HT-m+In6G1DAefimqEyTW~l(@w`5#Q`waVcAR~yc>JFXRC|c?Q^lAyq*oZ!d)7HbKV@67Hhpm? z$g;lu=E&n@%(zE}x+>JD>kmh^S@%uX3q8Hb}M4b~PtT5a4gt*+P3Jd~lyrd~nR zIp>bHW8PND@;*?qM#|St&;f3L??Szx6Ywcd4w6Wmk!Y~GP4(bEPv-wvmjw0-ejqQ< zp=co`cozgO6i;49%11#11S#r>_mMx&8{$C&5b)6!a7YyX=Yai@h(HL6_)%_6K{)dW z{wxlU2Ap8y=Q%~VDujsMFrl812_Ywdun7YGui}D6fe4)}%oF@&@pA;RI-JDl;6@+? zrVavvo09@_a4iBw0e}SE30RUs4}dg$lSdCh7l!C0>3HF?uW*?RDInwX0F(<97Vrj1dawR&NQrqaS{H! zn29%LLNLWbq;y~kMNSx{2TUO)2s%Arjzq{7rq03?nNST(4Z;+q#1yPQ2A&{C48i{* U=T?WuNdUCO0$f7iL<9l&AOFXHcmMzZ literal 0 HcmV?d00001 diff --git a/tests/bugfixes/github/test_issue_1827.py b/tests/bugfixes/github/test_issue_1827.py new file mode 100644 index 0000000000..3f9c4eaf3f --- /dev/null +++ b/tests/bugfixes/github/test_issue_1827.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- + +from system_tests import CaseMeta, CopyTmpFiles, path, check_no_ASAN_UBSAN_errors + +class ExposureTimeCastDoubleToLong(metaclass=CaseMeta): + """ + Regression test for the bug described in: + https://github.com/Exiv2/exiv2/issues/1827 + """ + url = "https://github.com/Exiv2/exiv2/issues/1827" + + filename = path("$data_path/issue_1827_poc.crw") + commands = ["$exiv2 $filename"] + stderr = [""] + retval = [0] + + compare_stdout = check_no_ASAN_UBSAN_errors From 1455cc88466a14d8ea49935005e9de097984f012 Mon Sep 17 00:00:00 2001 From: Kevin Backhouse Date: Mon, 2 Aug 2021 17:19:13 +0100 Subject: [PATCH 2/3] Check value is in range before casting from double to uint32_t, to avoid undefined behavior. --- src/tags_int.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/tags_int.cpp b/src/tags_int.cpp index cc23ded71d..923d1151fc 100644 --- a/src/tags_int.cpp +++ b/src/tags_int.cpp @@ -2585,12 +2585,22 @@ namespace Exiv2 { URational exposureTime(float shutterSpeedValue) { URational ur(1, 1); - double tmp = std::exp(std::log(2.0) * static_cast(shutterSpeedValue)); + const double tmp = std::exp(std::log(2.0) * static_cast(shutterSpeedValue)); if (tmp > 1) { - ur.second = static_cast(tmp + 0.5); + // Add 0.5 for rounding. + const double x = tmp + 0.5; + // Check that x is within the range of a uint32_t before casting. + if (0 <= x && x <= std::numeric_limits::max()) { + ur.second = static_cast(x); + } } else { - ur.first = static_cast(1/tmp + 0.5); + // Add 0.5 for rounding. + const double x = 1/tmp + 0.5; + // Check that x is within the range of a uint32_t before casting. + if (0 <= x && x <= std::numeric_limits::max()) { + ur.first = static_cast(x); + } } return ur; } From ad2e7221b498258bd04188b66f6da5cefd101e73 Mon Sep 17 00:00:00 2001 From: Kevin Backhouse Date: Mon, 2 Aug 2021 22:32:35 +0100 Subject: [PATCH 3/3] Update src/tags_int.cpp Co-authored-by: Christoph Hasse --- src/tags_int.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tags_int.cpp b/src/tags_int.cpp index 923d1151fc..69eed8a1af 100644 --- a/src/tags_int.cpp +++ b/src/tags_int.cpp @@ -2590,7 +2590,7 @@ namespace Exiv2 { // Add 0.5 for rounding. const double x = tmp + 0.5; // Check that x is within the range of a uint32_t before casting. - if (0 <= x && x <= std::numeric_limits::max()) { + if (x <= std::numeric_limits::max()) { ur.second = static_cast(x); } }