-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fixed int32 underflow on DateTime::createFromTimestamp #12775
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
fbb156d
Fixed int32 underflow on DateTime::createFromTimestamp
marc-mabe 26d3153
Added PHP_DATE_SIZEOF_LONG/PHP_DATE_DOUBLE_FITS_LONG similar to SIZEO…
marc-mabe 075f0bd
Addressed PR comments
marc-mabe 42c6b1a
Improve date range error message
marc-mabe cbaadb5
Use zend_argument_error
marc-mabe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
--TEST-- | ||
Tests for DateTime[Immutable]::createFromTimestamp 32bit variant | ||
--SKIPIF-- | ||
<?php | ||
if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only"); | ||
?> | ||
--INI-- | ||
date.timezone=Europe/London | ||
--FILE-- | ||
<?php | ||
|
||
$timestamps = array( | ||
PHP_INT_MAX, | ||
PHP_INT_MIN, | ||
PHP_INT_MAX + 0.5, | ||
PHP_INT_MIN + 0.5, | ||
PHP_INT_MAX - 0.5, | ||
PHP_INT_MIN - 0.5, | ||
PHP_INT_MAX + 1024.0, | ||
PHP_INT_MIN - 1025.0, | ||
); | ||
|
||
foreach ($timestamps as $ts) { | ||
echo 'DateTime::createFromTimestamp(' . var_export($ts, true) . '): '; | ||
try { | ||
var_dump(DateTime::createFromTimestamp($ts)); | ||
} catch (Throwable $e) { | ||
echo get_class($e) . ': ' . $e->getMessage() . "\n"; | ||
} | ||
|
||
echo 'DateTimeImmutable::createFromTimestamp(' . var_export($ts, true) . '): '; | ||
try { | ||
var_dump(DateTimeImmutable::createFromTimestamp($ts)); | ||
} catch (Throwable $e) { | ||
echo get_class($e) . ': ' . $e->getMessage() . "\n"; | ||
} | ||
} | ||
|
||
?> | ||
--EXPECTF-- | ||
DateTime::createFromTimestamp(2147483647): object(DateTime)#%d (3) { | ||
["date"]=> | ||
string(26) "2038-01-19 03:14:07.000000" | ||
["timezone_type"]=> | ||
int(1) | ||
["timezone"]=> | ||
string(6) "+00:00" | ||
} | ||
DateTimeImmutable::createFromTimestamp(2147483647): object(DateTimeImmutable)#%d (3) { | ||
["date"]=> | ||
string(26) "2038-01-19 03:14:07.000000" | ||
["timezone_type"]=> | ||
int(1) | ||
["timezone"]=> | ||
string(6) "+00:00" | ||
} | ||
DateTime::createFromTimestamp(-2147483647-1): object(DateTime)#%d (3) { | ||
["date"]=> | ||
string(26) "1901-12-13 20:45:52.000000" | ||
["timezone_type"]=> | ||
int(1) | ||
["timezone"]=> | ||
string(6) "+00:00" | ||
} | ||
DateTimeImmutable::createFromTimestamp(-2147483647-1): object(DateTimeImmutable)#%d (3) { | ||
["date"]=> | ||
string(26) "1901-12-13 20:45:52.000000" | ||
["timezone_type"]=> | ||
int(1) | ||
["timezone"]=> | ||
string(6) "+00:00" | ||
} | ||
DateTime::createFromTimestamp(2147483647.5): object(DateTime)#%d (3) { | ||
["date"]=> | ||
string(26) "2038-01-19 03:14:07.500000" | ||
["timezone_type"]=> | ||
int(1) | ||
["timezone"]=> | ||
string(6) "+00:00" | ||
} | ||
DateTimeImmutable::createFromTimestamp(2147483647.5): object(DateTimeImmutable)#%d (3) { | ||
["date"]=> | ||
string(26) "2038-01-19 03:14:07.500000" | ||
["timezone_type"]=> | ||
int(1) | ||
["timezone"]=> | ||
string(6) "+00:00" | ||
} | ||
DateTime::createFromTimestamp(-2147483647.5): object(DateTime)#%d (3) { | ||
["date"]=> | ||
string(26) "1901-12-13 20:45:52.500000" | ||
["timezone_type"]=> | ||
int(1) | ||
["timezone"]=> | ||
string(6) "+00:00" | ||
} | ||
DateTimeImmutable::createFromTimestamp(-2147483647.5): object(DateTimeImmutable)#%d (3) { | ||
["date"]=> | ||
string(26) "1901-12-13 20:45:52.500000" | ||
["timezone_type"]=> | ||
int(1) | ||
["timezone"]=> | ||
string(6) "+00:00" | ||
} | ||
DateTime::createFromTimestamp(2147483646.5): object(DateTime)#%d (3) { | ||
["date"]=> | ||
string(26) "2038-01-19 03:14:06.500000" | ||
["timezone_type"]=> | ||
int(1) | ||
["timezone"]=> | ||
string(6) "+00:00" | ||
} | ||
DateTimeImmutable::createFromTimestamp(2147483646.5): object(DateTimeImmutable)#%d (3) { | ||
["date"]=> | ||
string(26) "2038-01-19 03:14:06.500000" | ||
["timezone_type"]=> | ||
int(1) | ||
["timezone"]=> | ||
string(6) "+00:00" | ||
} | ||
DateTime::createFromTimestamp(-2147483648.5): DateRangeError: Timestamp must be a finite number between -2147483648 and 2147483647.999999, -2.14748e+9 given | ||
DateTimeImmutable::createFromTimestamp(-2147483648.5): DateRangeError: Timestamp must be a finite number between -2147483648 and 2147483647.999999, -2.14748e+9 given | ||
DateTime::createFromTimestamp(2147484671.0): DateRangeError: Timestamp must be a finite number between -2147483648 and 2147483647.999999, 2.14748e+9 given | ||
DateTimeImmutable::createFromTimestamp(2147484671.0): DateRangeError: Timestamp must be a finite number between -2147483648 and 2147483647.999999, 2.14748e+9 given | ||
DateTime::createFromTimestamp(-2147484673.0): DateRangeError: Timestamp must be a finite number between -2147483648 and 2147483647.999999, -2.14748e+9 given | ||
DateTimeImmutable::createFromTimestamp(-2147484673.0): DateRangeError: Timestamp must be a finite number between -2147483648 and 2147483647.999999, -2.14748e+9 given |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably use our default
zend_argument_error
format:Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought it's better matching the DateRangeError event though the documentation needs to be updated. https://www.php.net/manual/en/class.daterangeerror.php
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I got it. This makes sense 👍
-> Updated the PR accordingly