HTTP wrapper leaks dechunk filter when header parsing fails after Transfer-Encoding: chunked
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 78/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Área
- backend, networking
Línea de trabajo
Empieza en ext/standard/http_fopen_wrapper.c, en el análisis de los encabezados de respuesta y en la ruta de limpieza out:; el issue señala dónde se crea el filtro de dechunk y dónde la limpieza lo omite tras un encabezado mal formado. Reproduce el problema con los comandos server.php y client.php proporcionados y luego revisa el informe de fugas de la compilación de depuración. Se considera terminado cuando la solicitud fallida no informa de fugas y una respuesta chunked bien formada sigue funcionando.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Description
The following code:
server.php (run first, php server.php):
<?php
$srv = stream_socket_server("tcp://127.0.0.1:18231", $errno, $errstr);
$conn = stream_socket_accept($srv);
while (($line = fgets($conn, 8192)) !== false) { if (trim($line) === '') break; }
// Transfer-Encoding: chunked, then a malformed header line
fwrite($conn, "HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\nBrokenHeaderNoColon\r\n\r\n");
fclose($conn);
client.php (debug build, php -d report_memleaks=1 client.php):
<?php
@file_get_contents("http://127.0.0.1:18231/");
Resulted in this output:
ext/standard/filters.c(1885) : Freeing 0x... (16 bytes), script=.../client.php
main/streams/filter.c(267) : Freeing 0x... (80 bytes), script=.../client.php
=== Total 2 memory leaks detected ===
But I expected this output instead:
(no leaks reported)
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);
}
PHP Version
PHP 8.5.12 (also reproduces on master, 8.7.0-dev)
Operating System
Linux x86_64
- Lenguaje dominante
- C
- Estrellas
- 40.7k
- Forks
- 8.3k
- Merge medio
- 2 d 15 h
- PR fusionados (30 d)
- 155
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de php/php-src
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
Case-insensitive substr_compare, ksort, krsort are still locale-dependentPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. AbiertoBug Status: Needs Triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 73/100
php/php-src#24552 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
HTTP wrapper leaks Location buffer when an empty Location header is followed by another Location headerPosiblemente ocupada @bercedev la tomó hace 2 días. AbiertoBug Category: Streams Status: Verified
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
`Time\Duration::__unserialize()` accepts a "negative zero" payload.Posiblemente ocupada @TimWolla la tomó hoy. AbiertoBug Status: Needs Triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 71/100
php/php-src#24505 · 2 comentarios · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
master: part of the mbstring bailout fix got lost in a mergePosiblemente ocupada @lazerg la tomó hace 2 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
Todos los issues de php/php-src
Issues similares
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 95/100
containers/crun#2415 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
zephyrproject-rtos/zephyr#123423 ·
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día
-
dspromote: /etc/exports uses -alldirs on non-mount-point directories, so mountd exports nothingAbiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 83/100
nextbsd/nextbsd-userland#434 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
Los mantenedores suelen responder en 1 día