Skip to content
Open
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
7 changes: 6 additions & 1 deletion ext/date/lib/interval.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,12 @@ int timelib_diff_days(timelib_time *one, timelib_time *two)
days--;
}
} else {
days = fabs(floor(one->sse - two->sse) / 86400);
double diff = fabs(floor(one->sse - two->sse) / 86400);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that I'm not so sure silently capping the number is the right way to go about this.
This is also a bundled library, the fix should go into the upstream library at https://github.com/derickr/timelib

if (diff > INT_MAX) {
days = INT_MAX;
} else {
days = (int) diff;
}
}

return days;
Expand Down
14 changes: 14 additions & 0 deletions ext/date/tests/bug19894.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
DateTime::diff() with PHP_INT_MIN timestamp and timezone should not crash
--FILE--
<?php
$nowTime = new DateTime();
$nowTime->setTimestamp(PHP_INT_MIN);

$dateTime = new DateTime();
$dateTime->setTimezone(new DateTimeZone('America/New_York'));

echo $dateTime->diff($nowTime)->format('%R %a %H %I %S'), "\n";
?>
--EXPECTREGEX--
^[+-] [0-9]+ [0-9]+ [0-9]+ [0-9]+$
Loading