Create parent directories only after the containment check in InstallHelper.TryExtractToDirectory
还没有人认领这个 Issue。
评估
调研方向
从 src/code/InstallHelper.cs 中的 InstallHelper.TryExtractToDirectory 开始,检查目录创建和包含关系检查逻辑附近的代码。跟踪 entry.FullName 如何变成 destinationPath,并验证是否在任何目录或文件副作用发生之前完成包含关系检查。完成标准是:被包含关系检查拒绝的条目不会留下任何目录,而有效条目仍能正常提取。
由索引模型根据 Issue 内容生成。
描述
Summary of the new feature / enhancement
During package extraction, entry-derived parent directories are created before the path-containment decision runs. An entry whose file write the containment check would reject can still leave empty directories outside the extraction root (directory-only effect — no file content is written outside). As a user, I want each entry's extraction side effects to be all-or-nothing, so a malformed package cannot leave stray directories anywhere on disk.
Proposed technical implementation details
In src/code/InstallHelper.cs, TryExtractToDirectory (~L1299 on current main):
- For entries containing a path separator,
Directory.CreateDirectory(Path.Combine(extractPath, parentDirs))runs first (~L1372-1377), using the raw entry prefix. - Only afterwards is
destinationPath = Path.GetFullPath(Path.Combine(extractPath, entry.FullName))computed and theStartsWith(extractPath)containment verified (~L1381-1386) — and that check gates only theExtractToFilecall (~L1388).
So a package containing an entry such as ../../../../empty/dir/x (this loop is reached on installs from HTTP repositories, which do not go through a BCL extraction up front) creates empty/dir relative to the extraction temp directory as empty directories, and then the file write is skipped by the containment check.
Suggested reordering, so containment gates every side effect:
- Compute
destinationPath = Path.GetFullPath(Path.Combine(extractPath, entry.FullName))first. - Verify containment of
destinationPathunderextractPath. - Only then create
Path.GetDirectoryName(destinationPath)and callExtractToFile. - Skip entries that fail containment entirely — no partial side effects.
This also makes directory creation consistent with the resolved path rather than the raw entry string.
- 主要语言
- C#
- 星标
- 576
- 派生
- 114
- 平均合并
- 1 天 2 小时
- 30 天内合并 PR
- 7
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
PowerShell/PSResourceGet 的其他 Issue
-
feature_request
难度 2/5 1-3 小时 新手友好度 68/100
PowerShell/PSResourceGet#2013 · 3 条评论 ·
-
Needs-Triage
难度 3/5 1-2 天 新手友好度 68/100
PowerShell/PSResourceGet#2055 ·
-
Needs-Triage
难度 3/5 1-2 天 新手友好度 72/100
PowerShell/PSResourceGet#2054 ·
-
(dsc): Export ignores `--input` filter for `Repository` and `PSResourceList` on DSC 3.3.* or above 未关闭Needs-Triage
难度 3/5 1-2 天 新手友好度 72/100
PowerShell/PSResourceGet#2053 ·
-
feature_request Needs-Triage
难度 4/5 3-5 天 新手友好度 64/100
PowerShell/PSResourceGet#2052 ·
查看 PowerShell/PSResourceGet 的全部 Issue
相似的 Issue
-
bug documentation frontend
难度 2/5 1-3 小时 新手友好度 72/100
azurenoops/spin_agent#975 ·
-
难度 2/5 1-3 小时 新手友好度 86/100
-
:watch: Not Triaged 11.0 fundamentals/subsvc
难度 2/5 1-3 小时 新手友好度 92/100
dotnet/AspNetCore.Docs#37699 ·
-
难度 2/5 1-3 小时 新手友好度 72/100
SubtitleEdit/subtitleedit#15108 · 1 条评论 ·
-
area/docs-content Bug pulumi/docs
难度 1/5 1-3 小时 新手友好度 94/100