fix: 修复下载/解密卡死与静默截断问题#19
Closed
xchmwang wants to merge 2 commits into
Closed
Conversation
…fixes Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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
inspectSealed的明文大小是高估值(漏算 nt-package 封装开销),之前作为Content-Length传给 StreamSaver,导致浏览器下载永远到不了声明大小。现在不再向createWriteStream声明 size;该值更名为plaintextSizeEstimate(保留plaintextSize别名),仅用于大小限制与进度估算。进度 transformer 中间值钳制在 99% 以下,流真正完成时在flush()补发最终onProgress(total, total)。UnsealerCore解密结果为空/过短时原来continue(不计数、不报错),导致finished永远为假、输出被静默截断。现在抛出ERR_DECRYPT_FAILED。_transform内push(null)(消除 push-after-EOF 风险);_flush检测截断输入(新会话中totalItems>0 && !finished→ERR_TRUNCATED_INPUT;续传会话宽松处理)。浏览器Unsealer的flush()同样检测截断。RecoverableReadStream在输入结束于任意状态时都能正确终止(含 header 阶段 EOF 报错、防止once('readable')叠加);RecoverableWriteStream._final在内部流已 finish/destroy 时不再永久等待,并补充_destroy;已提交 item 数现在持久化到 context(readItemCount),续传时正确恢复。signal(AbortSignal),Range 使用重定向后的 URL,分片长度校验。downloadUnsealed/streamDownloadAndDecrypt/blobDownloadAndDecrypt新增不活动看门狗(默认 60s 无数据中止,timeoutMs可配置,0 禁用),流式尝试挂起时能真正触发 Blob 降级而不是永久挂起;StreamSaver CDN 脚本加载增加 4s 超时(CDN 被墙时不再挂死)。DataProvider构造时未设置 magic number,空输入(0 item)密封出的文件永远无法校验/解封。现在构造时即设置。undefined的checkSealedData/unsealData导出。HeaderSize、BlockInfoSize、MaxItemSize、validateHeader、UnsealerCore、createInactivityWatchdog;浏览器入口另导出inspectSealed、blobDownloadAndDecrypt、getBestWritable、progress transformers。gen:fixtures崩溃)。ERR_DECRYPT_FAILED/ERR_TRUNCATED_INPUT)——这是预期行为,损坏数据不应被当作成功。Test plan
npm test/ 相关 jest 套件通过(含新增的test/regression_fixes.spec.js)ERR_DECRYPT_FAILED/ERR_TRUNCATED_INPUT,而非静默产出不完整文件readItemCount恢复正确,不重复/漏计 item