Throw an exception on integer overflow.

main
Kevin Backhouse 4 years ago
parent 395389aa15
commit bb9ff53ebe
No known key found for this signature in database
GPG Key ID: 9DD01852EE40366E

@ -859,17 +859,6 @@ namespace Exiv2 {
XMP_DateTime datetime;
try {
SXMPUtils::ConvertToDate(value, &datetime);
}
#ifndef SUPPRESS_WARNINGS
catch (const XMP_Error& e) {
EXV_WARNING << "Failed to convert " << from << " to " << to << " (" << e.GetErrMsg() << ")\n";
return;
}
#else
catch (const XMP_Error&) {
return;
}
#endif // SUPPRESS_WARNINGS
char buf[30];
if (std::string(to) != "Exif.GPSInfo.GPSTimeStamp") {
@ -932,6 +921,17 @@ namespace Exiv2 {
buf[sizeof(buf) - 1] = 0;
(*exifData_)["Exif.GPSInfo.GPSDateStamp"] = buf;
}
}
#ifndef SUPPRESS_WARNINGS
catch (const XMP_Error& e) {
EXV_WARNING << "Failed to convert " << from << " to " << to << " (" << e.GetErrMsg() << ")\n";
return;
}
#else
catch (const XMP_Error&) {
return;
}
#endif // SUPPRESS_WARNINGS
if (erase_) xmpData_->erase(pos);
#else

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
from system_tests import CaseMeta, path
from system_tests import CaseMeta, path, check_no_ASAN_UBSAN_errors
class XMPUtilsSetTimeZoneIntegerOverflow(metaclass=CaseMeta):
"""
@ -17,109 +17,13 @@ class XMPUtilsSetTimeZoneIntegerOverflow(metaclass=CaseMeta):
"$exiv2 -q $filename2",
"$exiv2 -q $filename3",
"$exiv2 -q $filename4"]
stderr = ["", "", "", ""]
stdout = ["""File name : $filename1
File size : 170 Bytes
MIME type : application/rdf+xml
Image size : 0 x 0
Thumbnail : None
Camera make :
Camera model :
Image timestamp :
File number :
Exposure time :
Aperture :
Exposure bias :
Flash :
Flash bias :
Focal length :
Subject distance:
ISO speed :
Exposure mode :
Metering mode :
Macro mode :
Image quality :
White balance :
Copyright :
Exif comment :
stderr = ["""$filename1: No Exif data found in the file
""",
"""File name : $filename2
File size : 170 Bytes
MIME type : application/rdf+xml
Image size : 0 x 0
Thumbnail : None
Camera make :
Camera model :
Image timestamp :
File number :
Exposure time :
Aperture :
Exposure bias :
Flash :
Flash bias :
Focal length :
Subject distance:
ISO speed :
Exposure mode :
Metering mode :
Macro mode :
Image quality :
White balance :
Copyright :
Exif comment :
"""$filename2: No Exif data found in the file
""",
"""File name : $filename3
File size : 160 Bytes
MIME type : application/rdf+xml
Image size : 0 x 0
Thumbnail : None
Camera make :
Camera model :
Image timestamp :
File number :
Exposure time :
Aperture :
Exposure bias :
Flash :
Flash bias :
Focal length :
Subject distance:
ISO speed :
Exposure mode :
Metering mode :
Macro mode :
Image quality :
White balance :
Copyright :
Exif comment :
"""$filename3: No Exif data found in the file
""",
"""File name : $filename4
File size : 154 Bytes
MIME type : application/rdf+xml
Image size : 0 x 0
Thumbnail : None
Camera make :
Camera model :
Image timestamp :
File number :
Exposure time :
Aperture :
Exposure bias :
Flash :
Flash bias :
Focal length :
Subject distance:
ISO speed :
Exposure mode :
Metering mode :
Macro mode :
Image quality :
White balance :
Copyright :
Exif comment :
""]
retval = [253, 253, 253, 0]
"""]
retval = [0, 0, 0, 0]
compare_stdout = check_no_ASAN_UBSAN_errors

@ -1960,11 +1960,10 @@ XMPUtils::SetTimeZone ( XMP_DateTime * xmpTime )
if ( now == -1 ) XMP_Throw ( "Failure from ANSI C time function", kXMPErr_ExternalFailure );
ansi_localtime ( &now, &tmLocal );
} else {
// Fix for https://github.com/Exiv2/exiv2/issues/1901
if (xmpTime->year < std::numeric_limits<decltype(tmLocal.tm_year)>::min() + 1900) {
tmLocal.tm_year = std::numeric_limits<decltype(tmLocal.tm_year)>::min();
XMP_Throw ( "Invalid year", kXMPErr_BadParam);
} else if (xmpTime->year > std::numeric_limits<decltype(tmLocal.tm_year)>::max()) {
tmLocal.tm_year = std::numeric_limits<decltype(tmLocal.tm_year)>::max();
XMP_Throw ( "Invalid year", kXMPErr_BadParam);
} else {
tmLocal.tm_year = xmpTime->year - 1900;
}

Loading…
Cancel
Save