Skip to content
Open
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
5 changes: 5 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,11 @@ PHP 8.6 UPGRADE NOTES
endianness modifier. A name starting with these characters is unaffected
when a repeater precedes it, as in "s1<value".
RFC: https://wiki.php.net/rfc/pack-unpack-endianness-signed-integers-support
. stream_is_local() now returns false for zlib and bzip2 wrappers around
non-local streams, e.g. the following are now no longer considered local:
- `compress.bzip2://http://127.0.0.1/example.html`
- `compress.zlib://http://127.0.0.1/example.html`
- `zlib:http://127.0.0.1/example.html`

- Sysvshm:
. shm_attach() now raises a ValueError when the $key argument is outside the
Expand Down
25 changes: 24 additions & 1 deletion ext/standard/streamsfuncs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1696,7 +1696,30 @@ PHP_FUNCTION(stream_is_local)

php_stream_error_operation_begin();
context = php_stream_context_from_zval(zcontext, 0);
wrapper = php_stream_locate_url_wrapper(Z_STRVAL_P(zstream), NULL, 0);

// Skip past any of `zlib:`, `compress.zlib://`, and `compress.bzip2://`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a hack, not a real fix. Now details of zlib and bzip2 leak into the standard extension.

// if they are present, since they are wrappers that set is_url to
// 0 but the underlying wrapped stream might be a URL. But, only do
// that if the relevant extensions are registered
const HashTable *wrapper_hash = php_stream_get_url_stream_wrappers_hash();
const bool zlib_registered = zend_hash_str_exists(wrapper_hash, "compress.zlib", strlen("compress.zlib"));
const bool bzip2_registered = zend_hash_str_exists(wrapper_hash, "compress.bzip2", strlen("compress.bzip2"));

const char *path = Z_STRVAL_P(zstream);
if (zlib_registered || bzip2_registered) {
while (*path) {
if (zlib_registered && strncasecmp("compress.zlib://", path, strlen("compress.zlib://")) == 0) {
path += strlen("compress.zlib://");
} else if (bzip2_registered && strncasecmp("compress.bzip2://", path, strlen("compress.bzip2://")) == 0) {
path += strlen("compress.bzip2://");
} else if (zlib_registered && strncasecmp("zlib:", path, strlen("zlib:")) == 0) {
path += strlen("zlib:");
} else {
break;
}
}
}
wrapper = php_stream_locate_url_wrapper(path, NULL, 0);
php_stream_error_operation_end(context);
}

Expand Down
45 changes: 45 additions & 0 deletions ext/standard/tests/streams/stream_is_local-bzip2.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
--TEST--
Testing stream_is_local() with bzip2 wrappers
--EXTENSIONS--
bz2
--FILE--
<?php

$targets = [
'http://127.0.0.1/example.html',
'ftp://127.0.0.1/example.html',
'/etc/os-release',
];
$wrappers = [
'',
'compress.bzip2://',
];

foreach ($targets as $target) {
foreach ($wrappers as $wrapper) {
$case = $wrapper . $target;
echo $case . "\n";
var_dump(stream_is_local($case));
echo "\n";
}
}

?>
--EXPECT--
http://127.0.0.1/example.html
bool(false)

compress.bzip2://http://127.0.0.1/example.html
bool(false)

ftp://127.0.0.1/example.html
bool(false)

compress.bzip2://ftp://127.0.0.1/example.html
bool(false)

/etc/os-release
bool(true)

compress.bzip2:///etc/os-release
bool(true)
55 changes: 55 additions & 0 deletions ext/standard/tests/streams/stream_is_local-zlib.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
--TEST--
Testing stream_is_local() with zlib wrappers
--EXTENSIONS--
zlib
--FILE--
<?php

$targets = [
'http://127.0.0.1/example.html',
'ftp://127.0.0.1/example.html',
'/etc/os-release',
];
$wrappers = [
'',
'compress.zlib://',
'zlib:',
];

foreach ($targets as $target) {
foreach ($wrappers as $wrapper) {
$case = $wrapper . $target;
echo $case . "\n";
var_dump(stream_is_local($case));
echo "\n";
}
}

?>
--EXPECT--
http://127.0.0.1/example.html
bool(false)

compress.zlib://http://127.0.0.1/example.html
bool(false)

zlib:http://127.0.0.1/example.html
bool(false)

ftp://127.0.0.1/example.html
bool(false)

compress.zlib://ftp://127.0.0.1/example.html
bool(false)

zlib:ftp://127.0.0.1/example.html
bool(false)

/etc/os-release
bool(true)

compress.zlib:///etc/os-release
bool(true)

zlib:/etc/os-release
bool(true)
Loading