streams/userspace.c: PHP_STREAM_FLAG_NO_FCLOSE guard missing in stream_stat handler (incomplete fix for GH-25586)
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
Línea de trabajo
Empieza en main/streams/userspace.c, en _php_stream_stat, y compara cómo se maneja el callback stream_stat con las comprobaciones existentes para flush, write, read, seek y cast. Añade una prueba de regresión para un callback stream_stat() que llama a fclose() en su flujo, siguiendo las pruebas existentes de flujos de usuario. Se considera terminado cuando fclose() emite una advertencia y no cierra el flujo durante la ejecución del callback.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Description
GH-25586 (Nov 2026) added PHP_STREAM_FLAG_NO_FCLOSE guard to the flush
handler in main/streams/userspace.c to prevent use-after-free when a user
stream wrapper's stream_flush() callback calls fclose() on the stream.
The same guard is absent from the stream_stat handler (_php_stream_stat,
line ~865).
The following code:
<?php
class UAFStream {
public static $res;
public function stream_open($path, $mode, $opts, &$opened): bool {
return true;
}
public function stream_stat(): array|false {
// Without PHP_STREAM_FLAG_NO_FCLOSE, fclose() succeeds here,
// freeing the stream while C code may still hold a pointer to it.
fclose(self::$res);
return false;
}
public function stream_read(int $count): string { return ''; }
public function stream_eof(): bool { return true; }
}
stream_wrapper_register('x', 'UAFStream');
$fp = fopen('x://test', 'r');
UAFStream::$res = $fp;
fstat($fp); // triggers stream_stat → fclose() completes with no warning
echo "done\n";
Resulted in this output:
done
No warning is emitted and fclose() completes successfully inside the callback,
freeing the stream resource while fstat() / _php_stream_stat() may still
hold pointers into it.
But I expected this output instead:
Warning: Cannot close stream with active callback in ...
done
Consistent with the guard added for flush in GH-25586: fclose() should be
a no-op (with a warning) when called from within a stream callback.
Suggested fix (main/streams/userspace.c, _php_stream_stat):
bool originally_no_fclose = stream->flags & PHP_STREAM_FLAG_NO_FCLOSE;
stream->flags |= PHP_STREAM_FLAG_NO_FCLOSE;
call_result = zend_call_method_with_0_params(...); /* stream_stat */
if (!originally_no_fclose) {
stream->flags ^= PHP_STREAM_FLAG_NO_FCLOSE;
}
This is the identical pattern used for flush (GH-25586), write, read,
seek, and cast.
PHP Version
PHP 8.6.0 (cli) (built: Nov 19 2026 15:17:27) (ZTS)
Operating System
Ubuntu 26.04
- Lenguaje dominante
- C
- Estrellas
- 41.9k
- Forks
- 8.5k
- Merge medio
- 2 d 18 h
- PR fusionados (30 d)
- 106
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
-
Bug Status: Needs Triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Bug Status: Needs Triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
Los mantenedores suelen responder en 1 día
-
Bug Status: Needs Triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 79/100
Los mantenedores suelen responder en 1 día
-
Bug Status: Needs Triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
Los mantenedores suelen responder en 1 día
-
ext/openssl: 8.2.31+/8.3.31+ fail to build against OpenSSL 1.0.2 (ASN1_STRING_get0_data in xp_ssl.c)AbiertoExtension: openssl Status: Needs Triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 79/100
php/php-src#25402 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de php/php-src
Issues similares
-
documentation
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
Life-Framework/Life-Framework#5378 ·
Los mantenedores suelen responder en 1 día
-
bug status: planned ui
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
ChupathingyCE/chupathingyce#2126 ·
Los mantenedores suelen responder en 1 día
-
good first issue simulation
Dificultad 1/5 1-3 horas Aptitud para principiantes 92/100
MarcosAsh/Lattice_Fluid_Dynamics#270 ·
Los mantenedores suelen responder en 1 día
-
needs-kind
Dificultad 1/5 Menos de una hora Aptitud para principiantes 82/100
falcosecurity/libs#3173 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Installation fails from source: missing libintl.h on macOS, undeclared R_typeToChar() on R 4.6Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
vincentarelbundock/xtx#11 ·