FileStatus.IsModeReadOnlyCore compares group with user where its comment says other: an extra getgroups per entry, and a wrong ReadOnly for some modes

Abierto Apto para principiantes
#138,417 1 comentario 0 reacciones 0 asignados Ver en GitHub

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
Stack tecnológico
csharp, macos

Línea de trabajo

Lee src/libraries/System.Private.CoreLib/src/System/IO/FileStatus.Unix.cs en torno a IsModeReadOnlyCore, especialmente la comparación de permisos y su comentario. Revisa las pruebas existentes para el manejo de permisos de archivos Unix y añade cobertura para que los permisos de grupo y de otros usuarios coincidan, y para el modo 0446 en un archivo propiedad de otro usuario. El trabajo estará terminado cuando la comparación siga el comentario y se corrijan tanto el resultado incorrecto de solo lectura como la consulta innecesaria del grupo.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

area-System.IO untriaged
Description

FileStatus.IsModeReadOnlyCore (Unix) skips the group check when group and user agree, where its comment speaks of group and other:

https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/IO/FileStatus.Unix.cs#L112-L116

// System files often have the same permissions for group and other (umask 022).
if (isGroupReadOnly == isUserReadOnly)
{
    return isGroupReadOnly;
}

This has two effects for a file or folder another user owns:

  1. Speed. For the common 0755 or 0644 owned by root, group and other agree (both read-only) but user and group don't, so the shortcut is missed and IsMemberOfGroup runs. On macOS that calls getgroups, which asks opendirectoryd and takes about a millisecond each time. Reading FileSystemInfo.Attributes or FileSystemEntry.Attributes over a tree another user owns pays it for every entry. Walking the 1,163 folders of /usr/local/share/dotnet/packs (root-owned, as the macOS installer leaves it) and reading each one's attributes took 644 ms cold and 274 ms warm. Telling links apart there with LinkTarget took 34 ms.
  2. Correctness. Where group and user agree but other differs, a caller who is neither the owner nor in the group gets the group's answer instead of other's. For example, mode 0446 owned by another user reports ReadOnly to someone outside the group, who may write it.
Reproduction Steps

On macOS, as a user other than root:

var watch = System.Diagnostics.Stopwatch.StartNew();
int count = 0;
foreach (string folder in Directory.EnumerateDirectories("/usr/local/share/dotnet/packs", "*", SearchOption.AllDirectories))
{
    _ = new DirectoryInfo(folder).Attributes;
    count++;
}
Console.WriteLine($"{count} folders, {watch.ElapsedMilliseconds} ms");
Expected behavior

The group check is skipped when group and other agree, as the comment says. Folders owned by root with mode 0755 then need no getgroups call.

Actual behavior

Every such folder calls IsMemberOfGroup. For mode 0446 owned by another user, a caller outside the group is told the file is read-only.

Regression?

Not known.

Known Workarounds

Avoid reading Attributes where only a link check is needed, for example with LinkTarget.

Configuration

.NET 11.0.0, macOS 27 on ARM64 (Apple M2 Max). The code is the same on main.

Other information

The likely fix is if (isGroupReadOnly == isOtherReadOnly).

Lenguaje dominante
C#
Estrellas
18.5k
Forks
5.8k
Merge medio
2 d 8 h
PR fusionados (30 d)
597

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de dotnet/runtime

Todos los issues de dotnet/runtime

Issues similares

Más issues de C#

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.