DiskUtils.GetWindowsRealPathByHandle retries GetFinalPathNameByHandle after a hard failure and ignores the required buffer size
メンテナーはふだん 5 日以内に返信
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 74/100
- issue の種類
- リファクタリング
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- csharp
- 領域
- performance
調査の方向性
TruePath/DiskUtils.csから始め、特にDiskUtils.GetWindowsRealPathByHandleとそのローカル関数GetPathを確認してください。GetFinalPathNameByHandleが失敗と必要なバッファーサイズをどのように報告するかを確認し、推奨事項に沿うように再試行の動作を更新してください。完了条件は、致命的な失敗では再試行せずにnullを返し、バッファーが小さすぎる場合は報告された必要サイズを使って再試行することです。
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- C#
- スター
- 109
- フォーク
- 26
- 平均マージ
- 5日 23分
- マージ済み PR(30日)
- 10
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
ForNeVeR/TruePath のほかの issue
-
enhancement good first issue help wanted
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
ForNeVeR/TruePath#165 · コメント 2 件 ·
メンテナーはふだん 5 日以内に返信
-
bug help wanted
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
メンテナーはふだん 5 日以内に返信
-
enhancement help wanted
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
メンテナーはふだん 5 日以内に返信
-
enhancement help wanted
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
メンテナーはふだん 5 日以内に返信
-
Dependency Dashboardオープンdashboard
難易度 3/5 1〜2日 初心者へのやさしさ 15/100
メンテナーはふだん 5 日以内に返信
ForNeVeR/TruePath の issue をすべて見る
似ている issue
-
Bug
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 1 日以内に返信
-
good first issue help wanted
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
-
untriaged
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
dotnet/dotnet-api-docs#13210 ·
メンテナーはふだん 1 日以内に返信
-
aspnet-core/svc doc-enhancement mvc/subsvc Pri2
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
dotnet/AspNetCore.Docs#38016 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
HicServices/RDMP#2398 ·