Skip to content

Commit 1d6f344

Browse files
committed
Fix GH-13094: range(9.9, '0') causes segmentation fault
`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. Closes GH-13105.
1 parent 71a1def commit 1d6f344

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@ PHP NEWS
44

55
- Core:
66
. Fixed timer leak in zend-max-execution-timers builds. (withinboredom)
7+
78
- Phar:
89
. Fixed bug #71465 (PHAR doesn't know about litespeed). (nielsdos)
910

11+
- Standard:
12+
. Fixed bug GH-13094 (range(9.9, '0') causes segmentation fault). (nielsdos)
13+
1014
18 Jan 2024, PHP 8.3.2
1115

1216
- Core:

ext/standard/array.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2924,8 +2924,8 @@ PHP_FUNCTION(range)
29242924

29252925
/* If the range is given as strings, generate an array of characters. */
29262926
if (start_type >= IS_STRING || end_type >= IS_STRING) {
2927-
/* If one of the inputs is NOT a string */
2928-
if (UNEXPECTED(start_type + end_type < 2*IS_STRING)) {
2927+
/* If one of the inputs is NOT a string nor single-byte string */
2928+
if (UNEXPECTED(start_type < IS_STRING || end_type < IS_STRING)) {
29292929
if (start_type < IS_STRING) {
29302930
if (end_type != IS_ARRAY) {
29312931
php_error_docref(NULL, E_WARNING, "Argument #1 ($start) must be a single byte string if"
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
GH-13094 (range(9.9, '0') causes segmentation fault)
3+
--FILE--
4+
<?php
5+
var_dump(range(9.9, '0'));
6+
?>
7+
--EXPECT--
8+
array(10) {
9+
[0]=>
10+
float(9.9)
11+
[1]=>
12+
float(8.9)
13+
[2]=>
14+
float(7.9)
15+
[3]=>
16+
float(6.9)
17+
[4]=>
18+
float(5.9)
19+
[5]=>
20+
float(4.9)
21+
[6]=>
22+
float(3.9000000000000004)
23+
[7]=>
24+
float(2.9000000000000004)
25+
[8]=>
26+
float(1.9000000000000004)
27+
[9]=>
28+
float(0.9000000000000004)
29+
}

0 commit comments

Comments
 (0)