Skip to content

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

Closed
wants to merge 2 commits into from

Conversation

nielsdos
Copy link
Member

@nielsdos nielsdos commented Jan 9, 2024

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.

`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.
@nielsdos nielsdos requested a review from Girgias January 9, 2024 19:15
@nielsdos nielsdos requested a review from bukka as a code owner January 9, 2024 19:15
@nielsdos nielsdos linked an issue Jan 9, 2024 that may be closed by this pull request
@@ -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 */
Copy link
Member Author

@nielsdos nielsdos Jan 9, 2024

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 :-)

Copy link
Member

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.

Copy link
Member

@Girgias Girgias left a 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 */
Copy link
Member

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.

@nielsdos nielsdos closed this in 1d6f344 Jan 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

range(9.9, '0') causes segmentation fault
2 participants