Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix integer overflow in leap year calculation #1955

Merged
merged 2 commits into from
Oct 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions test/data/issue_1954_poc.xmp
Original file line number Diff line number Diff line change
@@ -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>
21 changes: 21 additions & 0 deletions tests/bugfixes/github/test_issue_1954.py
Original file line number Diff line number Diff line change
@@ -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]
4 changes: 2 additions & 2 deletions xmpsdk/src/XMPUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down