diff --git a/test/data/issue_1954_poc.xmp b/test/data/issue_1954_poc.xmp new file mode 100644 index 0000000000..dbd4619031 --- /dev/null +++ b/test/data/issue_1954_poc.xmp @@ -0,0 +1 @@ +-9223372036854775807-3 \ No newline at end of file diff --git a/tests/bugfixes/github/test_issue_1954.py b/tests/bugfixes/github/test_issue_1954.py new file mode 100644 index 0000000000..53b76f5959 --- /dev/null +++ b/tests/bugfixes/github/test_issue_1954.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- + +from system_tests import CaseMeta, path + +class XMPUtilsLeapYearOverflow(metaclass=CaseMeta): + """ + Regression test for the bug described in: + https://github.com/Exiv2/exiv2/issues/1954 + """ + url = "https://github.com/Exiv2/exiv2/issues/1954" + + filename = path("$data_path/issue_1954_poc.xmp") + commands = ["$exiv2 -q $filename"] + stderr = ["""$filename: No Exif data found in the file +"""] + stdout = ["""File name : $filename +File size : 172 Bytes +MIME type : application/rdf+xml +Image size : 0 x 0 +"""] + retval = [253] diff --git a/xmpsdk/src/XMPUtils.cpp b/xmpsdk/src/XMPUtils.cpp index af41c18791..89afd3d62d 100644 --- a/xmpsdk/src/XMPUtils.cpp +++ b/xmpsdk/src/XMPUtils.cpp @@ -174,8 +174,8 @@ XMP_VarString * sExtendedDigest = 0; static bool IsLeapYear ( long year ) { - - if ( year < 0 ) year = -year + 1; // Fold the negative years, assuming there is a year 0. + // This code uses the Gregorian calendar algorithm: + // https://en.wikipedia.org/wiki/Leap_year#Algorithm if ( (year % 4) != 0 ) return false; // Not a multiple of 4. if ( (year % 100) != 0 ) return true; // A multiple of 4 but not a multiple of 100.