-
Notifications
You must be signed in to change notification settings - Fork 7.8k
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
Fixed int32 underflow on DateTime::createFromTimestamp #12775
Conversation
9c07b42
to
548fe60
Compare
|
2f57d4e
to
491db8b
Compare
Ping @derickr |
The ASAN tests still seem to fail... I did try restarting it, but it's the same result. They need to get fixed before we can merge this. |
…F_ZEND_LONG/ZEND_DOUBLE_FITS_LONG
491db8b
to
26d3153
Compare
@derickr it's fixed now. I have rebased against master and for some reason I was using SIZEOF_TIMELIB_LONG which doesn't exist. About TIMELIB_LONG vs. ZEND_LONG can this ever differ? I have seen some logic to force 32bit in it or would it be better to simply fail compile if zend long != timelib long? |
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 LGTM, but I would want to have a second opinion. @iluuu1994 @kocsismate ?
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.
The code itself looks good to me. Thanks @marc-mabe!
ext/date/php_date.c
Outdated
"Seconds must be a finite number between " TIMELIB_LONG_FMT " and " TIMELIB_LONG_FMT ", %g given", | ||
TIMELIB_LONG_MIN, | ||
TIMELIB_LONG_MAX, | ||
sec_dval |
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.
Not printing usec would be confusing here.
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.
Mh to be precise the timestamp must be between TIMELIB_LONG_MIN.0 and TIMELIB_LONG_MAX.999999.
Should this be included in the message as well as currently it's about the seconds part only.
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 have updated the message to Timestamp must be a finite number between {TIMELIB_LONG_MIN} and {TIMELIB_LONG_MAX}.999999, {ARGUMENT} given
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.
LGTM! @derickr Please merge if you are happy too.
ext/date/php_date.c
Outdated
zend_throw_error( | ||
date_ce_date_range_error, | ||
"Seconds must be a finite number between " TIMELIB_LONG_FMT " and " TIMELIB_LONG_FMT ", %g given", | ||
"Timestamp must be a finite number between " TIMELIB_LONG_FMT " and " TIMELIB_LONG_FMT ".999999, %g given", |
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:
Argument #1 ($timestamp) must be a finite number between ...
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
@derickr @iluuu1994 can this PR be merged now? |
This fixes an integer underflow on passing
PHP_INT_MIN - 0.X
toDateTime[Immutable]::createFromTimestamp()
.This is due to the fact that the fractional part is handled separately ...
PS:
PHP_INT_MAX + 0.X
does not have this issueSimilar to
ZEND_DOUBLE_FITS_LONG
this is introducingPHP_DATE_DOUBLE_FITS_LONG
based onTIMELIB_LONG_MIN/MAX
/cc @iluuu1994 @derickr