From 1c157d3fa2e102ccf375ec4c1ddca8770208dae7 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 20 Oct 2020 15:32:01 +0200 Subject: [PATCH] Fixed bug #80256 Remove the transfer_encoding stream filter immediately when we destroy the old stream, to make sure it doesn't get attached to the new stream. --- NEWS | 4 ++++ ext/standard/http_fopen_wrapper.c | 9 +++++---- ext/standard/tests/http/bug80256.phpt | 29 +++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 ext/standard/tests/http/bug80256.phpt diff --git a/NEWS b/NEWS index 3977dcdd55..3d588c546f 100644 --- a/NEWS +++ b/NEWS @@ -13,6 +13,10 @@ PHP NEWS - Opcache: . Fixed bug #80255 (Opcache bug (bad condition result) in 8.0.0rc1). (Nikita) +- Standard: + . Fixed bug #80256 (file_get_contents strip first line with chunked encoding + redirect). (Nikita) + 15 Oct 2020, PHP 8.0.0RC2 - Core: diff --git a/ext/standard/http_fopen_wrapper.c b/ext/standard/http_fopen_wrapper.c index ac57c55efb..50758ad0f4 100644 --- a/ext/standard/http_fopen_wrapper.c +++ b/ext/standard/http_fopen_wrapper.c @@ -842,6 +842,11 @@ finish: php_stream_close(stream); stream = NULL; + if (transfer_encoding) { + php_stream_filter_free(transfer_encoding); + transfer_encoding = NULL; + } + if (location[0] != '\0') { char new_path[HTTP_HEADER_BLOCK_SIZE]; @@ -958,10 +963,6 @@ out: if (transfer_encoding) { php_stream_filter_append(&stream->readfilters, transfer_encoding); } - } else { - if (transfer_encoding) { - php_stream_filter_free(transfer_encoding); - } } return stream; diff --git a/ext/standard/tests/http/bug80256.phpt b/ext/standard/tests/http/bug80256.phpt new file mode 100644 index 0000000000..01797a082d --- /dev/null +++ b/ext/standard/tests/http/bug80256.phpt @@ -0,0 +1,29 @@ +--TEST-- +Bug #80256: file_get_contents strip first line with chunked encoding redirect +--SKIPIF-- + +--INI-- +allow_url_fopen=1 +--FILE-- + $pid, 'uri' => $uri] = http_server($responses, $output); + +var_dump(file_get_contents($uri)); + +http_server_kill($pid); + +?> +--EXPECT-- +string(4) "1234" -- 2.40.0