DiskUtils.GetWindowsRealPathByHandle retries GetFinalPathNameByHandle after a hard failure and ignores the required buffer size
Les mainteneurs répondent en général sous 5 jours
Évaluation
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Accessibilité débutants
- 74/100
- Type d'issue
- Refactorisation
- Clarté
- Clairement spécifiée
- Activité
- Active
- Stack technique
- csharp
- Domaine
- performance
Piste de recherche
Commencez par TruePath/DiskUtils.cs, plus précisément par DiskUtils.GetWindowsRealPathByHandle et sa fonction locale GetPath. Vérifiez comment GetFinalPathNameByHandle signale un échec par rapport à la taille de tampon requise, puis mettez à jour le comportement de nouvelle tentative conformément aux recommandations. Le travail est terminé lorsque les échecs irrécupérables renvoient null sans nouvelle tentative et que les tampons trop petits entraînent une nouvelle tentative avec la taille requise signalée.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
DiskUtils.GetWindowsRealPathByHandle calls GetFinalPathNameByHandle through the local GetPath function: first with a 256-char buffer, then, if that "fails", with a WindowsMaxPath (32,767-char) buffer:
if (GetPath(256, out var realPath) == false)
{
if (GetPath((uint)WindowsMaxPath, out realPath) == false)
return null;
}
GetPath returns false in two different situations, and the caller handles both the same way:
result == 0: a real error. According to theGetFinalPathNameByHandledocumentation,0means the function failed (e.g.ERROR_PATH_NOT_FOUND,ERROR_NOT_ENOUGH_MEMORY,ERROR_INVALID_PARAMETER). A larger buffer can't fix any of these, yet the code still retries with a 32,767-char buffer: one more P/Invoke and one 64 KiBchar[]rent that cannot succeed.result > bufferSize: buffer too small. In this case the return value is the exact required size, including the terminating null. The code discards it and rents a 32,767-char buffer instead. For example, a path of 300 characters needs 301 chars but gets a 64 KiB array.
Neither case produces a wrong result. This is wasted work on an uncommon path. It is not a correctness failure.
Recommendations
- Retry only when the buffer was too small (
result > bufferSize), and useresultas the new buffer size. - On
result == 0, returnnullimmediately (the caller already falls back to the original path). - Optionally, the first attempt could use a
stackalloc'dMAX_PATH-sized buffer, so the pool is only touched for long paths.
- Langage dominant
- C#
- Étoiles
- 109
- Forks
- 26
- Merge moyen
- 5 j 23 min
- PR mergées (30 j)
- 10
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Aucun modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de ForNeVeR/TruePath
-
enhancement good first issue help wanted
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
ForNeVeR/TruePath#165 · 2 commentaires ·
Les mainteneurs répondent en général sous 5 jours
-
bug help wanted
Difficulté 4/5 3-5 jours Accessibilité débutants 48/100
Les mainteneurs répondent en général sous 5 jours
-
enhancement help wanted
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 35/100
Les mainteneurs répondent en général sous 5 jours
-
enhancement help wanted
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 35/100
Les mainteneurs répondent en général sous 5 jours
-
Dependency DashboardOuvertedashboard
Difficulté 3/5 1-2 jours Accessibilité débutants 15/100
Les mainteneurs répondent en général sous 5 jours
Toutes les issues de ForNeVeR/TruePath
Issues similaires
-
good first issue help wanted
Difficulté 2/5 1-3 heures Accessibilité débutants 65/100
-
untriaged
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
dotnet/dotnet-api-docs#13210 ·
Les mainteneurs répondent en général sous 1 jour
-
aspnet-core/svc doc-enhancement mvc/subsvc Pri2
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
dotnet/AspNetCore.Docs#38016 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 64/100
HicServices/RDMP#2398 ·
-
[Android] Memory leak in MAUI Graphics text drawing and measurement during repeated renderingOuvertearea-drawing platform/android t/bug
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
dotnet/maui#39676 · 1 commentaire · 1 réaction ·
Les mainteneurs répondent en général sous 1 jour