Repository navigation
fix: fix infinite loop and OOB read in text processing - #454
Conversation
Reviewer's GuideImplementationBound PDF word extraction by the available text and rectangle entries, and avoid the empty-rectangle access that caused out-of-bounds reads.
Ensure autoCutText emits an over-wide character without decrementing the loop index, so wrapping continues instead of hanging.
TestsAdd regression tests for PDF extraction with oversized character counts, shorter or empty containers, and wrapping when a glyph exceeds the label width.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="reader/widgets/SecurityDialog.cpp" line_range="50-51" />
<code_context>
+ --i;
+ } else {
+ // 单字符宽度即超过label宽度,单独作为一行输出
+ newstr.strList.append(QString(strText.at(i)));
+ newstr.resultStr += strText.at(i) + QString("\n");
+ str.clear();
+ }
</code_context>
<issue_to_address>
**Supplementary characters display incorrectly**
When a supplementary Unicode character is encountered at a wrapping boundary or is wider than the label, `autoCutText()` processes `strText.at(i)` one UTF-16 code unit at a time, splitting the surrogate pair and causing the dialog to display corrupted or missing text.
Iterate over complete Unicode characters and keep each character’s surrogate pair together when wrapping and appending text.
</issue_to_address>
### Comment 2
<location path="reader/widgets/SecurityDialog.cpp" line_range="50-51" />
<code_context>
+ --i;
+ } else {
+ // 单字符宽度即超过label宽度,单独作为一行输出
+ newstr.strList.append(QString(strText.at(i)));
+ newstr.resultStr += strText.at(i) + QString("\n");
+ str.clear();
+ }
</code_context>
<issue_to_address>
**Label reserves an extra line**
When the final character is wider than the label, the oversized-character branch appends the character with a newline and leaves `str` empty, then the unconditional final append adds an empty `strList` entry; `autoFeed()` counts that entry when setting the label height, leaving blank space below the text.
Skip the final `strList` append when `str` is empty.
</issue_to_address>| newstr.strList.append(QString(strText.at(i))); | ||
| newstr.resultStr += strText.at(i) + QString("\n"); |
There was a problem hiding this comment.
🟡 Medium · Supplementary characters display incorrectly
When a supplementary Unicode character is encountered at a wrapping boundary or is wider than the label, autoCutText() processes strText.at(i) one UTF-16 code unit at a time, splitting the surrogate pair and causing the dialog to display corrupted or missing text.
Iterate over complete Unicode characters and keep each character’s surrogate pair together when wrapping and appending text.
Prompt for AI agents
In `reader/widgets/SecurityDialog.cpp` at lines 50-51:
**Supplementary characters display incorrectly**
When a supplementary Unicode character is encountered at a wrapping boundary or is wider than the label, `autoCutText()` processes `strText.at(i)` one UTF-16 code unit at a time, splitting the surrogate pair and causing the dialog to display corrupted or missing text.
Iterate over complete Unicode characters and keep each character’s surrogate pair together when wrapping and appending text.| newstr.strList.append(QString(strText.at(i))); | ||
| newstr.resultStr += strText.at(i) + QString("\n"); |
There was a problem hiding this comment.
🟡 Medium · Label reserves an extra line
When the final character is wider than the label, the oversized-character branch appends the character with a newline and leaves str empty, then the unconditional final append adds an empty strList entry; autoFeed() counts that entry when setting the label height, leaving blank space below the text.
Skip the final strList append when str is empty.
Prompt for AI agents
In `reader/widgets/SecurityDialog.cpp` at lines 50-51:
**Label reserves an extra line**
When the final character is wider than the label, the oversized-character branch appends the character with a newline and leaves `str` empty, then the unconditional final append adds an empty `strList` entry; `autoFeed()` counts that entry when setting the label height, leaving blank space below the text.
Skip the final `strList` append when `str` is empty.51c5ba7 to
17f46de
Compare
1. Root cause: SecurityDialog::autoCutText() decrements i after clearing str, but when a single char exceeds label width str is empty after remove, so --i cancels i++ causing infinite loop 2. Fix: check str.isEmpty() after remove, if empty output the char as-is without decrementing i, preventing the loop deadlock 3. Impact: security dialog text display works for wide chars, no behavior change for normal text wrapping 4. Root cause: PDFPage::words() loop exits on index==charCount but charCount may exceed texts/rects container sizes, causing OOB 5. Fix: add container size checks to loop exit condition and guard rects[0] access with isEmpty() check, preventing OOB read 6. Impact: PDF text extraction handles mismatched container sizes safely, no change for normal PDF documents Log: 修复安全对话框文本裁剪死循环和PDF文本提取越界读取问题 Influence: 1. Test PDF security dialog text display with normal text 2. Test security dialog with single wide character exceeding label 3. Test PDF text selection on normal documents 4. Test PDF text selection on documents with mismatched char counts fix: 修复文本处理中的死循环和越界读取问题 1. 根因:SecurityDialog::autoCutText() 在 str 清空后执行 --i,当 单字符宽度超过 label 时 str 为空,--i 抵消 i++ 导致死循环 2. 方案:remove 后检查 str 是否为空,为空时直接输出当前字符不减 i, 消除循环死锁 3. 影响:安全对话框文本显示支持超宽字符,正常文本折行无行为变化 4. 根因:PDFPage::words() 循环以 index==charCount 为退出条件,但 charCount 可能大于 texts/rects 容器大小导致越界读取 5. 方案:循环退出条件增加容器大小检查,rects[0] 访问前增加空检查, 防止越界读取 6. 影响:PDF 文本提取安全处理容器大小不一致,正常 PDF 文档无变化 Log: 修复安全对话框文本裁剪死循环和PDF文本提取越界读取问题 Influence: 1. 测试 PDF 安全对话框正常文本显示 2. 测试安全对话框单宽字符超过 label 宽度场景 3. 测试正常 PDF 文档文本选择功能 4. 测试字符数与容器不匹配的 PDF 文档文本选择 PMS: BUG-383499
d04f7ef to
c0827ad
Compare
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: liyigang1, lzwind 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 |
|
/forcemerge |
|
This pr force merged! (status: unstable) |
b99ed8c
into
linuxdeepin:release/snipe
fix: fix infinite loop and OOB read in text processing
clearing str, but when a single char exceeds label width str
is empty after remove, so --i cancels i++ causing infinite loop
as-is without decrementing i, preventing the loop deadlock
behavior change for normal text wrapping
charCount may exceed texts/rects container sizes, causing OOB
rects[0] access with isEmpty() check, preventing OOB read
safely, no change for normal PDF documents
Log: 修复安全对话框文本裁剪死循环和PDF文本提取越界读取问题
Influence:
fix: 修复文本处理中的死循环和越界读取问题
单字符宽度超过 label 时 str 为空,--i 抵消 i++ 导致死循环
消除循环死锁
charCount 可能大于 texts/rects 容器大小导致越界读取
防止越界读取
Log: 修复安全对话框文本裁剪死循环和PDF文本提取越界读取问题
Influence:
PMS: BUG-383499
Summary by Sourcery
Harden text processing against infinite loops and out-of-bounds reads while preserving normal wrapping and PDF extraction behavior.
Bug Fixes:
Tests: