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
Closed
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
4 changes: 2 additions & 2 deletions ext/standard/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.

if (UNEXPECTED(start_type < IS_STRING || end_type < IS_STRING)) {
if (start_type < IS_STRING) {
if (end_type != IS_ARRAY) {
php_error_docref(NULL, E_WARNING, "Argument #1 ($start) must be a single byte string if"
Expand Down
29 changes: 29 additions & 0 deletions ext/standard/tests/array/gh13094.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
--TEST--
GH-13094 (range(9.9, '0') causes segmentation fault)
--FILE--
<?php
var_dump(range(9.9, '0'));
?>
--EXPECT--
array(10) {
[0]=>
float(9.9)
[1]=>
float(8.9)
[2]=>
float(7.9)
[3]=>
float(6.9)
[4]=>
float(5.9)
[5]=>
float(4.9)
[6]=>
float(3.9000000000000004)
[7]=>
float(2.9000000000000004)
[8]=>
float(1.9000000000000004)
[9]=>
float(0.9000000000000004)
}