Merge pull request #1955 from kevinbackhouse/FixIssue1954

Fix integer overflow in leap year calculation
main
Kevin Backhouse 4 years ago committed by GitHub
commit d23ef9d6cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1 @@
<x:xmpmeta xmlns:x=" "><rdf:RDF xmlns:rdf=" "><rdf:Description xmlns:xmp="x"><xmp:CreateDate>-9223372036854775807-3</xmp:CreateDate></rdf:Description></rdf:RDF></x:xmpmeta>

@ -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]

@ -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.

Loading…
Cancel
Save