]> granicus.if.org Git - php/commitdiff
Fixed bug #80256
authorNikita Popov <nikita.ppv@gmail.com>
Tue, 20 Oct 2020 13:32:01 +0000 (15:32 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Tue, 20 Oct 2020 13:35:41 +0000 (15:35 +0200)
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
ext/standard/http_fopen_wrapper.c
ext/standard/tests/http/bug80256.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 3977dcdd55edf1dad4d80a97a5c7d18606e0eda3..3d588c546fdf1053517382c962c7509a57ec0fde 100644 (file)
--- 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:
index ac57c55efb4c82cdab7ad8aa18821bc0ffe932a8..50758ad0f4a67f1922050f17bfadc17fdd21a46f 100644 (file)
@@ -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 (file)
index 0000000..01797a0
--- /dev/null
@@ -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"