Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: Skip symbolic links when extracting release packages

Daniel6eea2a372759
diff --git a/docs/RELEASE-VERIFICATION.zh-CN.md b/docs/RELEASE-VERIFICATION.zh-CN.md
index 293e3c3480..23d47bad04 100644
--- a/docs/RELEASE-VERIFICATION.zh-CN.md
+++ b/docs/RELEASE-VERIFICATION.zh-CN.md
@@ -243,6 +243,7 @@ python -X utf8 scripts/verify-release.py check D:/releases/siyuan --version 3.8.
- 检查导出前端版本、语言 JSON、用户指南和正式版当前更新日志;桌面包必须包含资源根目录下的 `app/package.json`,其版本必须与发布版本一致
- 展开 NSIS 内层压缩包、移动端 `app.zip`、AAB、APP 和 Linux 安装包载荷;鸿蒙仅支持 APP,解包其内部 HAP 以检查内核与资源,不支持单独校验 HAP 文件
- macOS 不依赖本机存在对应构建产物;7-Zip 无法完整提取时明确失败
+- 解包时跳过符号链接,避免 Windows 提取 AppImage 等包时因创建链接权限不足而失败;普通文件解包错误仍会报错,必需入口、内核或被引用资源缺失也不会通过,链接本身不在校验范围内
当前回归测试主要使用模拟安装包,配置加载测试使用本机已安装的 Electron Builder。尚无随文档维护、可核验的真实安装包验收记录,不据此宣称任一平台的当前版本已经通过真实包验证。正式使用前应分平台验收,并保留包版本、SHA256、工具版本及检查报告;测试通过不等于实际构建、签名或安装成功。
diff --git a/scripts/test_verify_release.py b/scripts/test_verify_release.py
index 93d2077128..3e91345567 100644
--- a/scripts/test_verify_release.py
+++ b/scripts/test_verify_release.py
@@ -7,7 +7,10 @@ import io
import json
from pathlib import Path
import tempfile
+import subprocess
+import tarfile
import unittest
+from unittest.mock import patch
import zipfile
@@ -16,6 +19,64 @@ release = importlib.util.module_from_spec(SPEC)
SPEC.loader.exec_module(release)
+class SevenZipTests(unittest.TestCase):
+ def setUp(self):
+ self.temp = tempfile.TemporaryDirectory()
+ self.addCleanup(self.temp.cleanup)
+ self.root = Path(self.temp.name)
+ self.dest = self.root / "output"
+ self.dest.mkdir()
+ self.unpacker = release.Unpacker(self.root, release.find_7z() or "7z")
+
+ @unittest.skipUnless(release.find_7z(), "需要已安装的 7-Zip")
+ def test_real_sevenzip_skips_links_and_keeps_regular_files(self):
+ source = self.root / "links.tar"
+ with tarfile.open(source, "w") as archive:
+ for name in ("icon.png", "resources/kernel/SiYuan-Kernel"):
+ item = tarfile.TarInfo(name)
+ item.size = 4
+ archive.addfile(item, io.BytesIO(b"data"))
+ for name in (".DirIcon", "siyuan.png", "图标链接"):
+ item = tarfile.TarInfo(name)
+ item.type = tarfile.SYMTYPE
+ item.linkname = "icon.png"
+ archive.addfile(item)
+ self.unpacker.extract_sevenzip(source, self.dest)
+ self.assertEqual((self.dest / "icon.png").read_bytes(), b"data")
+ self.assertEqual((self.dest / "resources/kernel/SiYuan-Kernel").read_bytes(), b"data")
+ for name in (".DirIcon", "siyuan.png", "图标链接"):
+ self.assertFalse((self.dest / name).exists())
+
+ def test_squashfs_mode_links_are_excluded_literally(self):
+ listing = "----------\nPath = .DirIcon\nMode = lrwxrwxrwx\n\nPath = icon[1]*\nMode = lrwxrwxrwx\n\nPath = file\nMode = -rw-r--r--\n"
+
+ def run(command, **kwargs):
+ self.assertEqual(kwargs["encoding"], "utf-8")
+ self.assertIn("-sccUTF-8", command)
+ if command[1] == "l":
+ return subprocess.CompletedProcess(command, 0, listing, "")
+ self.assertIn("-spd", command)
+ exclusions = next(item[3:] for item in command if item.startswith("-x@"))
+ self.assertEqual(Path(exclusions).read_text(encoding="utf-8"), ".DirIcon\nicon[1]*\n")
+ return subprocess.CompletedProcess(command, 0, "", "")
+
+ with patch.object(release.subprocess, "run", side_effect=run):
+ self.unpacker.extract_sevenzip(self.root / "test.AppImage", self.dest)
+
+ def test_extraction_error_is_not_ignored(self):
+ results = [subprocess.CompletedProcess([], 0, "----------\nPath = file\nMode = -rw-r--r--\n", ""),
+ subprocess.CompletedProcess([], 2, "", "CRC failed")]
+ with patch.object(release.subprocess, "run", side_effect=results):
+ with self.assertRaisesRegex(release.VerificationError, "CRC failed"):
+ self.unpacker.extract_sevenzip(self.root / "test.AppImage", self.dest)
+
+ def test_listing_error_stops_extraction(self):
+ with patch.object(release.subprocess, "run", return_value=subprocess.CompletedProcess([], 2, "", "bad archive")) as run:
+ with self.assertRaisesRegex(release.VerificationError, "bad archive"):
+ self.unpacker.extract_sevenzip(self.root / "test.AppImage", self.dest)
+ self.assertEqual(run.call_count, 1)
+
+
class ReleaseTests(unittest.TestCase):
def setUp(self):
self.temp = tempfile.TemporaryDirectory()
diff --git a/scripts/verify-release.py b/scripts/verify-release.py
index 3c206e1801..78c38ff5fe 100644
--- a/scripts/verify-release.py
+++ b/scripts/verify-release.py
@@ -69,6 +69,38 @@ class Unpacker:
self.sevenzip = sevenzip
self.count = 0
+ def extract_sevenzip(self, source, dest):
+ if not self.sevenzip:
+ raise VerificationError(f"解包 {source.name} 需要 7-Zip,请指定 --sevenzip")
+ result = subprocess.run([self.sevenzip, "l", "-slt", "-sccUTF-8", str(source)],
+ capture_output=True, encoding="utf-8", errors="replace", timeout=600)
+ if result.returncode:
+ raise VerificationError(f"7-Zip 无法读取 {source.name}:{result.stderr.strip()}")
+ listing = result.stdout.replace("\r\n", "\n").partition("----------\n")
+ if not listing[1]:
+ raise VerificationError(f"无法识别 7-Zip 文件清单:{source.name}")
+ links = []
+ for block in listing[2].split("\n\n"):
+ properties = dict(line.split(" = ", 1) for line in block.splitlines() if " = " in line)
+ name = properties.get("Path")
+ if name is None:
+ continue
+ safe_name(name)
+ if properties.get("Symbolic Link") or properties.get("Mode", "").startswith("l"):
+ links.append(name)
+ command = [self.sevenzip, "x", "-y", "-bd", "-bso0", "-bsp0", "-sccUTF-8", f"-o{dest}"]
+ # 与 ZIP/TAR 解包保持一致,跳过符号链接;必要资源仍由后续完整性检查确认。
+ # 使用精确路径排除,避免通配符扩大范围;列表放在载荷目录之外。
+ with tempfile.TemporaryDirectory(prefix="siyuan-7z-links-", dir=self.root) as temporary:
+ if links:
+ exclusions = Path(temporary) / "links.txt"
+ exclusions.write_text("\n".join(links) + "\n", encoding="utf-8")
+ command.extend(("-spd", "-scsUTF-8", f"-x@{exclusions}"))
+ result = subprocess.run(command + [str(source)], capture_output=True,
+ encoding="utf-8", errors="replace", timeout=600)
+ if result.returncode:
+ raise VerificationError(f"7-Zip 无法完整解包 {source.name}:{result.stderr.strip()}")
+
def extract(self, source):
self.count += 1
if self.count > 64:
@@ -112,12 +144,7 @@ class Unpacker:
with archive.extractfile(entry) as src, target.open("wb") as out:
shutil.copyfileobj(src, out)
else:
- if not self.sevenzip:
- raise VerificationError(f"解包 {source.name} 需要 7-Zip,请指定 --sevenzip")
- command = [self.sevenzip, "x", "-y", "-bd", "-bso0", "-bsp0", f"-o{dest}", str(source)]
- result = subprocess.run(command, capture_output=True, text=True, errors="replace", timeout=600)
- if result.returncode:
- raise VerificationError(f"7-Zip 无法完整解包 {source.name}:{result.stderr.strip()}")
+ self.extract_sevenzip(source, dest)
return dest
def layers(self, package):