SplFileObject::isReadable and SplFileObject::isWriteable provide an untrustworthy interface
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- C
- Estrellas
- 40.4k
- Forks
- 8.1k
- Merge medio
- 2 d 13 h
- PR fusionados (30 d)
- 96
Descripción
Description
isReadable and isWriteable only consider the file system permissions but that isn't actually reflective of the state of the object because read and write methods also consider the resource mode so if you trust them you can can run into unexpected bugs as demonstrated in the example below.
Specifically
1 . Streams don't look readable?
2. Resources that are opened write only look readable.
The following code:
<?php
function showFile(\SplFileObject $file) {
var_dump($file->isReadable());
if ($file->isReadable()) {
var_dump($file->fread($file->getSize()));
}
echo str_repeat('=', 80) . PHP_EOL;
}
showFile(new SplFileObject(__FILE__));
$f = new SplFileObject('php://temp', 'r+');
$f->fwrite('content');
showFile($f);
showFile(new SplFileObject(__FILE__, 'a'));
Resulted in this output:
bool(true)
string(376) "<?php
function showFile(\SplFileObject $file) {
var_dump($file->isReadable());
if ($file->isReadable()) {
var_dump($file->fread($file->getSize()));
}
echo str_repeat('=', 80) . PHP_EOL;
}
showFile(new SplFileObject(__FILE__));
$f = new SplFileObject('php://temp', 'r+');
$f->fwrite('content');
showFile($f);
showFile(new SplFileObject(__FILE__, 'a'));
"
================================================================================
bool(false)
================================================================================
bool(true)
PHP Notice: SplFileObject::fread(): Read of 8192 bytes failed with errno=9 Bad file descriptor in /tmp/tmp.php on line 6
bool(false)
================================================================================
But I expected this output instead:
bool(true)
string(376) "<?php
function showFile(\SplFileObject $file) {
var_dump($file->isReadable());
if ($file->isReadable()) {
var_dump($file->fread($file->getSize()));
}
echo str_repeat('=', 80) . PHP_EOL;
}
showFile(new SplFileObject(__FILE__));
$f = new SplFileObject('php://temp', 'r+');
$f->fwrite('content');
showFile($f);
showFile(new SplFileObject(__FILE__, 'a'));
"
================================================================================
bool(true)
string(7) "content"
================================================================================
bool(false)
PHP Version
all
Operating System
No response
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.
Línea de trabajo
Los puntos de entrada son SplFileObject::isReadable(), SplFileObject::isWriteable() y los métodos de lectura/escritura demostrados en el ejemplo. Empieza rastreando cómo estos métodos evalúan los permisos del sistema de archivos frente al modo del recurso. Añade cobertura de regresión para los casos r+, solo escritura y anexado, y después verifica las salidas informadas y esperadas.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- c, php
- Área
- backend
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 42/100