Skip to content

Commit d00adca

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3: datefmt_parse/datefmt_localtime references type system fixes Fix GH-18438: Handling of empty data and errors in ZipArchive::addPattern
2 parents 5b8db66 + 2beec54 commit d00adca

File tree

5 files changed

+106
-10
lines changed

5 files changed

+106
-10
lines changed

NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ PHP NEWS
77
inaccurate sunrise and sunset times, but other calculated times are
88
correct) (JiriJozif).
99

10+
- Intl:
11+
. datefmt_parse/datefmt_localtime references type system fixes. (nielsdos)
12+
1013
- SPL:
1114
. Fixed bug GH-18421 (Integer overflow with large numbers in LimitIterator).
1215
(nielsdos)
@@ -18,6 +21,8 @@ PHP NEWS
1821
- Zip:
1922
. Fixed bug GH-18431 (Registering ZIP progress callback twice doesn't work).
2023
(nielsdos)
24+
. Fixed bug GH-18438 (Handling of empty data and errors in
25+
ZipArchive::addPattern). (nielsdos)
2126

2227
24 Apr 2025, PHP 8.4.7
2328

ext/intl/dateformat/dateformat_parse.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ PHP_FUNCTION(datefmt_parse)
145145
DATE_FORMAT_METHOD_FETCH_OBJECT;
146146

147147
if (z_parse_pos) {
148-
zend_long long_parse_pos;
149-
ZVAL_DEREF(z_parse_pos);
150-
long_parse_pos = zval_get_long(z_parse_pos);
148+
zval *z_parse_pos_tmp = z_parse_pos;
149+
ZVAL_DEREF(z_parse_pos_tmp);
150+
zend_long long_parse_pos = zval_get_long(z_parse_pos_tmp);
151151
if (ZEND_LONG_INT_OVFL(long_parse_pos)) {
152152
intl_error_set_code(NULL, U_ILLEGAL_ARGUMENT_ERROR);
153153
intl_error_set_custom_msg(NULL, "String index is out of valid range.", 0);
@@ -160,8 +160,7 @@ PHP_FUNCTION(datefmt_parse)
160160
}
161161
internal_parse_to_timestamp( dfo, text_to_parse, text_len, z_parse_pos ? &parse_pos : NULL, false, return_value);
162162
if (z_parse_pos) {
163-
zval_ptr_dtor(z_parse_pos);
164-
ZVAL_LONG(z_parse_pos, parse_pos);
163+
ZEND_TRY_ASSIGN_REF_LONG(z_parse_pos, parse_pos);
165164
}
166165
}
167166
/* }}} */
@@ -231,9 +230,9 @@ PHP_FUNCTION(datefmt_localtime)
231230
DATE_FORMAT_METHOD_FETCH_OBJECT;
232231

233232
if (z_parse_pos) {
234-
zend_long long_parse_pos;
235-
ZVAL_DEREF(z_parse_pos);
236-
long_parse_pos = zval_get_long(z_parse_pos);
233+
zval *z_parse_pos_tmp = z_parse_pos;
234+
ZVAL_DEREF(z_parse_pos_tmp);
235+
zend_long long_parse_pos = zval_get_long(z_parse_pos_tmp);
237236
if (ZEND_LONG_INT_OVFL(long_parse_pos)) {
238237
intl_error_set_code(NULL, U_ILLEGAL_ARGUMENT_ERROR);
239238
intl_error_set_custom_msg(NULL, "String index is out of valid range.", 0);
@@ -246,8 +245,7 @@ PHP_FUNCTION(datefmt_localtime)
246245
}
247246
internal_parse_to_localtime( dfo, text_to_parse, text_len, z_parse_pos?&parse_pos:NULL, return_value);
248247
if (z_parse_pos) {
249-
zval_ptr_dtor(z_parse_pos);
250-
ZVAL_LONG(z_parse_pos, parse_pos);
248+
ZEND_TRY_ASSIGN_REF_LONG(z_parse_pos, parse_pos);
251249
}
252250
}
253251
/* }}} */
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
--TEST--
2+
datefmt_parse/datefmt_localtime references type system
3+
--EXTENSIONS--
4+
intl
5+
--FILE--
6+
<?php
7+
8+
class Test {
9+
public float $prop = 1.0;
10+
}
11+
12+
$test = new Test;
13+
$offset1 =& $test->prop;
14+
$offset2 =& $test->prop;
15+
16+
$fmt = datefmt_create(
17+
'en_US',
18+
IntlDateFormatter::FULL,
19+
IntlDateFormatter::FULL,
20+
'America/Los_Angeles',
21+
IntlDateFormatter::GREGORIAN
22+
);
23+
datefmt_localtime($fmt, 'Wednesday, December 31, 1969 4:00:00 PM PT', $offset1);
24+
datefmt_parse($fmt, 'Wednesday, December 31, 1969 4:00:00 PM PT', $offset2);
25+
var_dump($offset1, $offset2);
26+
var_dump($test);
27+
28+
?>
29+
--EXPECT--
30+
float(1)
31+
float(1)
32+
object(Test)#1 (1) {
33+
["prop"]=>
34+
&float(1)
35+
}

