Skip to content

Commit 544dbe8

Browse files
committed
Merge branch 'PHP-7.4' into master
* PHP-7.4: Fix #76943: Inconsistent stream_wrapper_restore() errors
2 parents 35013ac + ff0f6c2 commit 544dbe8

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
Bug #76943 (Inconsistent stream_wrapper_restore() errors)
3+
--SKIPIF--
4+
<?php
5+
if (!in_array('phar', stream_get_wrappers())) die('skip phar wrapper not registered');
6+
?>
7+
--FILE--
8+
<?php
9+
var_dump(stream_wrapper_restore('foo'));
10+
var_dump(stream_wrapper_restore('phar'));
11+
12+
stream_wrapper_register('bar', 'stdClass');
13+
14+
var_dump(stream_wrapper_restore('foo'));
15+
var_dump(stream_wrapper_restore('phar'));
16+
?>
17+
--EXPECTF--
18+
Warning: stream_wrapper_restore(): foo:// never existed, nothing to restore in %s on line %d
19+
bool(false)
20+
21+
Notice: stream_wrapper_restore(): phar:// was never changed, nothing to restore in %s on line %d
22+
bool(true)
23+
24+
Warning: stream_wrapper_restore(): foo:// never existed, nothing to restore in %s on line %d
25+
bool(false)
26+
27+
Notice: stream_wrapper_restore(): phar:// was never changed, nothing to restore in %s on line %d
28+
bool(true)

main/streams/userspace.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -526,23 +526,24 @@ PHP_FUNCTION(stream_wrapper_restore)
526526
{
527527
zend_string *protocol;
528528
php_stream_wrapper *wrapper;
529-
HashTable *global_wrapper_hash;
529+
HashTable *global_wrapper_hash, *wrapper_hash;
530530

531531
if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &protocol) == FAILURE) {
532532
RETURN_THROWS();
533533
}
534534

535535
global_wrapper_hash = php_stream_get_url_stream_wrappers_hash_global();
536-
if (php_stream_get_url_stream_wrappers_hash() == global_wrapper_hash) {
537-
php_error_docref(NULL, E_NOTICE, "%s:// was never changed, nothing to restore", ZSTR_VAL(protocol));
538-
RETURN_TRUE;
539-
}
540-
541536
if ((wrapper = zend_hash_find_ptr(global_wrapper_hash, protocol)) == NULL) {
542537
php_error_docref(NULL, E_WARNING, "%s:// never existed, nothing to restore", ZSTR_VAL(protocol));
543538
RETURN_FALSE;
544539
}
545540

541+
wrapper_hash = php_stream_get_url_stream_wrappers_hash();
542+
if (wrapper_hash == global_wrapper_hash || zend_hash_find_ptr(wrapper_hash, protocol) == wrapper) {
543+
php_error_docref(NULL, E_NOTICE, "%s:// was never changed, nothing to restore", ZSTR_VAL(protocol));
544+
RETURN_TRUE;
545+
}
546+
546547
/* A failure here could be okay given that the protocol might have been merely unregistered */
547548
php_unregister_url_stream_wrapper_volatile(protocol);
548549

0 commit comments

Comments
 (0)