summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2020-10-20 15:32:01 +0200
committerNikita Popov <nikita.ppv@gmail.com>2020-10-20 15:35:41 +0200
commit1c157d3fa2e102ccf375ec4c1ddca8770208dae7 (patch)
tree7860c7d0bdc0bdf91e4a1b4b4f13447e354b41a0
parent486c49dee80440e3aeafc90733c3afe6a19abaed (diff)
downloadphp-git-1c157d3fa2e102ccf375ec4c1ddca8770208dae7.tar.gz
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.
-rw-r--r--NEWS4
-rw-r--r--ext/standard/http_fopen_wrapper.c9
-rw-r--r--ext/standard/tests/http/bug80256.phpt29
3 files changed, 38 insertions, 4 deletions
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--
+<?php require 'server.inc'; http_server_skipif(); ?>
+--INI--
+allow_url_fopen=1
+--FILE--
+<?php
+require 'server.inc';
+
+$responses = array(
+ "data://text/plain,HTTP/1.1 302 Moved Temporarily\r\n"
+ . "Location: /try-again\r\n"
+ . "Transfer-Encoding: chunked\r\n\r\n"
+ . "0\r\n\r\n",
+ "data://text/plain,HTTP/1.1 200 Ok\r\n"
+ . "Transfer-Encoding: chunked\r\n\r\n"
+ . "4\r\n1234\r\n0\r\n\r\n",
+);
+
+['pid' => $pid, 'uri' => $uri] = http_server($responses, $output);
+
+var_dump(file_get_contents($uri));
+
+http_server_kill($pid);
+
+?>
+--EXPECT--
+string(4) "1234"