[php-src] Issue #21468: Segfault in file_get_contents w/ a https URL and a proxy set

[email protected] (devicenull)
Newsgroups php.bugs
Message-ID <[email protected]>
Issue: https://github.com/php/php-src/issues/21468
Author: devicenull

### Description

The following code:

```php
<?php
$opts = [
	'http' => [
		'proxy' => 'example.com:80',
	],
];

$context = stream_context_create($opts);
var_dump(file_get_contents('https://php.net', false, $context));
```

Resulted in this output:
```
Segmentation fault
```

But I expected this output instead:
```
bool(false)
```

This appears to be caused by https://github.com/php/php-src/blob/9b022c4c5c41e203ac91041e15ad01310c09a344/ext/standard/http_fopen_wrapper.c#L579 - there seems to be a missing `if (stream)` context here.

Backtrace looks like this:
```
(gdb) bt
#0  php_stream_url_wrap_http_ex (wrapper=wrapper@entry=0x5555569c8760 <php_stream_http_wrapper>, path=path@entry=0x1555520683b0 "https://php.net", mode=mode@entry=0x55555657a370 "rb", options=options@entry=0,
    context=context@entry=0x155552069480, redirect_max=redirect_max@entry=20, flags=1, response_header=0x7fffffffa920, opened_path=<optimized out>) at /home/builder/php-8.4.19/ext/standard/http_fopen_wrapper.c:573
#1  0x0000555555895359 in php_stream_url_wrap_http (wrapper=0x5555569c8760 <php_stream_http_wrapper>, path=0x1555520683b0 "https://php.net", mode=0x55555657a370 "rb", options=0, opened_path=<optimized out>,
    context=0x155552069480) at /home/builder/php-8.4.19/ext/standard/http_fopen_wrapper.c:1203
#2  0x0000555555923926 in _php_stream_open_wrapper_ex (path=path@entry=0x1555520683b0 "https://php.net", mode=mode@entry=0x55555657a370 "rb", options=8, opened_path=opened_path@entry=0x0, context=0x155552069480)
    at /home/builder/php-8.4.19/main/streams/streams.c:2272
#3  0x000055555587ca02 in zif_file_get_contents (execute_data=<optimized out>, return_value=0x1555520140c0) at /home/builder/php-8.4.19/ext/standard/file.c:414
#4  0x00005555557cfbd4 in zif_phar_file_get_contents (execute_data=0x155552014160, return_value=0x1555520140c0) at /home/builder/php-8.4.19/ext/phar/func_interceptors.c:230
#5  0x0000555555642161 in ZEND_DO_FCALL_SPEC_OBSERVER_HANDLER () at /home/builder/php-8.4.19/Zend/zend_vm_execute.h:2146
#6  0x0000555555642ac8 in execute_ex (ex=0x1555520694a0) at /home/builder/php-8.4.19/Zend/zend_vm_execute.h:58951
#7  0x00005555559ffca3 in zend_execute (op_array=op_array@entry=0x15555208c000, return_value=return_value@entry=0x0) at /home/builder/php-8.4.19/Zend/zend_vm_execute.h:64328
#8  0x0000555555a65580 in zend_execute_script (type=type@entry=8, retval=retval@entry=0x0, file_handle=file_handle@entry=0x7fffffffd050) at /home/builder/php-8.4.19/Zend/zend.c:1934
#9  0x000055555590b606 in php_execute_script_ex (primary_file=<optimized out>, retval=retval@entry=0x0) at /home/builder/php-8.4.19/main/main.c:2578
#10 0x000055555590b917 in php_execute_script (primary_file=<optimized out>) at /home/builder/php-8.4.19/main/main.c:2618
#11 0x0000555555a671cf in do_cli (argc=2, argv=0x555556b0eae0) at /home/builder/php-8.4.19/sapi/cli/php_cli.c:935
#12 0x0000555555648fb6 in main (argc=2, argv=0x555556b0eae0) at /home/builder/php-8.4.19/sapi/cli/php_cli.c:1310
```

### PHP Version

```plain
PHP 8.4.19 (cli) (built: Mar 13 2026 09:22:31) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.4.19, Copyright (c) Zend Technologies
    with Zend OPcache v8.4.19, Copyright (c), by Zend Technologies
```

### Operating System

Debian 13
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.