fix(desktop): reject fractional transfer sizes - #5527
Conversation
|
📌 Same maintainer note — full version on #5509. This is the strict-numeric-parsing / reject-fractional theme again — same class as the merged #5500, #5491, #5496, now for desktop transfer sizes. Please consolidate the strict-parse work into a single PR and reuse a shared "strict positive integer" helper instead of another per-file copy. The change itself looks fine — this is purely grouping + DRY, not correctness. |
|
macOS CI failed in |
|
@qwen-code /triage |
qwen-code-ci-bot
left a comment
There was a problem hiding this comment.
Thanks for the PR @tt-a1i! Before we dive into the code, this needs to follow the PR template so reviewers can evaluate it efficiently.
The PR body is missing several required sections:
## What this PR does— currently "Summary", which is close but not the standard heading## Why it's needed— the motivation for the fix (the bug in #5526 is clear, but this section is required)## Reviewer Test Plan— the current "Test plan" lists commands but lacks the required sub-structure: "How to verify", "Evidence (Before & After)", and the "Tested on" OS table## Risk & Scope— risk, out-of-scope items, breaking changes## Linked Issues—Fixes #5526should go in this section- Chinese translation — the
<details>block with a full translation is missing
Please restructure the PR body to match the template headings. The content you already have is good — it just needs to be placed under the right sections.
中文说明
感谢 @tt-a1i 的贡献!在审查代码之前,PR 描述需要按照 PR 模板 的格式来组织,方便 reviewer 高效评估。
当前 PR 描述缺少几个必需的部分:
## What this PR does— 目前用的是 "Summary",接近但不是标准标题## Why it's needed— 修复的动机(#5526 的 bug 很清晰,但这个部分是必需的)## Reviewer Test Plan— 当前的 "Test plan" 列出了命令,但缺少必需的子结构:"How to verify"、"Evidence (Before & After)" 以及 "Tested on" 操作系统表格## Risk & Scope— 风险、不在范围内的内容、破坏性变更## Linked Issues—Fixes #5526应放在这个部分- 中文翻译 — 缺少包含完整翻译的
<details>区块
请按照模板标题重新组织 PR 描述。现有内容质量不错,只需放到正确的章节下即可。
— Qwen Code · qwen3.7-max
|
@qwen-code /triage |
|
Thanks for the PR! Template looks good ✓ — all required sections present, bilingual, test plan clear. On direction: this fixes a real correctness bug. Fractional On approach: minimal and focused — 2 lines of validation changed, 2 regression tests added, nothing extraneous. The change is exactly what the problem calls for. I see @wenshao's existing Moving on to code review. 🔍 中文说明感谢贡献! 模板完整 ✓ — 所有章节齐全,双语,测试计划清晰。 方向:修复了一个真实的正确性 bug。分数的 方案:极简且聚焦 — 改动 2 行校验逻辑,新增 2 个回归测试,没有多余内容。 注意到 @wenshao 已有的 进入代码审查 🔍 — Qwen Code · qwen3.7-max |
2a. Code ReviewIndependent proposal: Given "fractional chunk counts cause transfer hangs" — swap Comparison with diff: The PR does exactly this. Two-line validation swap, two regression tests. No surprises, no scope creep. Findings:
No correctness bugs, no security concerns, no AGENTS.md violations. The code follows the existing inline-validation pattern used in 30+ other locations in the codebase. 2b. Test ResultsCI (GitHub Actions):
Tmux real-scenario testing: N/A. This is an internal RPC handler input-validation change in 中文说明2a. 代码审查独立方案: 针对"分数 chunk 计数导致传输挂起"—— 将 与 diff 的对比: PR 完全按此方案实现。两行校验替换,两个回归测试。无意外,无范围蔓延。 审查发现:
无正确性 bug,无安全隐患,无 AGENTS.md 违规。 2b. 测试结果CI (GitHub Actions): Lint ✅ / Linux 测试 ✅ / Windows 测试 ✅ / macOS ❌( Tmux 真实场景测试:N/A。 这是 — Qwen Code · qwen3.7-max |
|
Stepping back to look at the whole picture: This is a clean, correct fix for a real bug. Fractional The tests pass on Linux and Windows (macOS failure is an unrelated cronScheduler race, filed as #5535). The diff is focused — no drive-by refactors, no scope creep. The code follows the same inline validation pattern used in 30+ other places in the codebase. The existing Approving. ✅ 中文说明回顾整体: 这是一个干净、正确的真实 bug 修复。分数的 测试在 Linux 和 Windows 上通过(macOS 失败是不相关的 cronScheduler 竞态,已提交 #5535)。Diff 聚焦 — 没有顺手重构,没有范围蔓延。代码遵循了代码库中 30+ 处使用的相同内联校验模式。 @wenshao 已有的 批准。✅ — Qwen Code · qwen3.7-max |
qwen-code-ci-bot
left a comment
There was a problem hiding this comment.
LGTM — correct minimal fix for the fractional chunk count hang. CI green on Linux/Windows; macOS failure is unrelated (#5535). ✅
✅ Local verification report — safe to mergeI reproduced this PR's full test plan locally on a clean isolated worktree checked out at the PR head ( Verdict: the change does exactly what it claims, the regression tests genuinely guard it, and nothing else regresses. Every check documented in the PR reproduces. Results
The regression tests actually catch the bugTo confirm the new tests aren't vacuous, I reverted only With the fix restored, all 7 pass. So the change cleanly flips fractional One pre-existing failure in the broader suite — not caused by this PR
This is a stale expected-message string in a file this PR does not touch (the PR changes exactly 2 files: Note on the prettier command
Recommendation: approve / merge. 👍 🇨🇳 中文版(点击展开)✅ 本地验证报告 —— 可以合并我在一个干净的独立 worktree(checkout 到 PR HEAD 结论:改动确实实现了其声明的功能,回归测试能真正守护该行为,且没有引入任何其它回归。 PR 中记录的每一项检查都能复现。 结果
回归测试确实能捕获该 bug为确认新增测试并非「永真」摆设,我仅把 恢复修复后,7 个测试全部通过。因此该改动把分数 更大范围测试中的一个既有失败 —— 与本 PR 无关
这是一个位于本 PR 未触碰文件中的过期断言文本(本 PR 恰好只改了 2 个文件: 关于 prettier 命令的说明仓库根目录的 建议:批准 / 合并。 👍 |
What this PR does
Hardens the
transfer:startRPC handler in the desktop server-core so that it rejects fractionalchunkCountandtotalBytesvalues. The metadata validation now requires both fields to be integers (viaNumber.isInteger) instead of merely being of typenumber, so invalid transfer metadata is rejected before any transfer state is allocated. Adds regression tests covering fractional chunk counts and fractional byte counts.Why it's needed
The previous validation only checked
typeof opts.chunkCount === 'number'/typeof opts.totalBytes === 'number', which accepts fractional values such as1.5or10.5. Non-integer chunk counts and byte counts are not valid transfer metadata and could lead to allocating transfer state from malformed input. Requiring integers rejects these bad values up front.Reviewer Test Plan
How to verify
bun test packages/desktop/packages/server-core/src/handlers/rpc/transfer.test.tscd packages/desktop/packages/server-core && bun run typechecknpx prettier --check packages/desktop/packages/server-core/src/handlers/rpc/transfer.ts packages/desktop/packages/server-core/src/handlers/rpc/transfer.test.tsgit diff --checkAlso ran
bun test packages/desktop/packages/server-core/src; transfer coverage passed, but the full package currently has an unrelated existing failure insystem.open-url.test.tswhere the expected unsupported-protocol error text does not match the current blocked-scheme message.Evidence (Before & After)
N/A — internal logic change covered by unit tests. Before: fractional
chunkCount/totalBytespassed validation. After: they are rejected withInvalid chunkCount/Invalid totalBytes, verified by the new regression tests.Tested on
Environment (optional)
Local macOS workspace; unit tests via bun.
Risk & Scope
transfer:starthandler.Linked Issues
Fixes #5526
AI Assistance Disclosure
I used Codex to review the changes, sanity-check the implementation against existing patterns, and help spot potential edge cases.
中文说明
本 PR 做了什么
加固 desktop server-core 中的
transfer:startRPC 处理器,使其拒绝分数(非整数)的chunkCount和totalBytes值。元数据校验现在要求这两个字段都是整数(通过Number.isInteger),而不仅仅是number类型,因此无效的传输元数据会在分配任何传输状态之前就被拒绝。新增了针对分数 chunk 数和分数字节数的回归测试。为什么需要
此前的校验只检查
typeof opts.chunkCount === 'number'/typeof opts.totalBytes === 'number',这会接受诸如1.5或10.5之类的分数值。非整数的 chunk 数和字节数不是合法的传输元数据,可能导致基于畸形输入分配传输状态。要求整数可以在前期就拒绝这些非法值。审阅者测试计划
如何验证
bun test packages/desktop/packages/server-core/src/handlers/rpc/transfer.test.tscd packages/desktop/packages/server-core && bun run typechecknpx prettier --check packages/desktop/packages/server-core/src/handlers/rpc/transfer.ts packages/desktop/packages/server-core/src/handlers/rpc/transfer.test.tsgit diff --check同时运行了
bun test packages/desktop/packages/server-core/src;传输相关的测试通过,但整个包目前存在一个与本次改动无关的既有失败:system.open-url.test.ts中期望的「不支持协议」错误文本与当前的「被屏蔽 scheme」消息不匹配。证据(前后对比)
N/A —— 内部逻辑改动,已由单元测试覆盖。改动前:分数的
chunkCount/totalBytes能通过校验。改动后:它们会被拒绝并抛出Invalid chunkCount/Invalid totalBytes,由新增的回归测试验证。测试平台
环境(可选)
本地 macOS 工作区;通过 bun 运行单元测试。
风险与范围
transfer:start处理器的输入校验。关联 Issue
Fixes #5526
AI 协助声明
我使用 Codex 来审查改动、对照既有模式核对实现,并帮助发现潜在的边界情况。