fix(sync): 支持大规模 Skills 归档安全恢复#5695
Open
DASungta wants to merge 4 commits into
Open
Conversation
DASungta
marked this pull request as ready for review
July 23, 2026 15:35
Owner
|
@codex review |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary / 概述
这个 PR 修复 WebDAV / S3 Skills 备份“可以上传,但在另一台设备无法恢复”的问题。
主要改动:
manifest.json中为skills.zip增加可选的entryCount、uncompressedSize,不提升协议版本。问题定位与历史分析
原实现的判断位于 Skills ZIP 恢复路径:
这里的
archive.len()统计的是 ZIP 中所有文件和目录条目,并不是 CC Switch 数据库中的 Skill 数量。因此,一个 Skill 只要携带较多模板、示例、前端依赖或其他资源文件,就可能单独突破限制。我对本机的真实备份进行了统计:
这份备份远低于 512 MiB,却因为条目数超过 10,000 而无法在其他设备恢复。资源型 Skill 已经越来越常见,Skill 数量与 ZIP 条目数之间不再存在稳定比例。
继续查看 Git 历史后确认,10,000 条目和 512 MiB 限制最初由提交
6098fa75引入,目的在于防止 ZIP Bomb、海量小文件导致的 CPU / inode 消耗以及解压后磁盘占用失控。这个安全目标是合理且必须保留的。真正的问题有两个:
修改理由与必要性
只删除条目上限会放弃对海量小文件攻击的防护;只提高上限但不调整上传路径,则仍然可能产生“上传成功、恢复失败”的快照。
因此这个 PR 采用有界扩容和上传/恢复对称校验:
100,000 相对当前真实的 12,676 条目约有 7.9 倍余量,能够支持多个资源型 Skill,同时仍然是明确、可测试的资源上界。
实现考量
1. 上传和恢复使用相同安全策略
ZIP 创建过程不再一次性读取单个文件,而是流式复制并累计实际字节数。每写入一个文件或目录条目就更新统计,超限立即终止本地快照构建。
ZIP 完成后,
db.sql和skills.zip的最终产物大小还会使用与下载端相同的 512 MiB artifact 限制。WebDAV 只有在整个本地快照通过预检后才创建远端目录,S3 同样在任何put_object之前完成快照构建。2. 中央目录预检 + 实际字节流硬限制
恢复端先遍历 ZIP 中央目录:
checked_add汇总声明的未压缩大小;中央目录属于不可信输入,因此它只用于快速预检。真正解压时仍按实际读取的字节数再次执行 512 MiB 限制,避免伪造 ZIP 元数据绕过检查。
3. 保持协议向后兼容
统计字段放在
skills.zip对应的ArtifactMeta中,并使用可选字段:{ "entryCount": 12676, "uncompressedSize": 64554996 }4. 预估体积的语义
界面展示的是文件内容逻辑大小,即 ZIP 解压后所有普通文件字节数之和。它可跨平台稳定计算,但不等同于最终磁盘占用;大量小文件、目录项和文件系统块分配会使实际占盘更高。
Related Issue / 关联 Issue
未关联 Issue。本 PR 针对可稳定复现的跨设备 Skills 恢复失败。
Screenshots / 截图
无。恢复确认框仅在新 manifest 包含统计字段时增加“Skills 文件/目录条目”和“预计解压体积”两行;旧 manifest 的现有界面保持不变。
Validation / 验证
cargo fmt --checkcargo clippy --lib -- -D warningscargo test --lib services::webdav_sync -- --nocapture:8 passedcargo test --lib services::sync_protocol::tests -- --nocapture:25 passedcargo test --lib services::s3_sync::tests -- --nocapture:5 passednode node_modules/typescript/bin/tsc --noEmitnode node_modules/prettier/bin/prettier.cjs --check "src/**/*.{js,jsx,ts,tsx,css,json}"node node_modules/vitest/vitest.mjs run tests/components/WebdavSyncSection.test.tsx:21 passed本机
pnpm typecheck会被 pnpm 的依赖构建审批检查提前阻断(ERR_PNPM_IGNORED_BUILDS,涉及 esbuild / msw),尚未进入tsc;因此使用项目已安装的同一 TypeScript 本地二进制直接执行了等价的tsc --noEmit,未修改依赖审批配置。Checklist / 检查清单
cargo fmt/cargo clippy通过