fix(adapter): catch JSON.stringify RangeError on oversized bridge data#1960
Merged
fix(adapter): catch JSON.stringify RangeError on oversized bridge data#1960
Conversation
When the adapter emits events to BrowserWindows, JSON.stringify can
throw RangeError ("Invalid string length") if the data payload exceeds
V8's string size limit. Wrap serialization in try-catch to prevent
unhandled promise rejection and log the error instead.
Fixes ELECTRON-D9
Contributor
Code Review:fix(adapter): catch JSON.stringify RangeError on oversized bridge data (#1960)变更概述本 PR 修复了 Sentry ELECTRON-D9 问题:当 bridge adapter 的 方案评估结论:✅ 方案合理 方案正确解决了目标问题:在序列化阶段 catch 问题清单未发现 CRITICAL、HIGH 或 MEDIUM 级别问题。 汇总
结论✅ 批准合并 — 修复逻辑正确,错误处理恰当(catch + log + early return),序列化优化合理,测试覆盖了核心错误路径(mock RangeError + 验证 IPC/WebSocket 均未调用),代码质量良好。 本报告由本地 CONCLUSION: APPROVED |
Contributor
|
✅ 已自动 review,无阻塞性问题,正在触发自动合并。 |
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
JSON.stringifyin adapteremit()with try-catch to preventRangeError: Invalid string lengthwhen data payloads exceed V8's string size limitJSON.stringifycalls per window by serializing once before the loopSentry Issue
ELECTRON-D9 —
RangeError: Invalid string lengthinsrc/common/adapter/main.ts:39bridge.adapter.emit()→JSON.stringify({ name, data })Root Cause
JSON.stringifythrowsRangeError: Invalid string lengthwhen the resulting string would exceed ~512 MB (V8 limit). The adapter'semitfunction calledJSON.stringifywithout error handling, causing an unhandled promise rejection that crashed the event broadcasting.Fix
console.errorTest Plan
tests/unit/adapterEmitGuard.test.tsthat mocksJSON.stringifyto throwRangeErrorand verifies:win.webContents.sendis not calledbroadcastToAllis not calledbunx tsc --noEmit)