Merge pull request #1914 from sgoranov/fix/1913-datetime-overflow

Fix DateTimeHelper::ParseRFC2822DateString integer overflow on 32-bit PHP
This commit is contained in:
Maarten 2025-06-16 17:30:55 +02:00 committed by GitHub
commit 24bb509b96
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -54,11 +54,22 @@ abstract class DateTimeHelper
\DateTime::createFromFormat('d M Y H:i:s O', $sDateTime, static::GetUtcTimeZoneObject())
// Using T (obsolete timezone abbreviation)
?: \DateTime::createFromFormat('d M Y H:i:s T', $sDateTime, static::GetUtcTimeZoneObject());
// 398045302 is 1982-08-13 00:08:22 the date RFC 822 was created
if (!$oDateTime || 398045302 > $oDateTime->getTimestamp()) {
try {
$timestamp = $oDateTime->getTimestamp();
// 398045302 is 1982-08-13 00:08:22, the date RFC 822 was created
if (398045302 > $timestamp) {
\SnappyMail\Log::notice('', "Failed to parse RFC 2822 date '{$sDateTime}'");
return 0;
}
return $timestamp;
} catch (\Error $error) {
// Catch integer overflow or other fatal errors
\SnappyMail\Log::notice('', "Failed to parse RFC 2822 date '{$sDateTime}'");
return 0;
}
return $oDateTime ? $oDateTime->getTimestamp() : 0;
}
/**