Skip to content

Commit 3e45961

Browse files
fix: Potential fix for code scanning alert no. 6: Arbitrary file access during archive extraction ("Zip Slip") (#52)
Signed-off-by: 梦里不知身是客 <liang.tang.cx@gmail.com> Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent b10a7c7 commit 3e45961

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

  • bundles/com.tlcsdm.eclipse.rcp.example.python3.win32.x86_64/src/com/tlcsdm/eclipse/rcp/example/python3

bundles/com.tlcsdm.eclipse.rcp.example.python3.win32.x86_64/src/com/tlcsdm/eclipse/rcp/example/python3/Activator.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ private static void install() throws IOException, URISyntaxException {
8888
Path target = installDir.resolve("runtimes/python");
8989
// 确保目标目录存在,即使 runtimes 或 python 文件夹不存在
9090
Files.createDirectories(target);
91+
Path normalizedTarget = target.toAbsolutePath().normalize();
9192

9293
// 2. 检查是否已经安装过
9394
Path pythonExe = target.resolve("python.exe");
@@ -103,7 +104,10 @@ private static void install() throws IOException, URISyntaxException {
103104

104105
ZipEntry entry;
105106
while ((entry = zis.getNextEntry()) != null) {
106-
Path filePath = target.resolve(entry.getName());
107+
Path filePath = normalizedTarget.resolve(entry.getName()).normalize();
108+
if (!filePath.startsWith(normalizedTarget)) {
109+
throw new IOException("Bad zip entry: " + entry.getName());
110+
}
107111
if (entry.isDirectory()) {
108112
Files.createDirectories(filePath);
109113
} else {

0 commit comments

Comments
 (0)