Skip to content

Commit

Permalink
Merge pull request #1923 from Exiv2/mergify/bp/0.27-maintenance/pr-1902
Browse files Browse the repository at this point in the history
Comment out bogus code in XMPUtils.cpp (backport #1902)
  • Loading branch information
kevinbackhouse authored Sep 29, 2021
2 parents b669a9d + 0425eac commit 676d959
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 64 deletions.
124 changes: 62 additions & 62 deletions src/convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,68 @@ namespace Exiv2 {
XMP_DateTime datetime;
try {
SXMPUtils::ConvertToDate(value, &datetime);
char buf[30];
if (std::string(to) != "Exif.GPSInfo.GPSTimeStamp") {

SXMPUtils::ConvertToLocalTime(&datetime);

snprintf(buf, sizeof(buf), "%4d:%02d:%02d %02d:%02d:%02d",
static_cast<int>(datetime.year),
static_cast<int>(datetime.month),
static_cast<int>(datetime.day),
static_cast<int>(datetime.hour),
static_cast<int>(datetime.minute),
static_cast<int>(datetime.second));
buf[sizeof(buf) - 1] = 0;
(*exifData_)[to] = buf;

if (datetime.nanoSecond) {
const char* subsecTag = 0;
if (std::string(to) == "Exif.Image.DateTime") {
subsecTag = "Exif.Photo.SubSecTime";
}
else if (std::string(to) == "Exif.Photo.DateTimeOriginal") {
subsecTag = "Exif.Photo.SubSecTimeOriginal";
}
else if (std::string(to) == "Exif.Photo.DateTimeDigitized") {
subsecTag = "Exif.Photo.SubSecTimeDigitized";
}
if (subsecTag) {
prepareExifTarget(subsecTag, true);
(*exifData_)[subsecTag] = toString(datetime.nanoSecond);
}
}
}
else { // "Exif.GPSInfo.GPSTimeStamp"

// Ignore the time zone, assuming the time is in UTC as it should be

URational rhour(datetime.hour, 1);
URational rmin(datetime.minute, 1);
URational rsec(datetime.second, 1);
if (datetime.nanoSecond != 0) {
if (datetime.second != 0) {
// Add the seconds to rmin so that the ns fit into rsec
rmin.second = 60;
rmin.first *= 60;
rmin.first += datetime.second;
}
rsec.second = 1000000000;
rsec.first = datetime.nanoSecond;
}

std::ostringstream array;
array << rhour << " " << rmin << " " << rsec;
(*exifData_)[to] = array.str();

prepareExifTarget("Exif.GPSInfo.GPSDateStamp", true);
snprintf(buf, sizeof(buf), "%4d:%02d:%02d",
static_cast<int>(datetime.year),
static_cast<int>(datetime.month),
static_cast<int>(datetime.day));
buf[sizeof(buf) - 1] = 0;
(*exifData_)["Exif.GPSInfo.GPSDateStamp"] = buf;
}
}
#ifndef SUPPRESS_WARNINGS
catch (const XMP_Error& e) {
Expand All @@ -866,68 +928,6 @@ namespace Exiv2 {
return;
}
#endif // SUPPRESS_WARNINGS
char buf[30];
if (std::string(to) != "Exif.GPSInfo.GPSTimeStamp") {

SXMPUtils::ConvertToLocalTime(&datetime);

snprintf(buf, sizeof(buf), "%4d:%02d:%02d %02d:%02d:%02d",
static_cast<int>(datetime.year),
static_cast<int>(datetime.month),
static_cast<int>(datetime.day),
static_cast<int>(datetime.hour),
static_cast<int>(datetime.minute),
static_cast<int>(datetime.second));
buf[sizeof(buf) - 1] = 0;
(*exifData_)[to] = buf;

if (datetime.nanoSecond) {
const char* subsecTag = 0;
if (std::string(to) == "Exif.Image.DateTime") {
subsecTag = "Exif.Photo.SubSecTime";
}
else if (std::string(to) == "Exif.Photo.DateTimeOriginal") {
subsecTag = "Exif.Photo.SubSecTimeOriginal";
}
else if (std::string(to) == "Exif.Photo.DateTimeDigitized") {
subsecTag = "Exif.Photo.SubSecTimeDigitized";
}
if (subsecTag) {
prepareExifTarget(subsecTag, true);
(*exifData_)[subsecTag] = toString(datetime.nanoSecond);
}
}
}
else { // "Exif.GPSInfo.GPSTimeStamp"

// Ignore the time zone, assuming the time is in UTC as it should be

URational rhour(datetime.hour, 1);
URational rmin(datetime.minute, 1);
URational rsec(datetime.second, 1);
if (datetime.nanoSecond != 0) {
if (datetime.second != 0) {
// Add the seconds to rmin so that the ns fit into rsec
rmin.second = 60;
rmin.first *= 60;
rmin.first += datetime.second;
}
rsec.second = 1000000000;
rsec.first = datetime.nanoSecond;
}

std::ostringstream array;
array << rhour << " " << rmin << " " << rsec;
(*exifData_)[to] = array.str();

prepareExifTarget("Exif.GPSInfo.GPSDateStamp", true);
snprintf(buf, sizeof(buf), "%4d:%02d:%02d",
static_cast<int>(datetime.year),
static_cast<int>(datetime.month),
static_cast<int>(datetime.day));
buf[sizeof(buf) - 1] = 0;
(*exifData_)["Exif.GPSInfo.GPSDateStamp"] = buf;
}

if (erase_) xmpData_->erase(pos);
#else
Expand Down
1 change: 1 addition & 0 deletions test/data/issue_1901_poc1.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="a"><xmp:CreateDate>-9223372036854775807</xmp:CreateDate></rdf:Description></rdf:RDF></x:xmpmeta>
1 change: 1 addition & 0 deletions test/data/issue_1901_poc2.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="a"><xmp:CreateDate>-9223372034707290000</xmp:CreateDate></rdf:Description></rdf:RDF></x:xmpmeta>
1 change: 1 addition & 0 deletions test/data/issue_1901_poc3.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="a"><xmp:CreateDate>2147483650</xmp:CreateDate></rdf:Description></rdf:RDF></x:xmpmeta>
1 change: 1 addition & 0 deletions test/data/issue_1901_poc4.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="a"><xmp:CreateDate>2021</xmp:CreateDate></rdf:Description></rdf:RDF></x:xmpmeta>
29 changes: 29 additions & 0 deletions tests/bugfixes/github/test_issue_1901.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-

from system_tests import CaseMeta, path, check_no_ASAN_UBSAN_errors

class XMPUtilsSetTimeZoneIntegerOverflow(metaclass=CaseMeta):
"""
Regression test for the bug described in:
https://github.com/Exiv2/exiv2/issues/1901
"""
url = "https://github.com/Exiv2/exiv2/issues/1901"

filename1 = path("$data_path/issue_1901_poc1.xmp")
filename2 = path("$data_path/issue_1901_poc2.xmp")
filename3 = path("$data_path/issue_1901_poc3.xmp")
filename4 = path("$data_path/issue_1901_poc4.xmp")
commands = ["$exiv2 -q $filename1",
"$exiv2 -q $filename2",
"$exiv2 -q $filename3",
"$exiv2 -q $filename4"]
stderr = ["""$filename1: No Exif data found in the file
""",
"""$filename2: No Exif data found in the file
""",
"""$filename3: No Exif data found in the file
""",
""]
retval = [253, 253, 253, 0]

compare_stdout = check_no_ASAN_UBSAN_errors
9 changes: 7 additions & 2 deletions xmpsdk/src/XMPUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1960,8 +1960,13 @@ XMPUtils::SetTimeZone ( XMP_DateTime * xmpTime )
if ( now == -1 ) XMP_Throw ( "Failure from ANSI C time function", kXMPErr_ExternalFailure );
ansi_localtime ( &now, &tmLocal );
} else {
tmLocal.tm_year = xmpTime->year - 1900;
while ( tmLocal.tm_year < 70 ) tmLocal.tm_year += 4; // ! Some versions of mktime barf on years before 1970.
if (xmpTime->year < std::numeric_limits<int>::min() + 1900) {
XMP_Throw ( "Invalid year", kXMPErr_BadParam);
} else if (xmpTime->year > std::numeric_limits<int>::max()) {
XMP_Throw ( "Invalid year", kXMPErr_BadParam);
} else {
tmLocal.tm_year = xmpTime->year - 1900;
}
tmLocal.tm_mon = xmpTime->month - 1;
tmLocal.tm_mday = xmpTime->day;
}
Expand Down

0 comments on commit 676d959

Please sign in to comment.