You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
HTTP wrapper leaks dechunk filter when header parsing fails after Transfer-Encoding: chunked #24508
Root cause: when the response carries Transfer-Encoding: chunked, the wrapper creates a dechunk filter while parsing headers (php_stream_filter_create, ext/standard/http_fopen_wrapper.c:379 in 8.5.12, :366 on master). If a later header line is malformed, header_info.error is set, the caller closes the stream and jumps to out: (master :1052-1058). The out: cleanup only appends the filter to the stream's readfilters when stream != NULL (master :1257-1259), so on the error path the filter is never freed. Per failed request this leaks the php_stream_filter struct (80 bytes) plus the dechunk filter data (16 bytes).
Reproduces on current master (8.7.0-dev) as well.
Suggested patch (verified against master: repro reports 0 leaks after patching; well-formed chunked responses unaffected):
--- a/ext/standard/http_fopen_wrapper.c+++ b/ext/standard/http_fopen_wrapper.c@@ -1230,6 +1230,13 @@ static php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper,
efree(header_info.location);
}
+ /* On the error path stream is NULL and the filter is never appended+ * to readfilters below, so it must be freed here. */+ if (header_info.transfer_encoding != NULL && stream == NULL) {+ php_stream_filter_free(header_info.transfer_encoding);+ header_info.transfer_encoding = NULL;+ }+
if (resource) {
php_uri_struct_free(resource);
}
Activity