-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix GH-13094: range(9.9, '0') causes segmentation fault #13105
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
Conversation
`start_type + end_type < 2*IS_STRING` is not right, in this test case the types are start_type==5 (IS_DOUBLE), end_type==7 (IS_ARRAY). The IS_ARRAY type is a sentinel to disambiguate single-byte strings. The path must be taken when one of the types is not a string nor a single-byte string. Therefore, use < IS_STRING with an OR condition.
@@ -2924,8 +2924,8 @@ PHP_FUNCTION(range) | |||
|
|||
/* If the range is given as strings, generate an array of characters. */ | |||
if (start_type >= IS_STRING || end_type >= IS_STRING) { | |||
/* If one of the inputs is NOT a string */ | |||
if (UNEXPECTED(start_type + end_type < 2*IS_STRING)) { | |||
/* If one of the inputs is NOT a string nor single-byte string */ |
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.
Gina, please double-check my edit to this comment :-)
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 took a hot minute, but I think this is correct, yes.
As the initial logic was that one of the inputs is a valid string (be single byte or not) and the other one is either an int or float. Thus it "wouldn't" be more than 2*IS_STRING
in my head.
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.
Don't know why I didn't do this in the first place. Was probably trying to be smart.
@@ -2924,8 +2924,8 @@ PHP_FUNCTION(range) | |||
|
|||
/* If the range is given as strings, generate an array of characters. */ | |||
if (start_type >= IS_STRING || end_type >= IS_STRING) { | |||
/* If one of the inputs is NOT a string */ | |||
if (UNEXPECTED(start_type + end_type < 2*IS_STRING)) { | |||
/* If one of the inputs is NOT a string nor single-byte string */ |
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 took a hot minute, but I think this is correct, yes.
As the initial logic was that one of the inputs is a valid string (be single byte or not) and the other one is either an int or float. Thus it "wouldn't" be more than 2*IS_STRING
in my head.
start_type + end_type < 2*IS_STRING
is not right, in this test case the types are start_type==5 (IS_DOUBLE), end_type==7 (IS_ARRAY). The IS_ARRAY type is a sentinel to disambiguate single-byte strings. The path must be taken when one of the types is not a string nor a single-byte string. Therefore, use < IS_STRING with an OR condition.