ext/zip/php_zip.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,10 @@ int php_zip_pcre(zend_string *regexp, char *path, int path_len, zval *return_val
760760

761761
re = pcre_get_compiled_regex(regexp, &capture_count);
762762
if (!re) {
763+
for (i = 0; i < files_cnt; i++) {
764+
zend_string_release_ex(namelist[i], 0);
765+
}
766+
efree(namelist);
763767
php_error_docref(NULL, E_WARNING, "Invalid expression");
764768
return -1;
765769
}
@@ -1843,6 +1847,10 @@ static void php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAMETERS, int type) /*
18431847
#endif
18441848
}
18451849
}
1850+
} else if (found == 0) {
1851+
RETURN_EMPTY_ARRAY();
1852+
} else {
1853+
RETURN_FALSE;
18461854
}
18471855
}
18481856
/* }}} */

ext/zip/tests/gh18438.phpt

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
--TEST--
2+
GH-18438 (Handling of empty data and errors in ZipArchive::addPattern)
3+
--EXTENSIONS--
4+
zip
5+
--SKIPIF--
6+
<?php
7+
if (PHP_ZTS) die("skip not for ZTS because of path prefixing breaking custom wrapper test");
8+
?>
9+
--FILE--
10+
<?php
11+
class CustomStreamWrapper {
12+
public $context;
13+
function dir_closedir(): bool {
14+
return true;
15+
}
16+
function dir_opendir(string $path, int $options): bool {
17+
return true;
18+
}
19+
function dir_readdir(): string|false {
20+
return false;
21+
}
22+
function dir_rewinddir(): bool {
23+
return false;
24+
}
25+
}
26+
27+
$file = __DIR__ . '/gh18438.zip';
28+
$zip = new ZipArchive;
29+
$zip->open($file, ZIPARCHIVE::CREATE);
30+
var_dump($zip->addPattern('/nomatches/'));
31+
var_dump($zip->addPattern('/invalid'));
32+
33+
stream_wrapper_register('custom', CustomStreamWrapper::class);
34+
var_dump($zip->addPattern('/invalid', 'custom://'));
35+
?>
36+
--CLEAN--
37+
<?php
38+
$file = __DIR__ . '/gh18438.zip';
39+
@unlink($file);
40+
?>
41+
--EXPECTF--
42+
array(0) {
43+
}
44+
45+
Warning: ZipArchive::addPattern(): No ending delimiter '/' found in %s on line %d
46+
47+
Warning: ZipArchive::addPattern(): Invalid expression in %s on line %d
48+
bool(false)
49+
array(0) {
50+
}

0 commit comments

Comments
 (0)