Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: liyigang1 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Reviewer's GuideThe PR prevents UI freezes caused by very large pastes by enforcing a 100,000-character limit across all text-related paste paths, rejecting oversized content with a dedicated warning while preserving existing behavior for normal text, voice, and image pastes. Sequence diagram for bounded paste handlingsequenceDiagram
participant User
participant Editor as WebRichTextEditor
participant Clipboard
participant Dialog as VNoteMessageDialog
participant Chromium as QWebEnginePage
participant JS as JsContent
User->>Editor: onPaste(isVoicePaste)
alt voice paste
Editor->>Clipboard: text()
alt text length > MAX_NOTE_CONTENT_LEN
Editor->>Dialog: exec()
else within limit
Editor->>Chromium: triggerAction(Paste)
end
else clipboard paste
Editor->>Clipboard: mimeData()
alt voice HTML
alt HTML length > MAX_NOTE_CONTENT_LEN
Editor->>Dialog: exec()
else within limit
Editor->>JS: callJsPasteHtml(html)
end
else image
Editor->>JS: insertImages(imageData)
else text length > MAX_NOTE_CONTENT_LEN
Editor->>Dialog: exec()
else within limit
Editor->>Chromium: triggerAction(Paste)
end
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
1. Root cause: onPaste() in WebRichTextEditor passes clipboard content directly to Chromium render engine without any size limit, pasting extremely large text (e.g. 50MB) causes UI thread freeze 2. Fix: add MAX_NOTE_CONTENT_LEN (100000 chars) check in all paste paths (voice paste, voice HTML paste, normal text paste), show ContentTooLong dialog and return early when limit is exceeded 3. Impact: normal-sized paste is unaffected, only oversized content triggers the limit dialog, preventing application freeze Log: Prevent application freeze when pasting extremely large text Influence: 1. Test normal text paste (small and medium) works as before 2. Test voice paste and image paste are unaffected 3. Test pasting text exceeding 100000 characters shows a dialog fix: 限制粘贴内容大小防止界面卡死 1. 根因:WebRichTextEditor 的 onPaste() 将剪贴板内容直接交给 Chromium 渲染,无内容大小限制,粘贴巨量文本(如50MB)导致UI线程阻塞 2. 方案:在所有粘贴路径(语音粘贴、语音HTML粘贴、普通文本粘贴)增加 MAX_NOTE_CONTENT_LEN(100000字符)校验,超限时弹出 ContentTooLong 提示框并返回,不再将超大内容交给渲染引擎 3. 影响:正常大小粘贴不受影响,仅超大内容触发限制提示框 Log: 防止粘贴巨量文本导致应用卡死 Influence: 1. 测试正常文本粘贴(小段和中段)功能正常 2. 测试语音粘贴和图片粘贴不受影响 3. 测试粘贴超过100000字符的文本时弹出提示框 PMS: BUG-261415
da08ab7 to
0db94c7
Compare
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 优秀 ✅ 通过 潜在问题: 建议: 语法正确,逻辑清晰。所有粘贴路径的长度校验逻辑放置正确,提前返回防止超大内容进入 Chromium 渲染引擎。剪贴板获取代码移至函数开头是合理的重构,保证了所有路径都能访问 mimeData。 2. 代码质量 ✅评价: 良好 ✅ 通过 潜在问题:
建议: 建议将重复的校验逻辑提取为辅助函数,例如:bool WebRichTextEditor::isContentTooLong(const QMimeData* mimeData) { if (mimeData->text().length() > MAX_NOTE_CONTENT_LEN) { VNoteMessageDialog dlg(VNoteMessageDialog::ContentTooLong); dlg.exec(); return true; } return false; },然后在各路径中调用 if (isContentTooLong(mimeData)) return; 以减少代码重复 3. 代码性能 ✅评价: 优秀 ✅ 通过 潜在问题:
建议: 在调用 text() 前,可以先通过 mimeData->hasText() 判断是否存在文本数据,避免对纯图片或语音数据进行不必要的 text() 调用。例如:if (mimeData->hasText() && mimeData->text().length() > MAX_NOTE_CONTENT_LEN) { ... } 4. 代码安全 🔒评价: 优秀 ✅ 通过
安全漏洞详情: 建议: 无安全风险。本次变更通过添加输入内容大小校验,增强了应用的健壮性,防止超大输入导致的拒绝服务问题。剪贴板内容仅用于长度比较,未传递给任何危险操作。 💡 改进建议代码示例// 建议重构:提取重复的校验逻辑为辅助函数
bool WebRichTextEditor::isContentTooLong(const QMimeData* mimeData)
{
if (mimeData->hasText() && mimeData->text().length() > MAX_NOTE_CONTENT_LEN) {
VNoteMessageDialog contentTooLong(VNoteMessageDialog::ContentTooLong);
contentTooLong.exec();
return true;
}
return false;
}
// 在 onPaste() 各路径中调用:
void WebRichTextEditor::onPaste(bool isVoicePaste)
{
QClipboard *clipboard = QApplication::clipboard();
const QMimeData *mimeData = clipboard->mimeData();
if (isVoicePaste) {
if (isContentTooLong(mimeData)) return;
return page()->triggerAction(QWebEnginePage::Paste);
}
auto html = mimeData->html();
if (html.contains(QRegularExpression("<div class=\"[^\"]*voiceBox"))) {
if (isContentTooLong(mimeData)) return;
JsContent::instance()->callJsPasteHtml(html);
return;
}
// ...
} else {
if (isContentTooLong(mimeData)) return;
page()->triggerAction(QWebEnginePage::Paste);
}
}本报告由 AI 代码审查工具自动生成 |
Root Cause Analysis
The
onPaste()method inWebRichTextEditor(src/views/webrichtexteditor.cpp:537-566) passes clipboard content directly to the Chromium render engine viapage()->triggerAction(QWebEnginePage::Paste)without any size limit. When a user pastes extremely large text (e.g. 50MB), Chromium's HTML parser and layout engine consume excessive resources, blocking the UI thread and causing the application to freeze. Key evidence: the entire codebase has length limits for titles (64 chars), folder names (64 chars), and audio duration (20 min), but no limit exists for note body content.Fix Approach
Added
MAX_NOTE_CONTENT_LEN(100,000 characters) constant inglobaldef.hand size checks in all three paste paths withinonPaste(): voice paste (isVoicePaste), voice HTML paste (HTML containingvoiceBoxclass), and normal text paste (else branch). When the limit is exceeded, aContentTooLongdialog is shown and the paste is aborted early, preventing the oversized content from reaching the Chromium render engine. A newContentTooLongenum value and corresponding dialog message were added tovnotemessagedialog.h/.cpp.Change Safety Assessment
Code Safety
onPaste()method signature is unchanged; the fix only adds early-return size checks before existing paste logic, with no modification to normal paste flow behavioronPastewas never previously modified for content size limits — this is purely additive, with no risk of reverting prior bug fixes (PMS 365817, 354073, 354083 are all unrelated to paste size logic)Business Impact Scope
Verification Suggestion
根因分析
WebRichTextEditor的onPaste()方法(src/views/webrichtexteditor.cpp:537-566)通过page()->triggerAction(QWebEnginePage::Paste)将剪贴板内容直接交给 Chromium 渲染引擎,无任何大小限制。当用户粘贴巨量文本(如 50MB)时,Chromium 的 HTML 解析和排版引擎消耗过多资源,阻塞 UI 线程导致应用卡死。关键证据:全项目对标题(64字符)、文件夹名(64字符)、音频时长(20分钟)均有长度限制,但笔记正文无任何限制。修复方案
在
globaldef.h中新增MAX_NOTE_CONTENT_LEN(100,000 字符)常量,并在onPaste()的三条粘贴路径中增加大小校验:语音粘贴(isVoicePaste)、语音 HTML 粘贴(含voiceBox类的 HTML)、普通文本粘贴(else 分支)。超限时弹出ContentTooLong提示框并提前返回,阻止超大内容进入 Chromium 渲染引擎。同时在vnotemessagedialog.h/.cpp中新增ContentTooLong枚举值及对应提示文案。改动安全评估
代码安全评估
onPaste()函数签名未变,修复仅在现有粘贴逻辑前增加 early-return 大小校验,不改变正常粘贴流程行为onPaste从未做过内容大小限制——本次为纯新增,不存在撤销历史修复的风险(PMS 365817、354073、354083 均与粘贴大小逻辑无关)业务影响范围
验证建议
Summary by Sourcery
Limit pasted note content and provide a warning dialog when the maximum size is exceeded.
Bug Fixes:
Enhancements: