From 21a82e1c55af62333463c5e3bfcb502491de03b5 Mon Sep 17 00:00:00 2001 From: Jim Easterbrook Date: Wed, 4 Dec 2024 13:22:08 +0000 Subject: [PATCH 1/2] DateValue::toRational returns zero if out of range The "seconds since UNIX epoch" overflows a Rational (int32) in 2038. See https://github.com/Exiv2/exiv2/issues/3080 for background. (cherry picked from commit 308e219f641112f645c54b2fee7f22048ed5bd0d) --- src/value.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/value.cpp b/src/value.cpp index 1cbb78e581..2070b4c38e 100644 --- a/src/value.cpp +++ b/src/value.cpp @@ -873,7 +873,11 @@ float DateValue::toFloat(size_t n) const { } Rational DateValue::toRational(size_t n) const { - return {static_cast(toInt64(n)), 1}; + const int64_t t = toInt64(n); + if (t < std::numeric_limits::min() || t > std::numeric_limits::max()) { + return {0, 1}; + } + return {static_cast(t), 1}; } TimeValue::TimeValue() : Value(time) { From 9b7f7e0f2b48bed91fc3be539bb6f8efd77b37de Mon Sep 17 00:00:00 2001 From: Jim Easterbrook Date: Wed, 4 Dec 2024 14:40:45 +0000 Subject: [PATCH 2/2] Set 'ok_' to false if timestamp overflow error This is the correct way to indicate that the value conversion failed. (cherry picked from commit c7a0b78357c62ffb5178efdeed53b51c4800b082) --- src/value.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/value.cpp b/src/value.cpp index 2070b4c38e..c9d031e9b9 100644 --- a/src/value.cpp +++ b/src/value.cpp @@ -863,6 +863,7 @@ int64_t DateValue::toInt64(size_t /*n*/) const { uint32_t DateValue::toUint32(size_t /*n*/) const { const int64_t t = toInt64(); if (t < 0 || t > std::numeric_limits::max()) { + ok_ = false; return 0; } return static_cast(t); @@ -875,6 +876,7 @@ float DateValue::toFloat(size_t n) const { Rational DateValue::toRational(size_t n) const { const int64_t t = toInt64(n); if (t < std::numeric_limits::min() || t > std::numeric_limits::max()) { + ok_ = false; return {0, 1}; } return {static_cast(t), 1};