Skip to content

Commit

Permalink
Fix possible performance issue when parsing malformed and long Date h…
Browse files Browse the repository at this point in the history
…eader (#6087)
  • Loading branch information
alecpl committed Dec 12, 2017
1 parent d132702 commit 472e48f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CHANGELOG Roundcube Webmail
- Fix untagged COPYUID responses handling - again (#5982)
- Fix PHP warning "idn_to_utf8(): INTL_IDNA_VARIANT_2003 is deprecated" with PHP 7.2 (#6075)
- Fix bug where Archive folder wasn't auto-created on login with create_default_folders=true
- Fix performance issue when parsing malformed and long Date header (#6087)

RELEASE 1.3.3
-------------
Expand Down
14 changes: 9 additions & 5 deletions program/lib/Roundcube/rcube_utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -714,15 +714,19 @@ public static function strtotime($date, $timezone = null)
return (int) $date;
}

// It can be very slow when provided string is not a date and very long
if (strlen($date) > 128) {
$date = substr($date, 0, 128);
}

// if date parsing fails, we have a date in non-rfc format.
// remove token from the end and try again
while ((($ts = @strtotime($date . $tzname)) === false) || ($ts < 0)) {
$d = explode(' ', $date);
array_pop($d);
if (!$d) {
while (($ts = @strtotime($date . $tzname)) === false || $ts < 0) {
if (($pos = strrpos($date, ' ')) === false) {
break;
}
$date = implode(' ', $d);

$date = rtrim(substr($date, 0, $pos));
}

return (int) $ts;
Expand Down

0 comments on commit 472e48f

Please sign in to comment.