Skip to content

Commit 1c157d3

Browse files
committed
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.
1 parent 486c49d commit 1c157d3

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ PHP NEWS
1313
- Opcache:
1414
. Fixed bug #80255 (Opcache bug (bad condition result) in 8.0.0rc1). (Nikita)
1515

16+
- Standard:
17+
. Fixed bug #80256 (file_get_contents strip first line with chunked encoding
18+
redirect). (Nikita)
19+
1620
15 Oct 2020, PHP 8.0.0RC2
1721

1822
- Core:

ext/standard/http_fopen_wrapper.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,11 @@ static php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper,
842842
php_stream_close(stream);
843843
stream = NULL;
844844

845+
if (transfer_encoding) {
846+
php_stream_filter_free(transfer_encoding);
847+
transfer_encoding = NULL;
848+
}
849+
845850
if (location[0] != '\0') {
846851

847852
char new_path[HTTP_HEADER_BLOCK_SIZE];
@@ -958,10 +963,6 @@ static php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper,
958963
if (transfer_encoding) {
959964
php_stream_filter_append(&stream->readfilters, transfer_encoding);
960965
}
961-
} else {
962-
if (transfer_encoding) {
963-
php_stream_filter_free(transfer_encoding);
964-
}
965966
}
966967

967968
return stream;

ext/standard/tests/http/bug80256.phpt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
Bug #80256: file_get_contents strip first line with chunked encoding redirect
3+
--SKIPIF--
4+
<?php require 'server.inc'; http_server_skipif(); ?>
5+
--INI--
6+
allow_url_fopen=1
7+
--FILE--
8+
<?php
9+
require 'server.inc';
10+
11+
$responses = array(
12+
"data://text/plain,HTTP/1.1 302 Moved Temporarily\r\n"
13+
. "Location: /try-again\r\n"
14+
. "Transfer-Encoding: chunked\r\n\r\n"
15+
. "0\r\n\r\n",
16+
"data://text/plain,HTTP/1.1 200 Ok\r\n"
17+
. "Transfer-Encoding: chunked\r\n\r\n"
18+
. "4\r\n1234\r\n0\r\n\r\n",
19+
);
20+
21+
['pid' => $pid, 'uri' => $uri] = http_server($responses, $output);
22+
23+
var_dump(file_get_contents($uri));
24+
25+
http_server_kill($pid);
26+
27+
?>
28+
--EXPECT--
29+
string(4) "1234"

0 commit comments

Comments
 (0)