fix: issue of corrupted PNG file.#187
Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:develop/snipefrom Jan 21, 2026
Merged
fix: issue of corrupted PNG file.#187deepin-bot[bot] merged 1 commit intolinuxdeepin:develop/snipefrom
deepin-bot[bot] merged 1 commit intolinuxdeepin:develop/snipefrom
Conversation
Some corrupted PNG files will trigger error messages during parsing, but data is still read from them, and we process them following the normal procedure. 某些已损坏的PNG文件解析时会报错,但同时也读取到了数据,我们按正常流程处理。 Bug: https://pms.uniontech.com//bug-view-346475.html v20 BUG 分支合一到v25主线 Task: https://pms.uniontech.com/task-view-383477.html
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: lichaofan2008 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 guide (collapsed on small PRs)Reviewer's GuideAdjusts PNG image loading to use the boolean-returning overload of QImageReader::read, adds logging around reading behavior, and preserves the existing DPI adjustment logic. Sequence diagram for updated PNG image loading and loggingsequenceDiagram
participant FileHander
participant loadImage_helper
participant QImageReader as QImageReader_reader
participant Logger
FileHander->>loadImage_helper: loadImage_helper(path, hander)
activate loadImage_helper
loadImage_helper->>QImageReader_reader: construct with path
loadImage_helper->>QImageReader_reader: canRead()
QImageReader_reader-->>loadImage_helper: bool canRead
alt reader can read image data
loadImage_helper->>Logger: qInfo img can read, file path
loadImage_helper->>QImageReader_reader: read(img)
QImageReader_reader-->>loadImage_helper: bool readOk
alt readOk is true
loadImage_helper->>Logger: qInfo img read success after can read, file path
else readOk is false
loadImage_helper->>Logger: qWarning img read failed after can read, file path
end
loadImage_helper->>loadImage_helper: adjust DPI if needed (Qt5)
else reader cannot read image data
loadImage_helper->>loadImage_helper: handle unreadable image
end
loadImage_helper-->>FileHander: QImage img
deactivate loadImage_helper
Flow diagram for updated loadImage_helper PNG handlingflowchart TD
A[Start loadImage_helper with path] --> B[Create QImageReader with path]
B --> C{reader.canRead}
C -- No --> D[Handle unreadable image and return]
C -- Yes --> E[qInfo img can read, file path]
E --> F[Call reader.read into img]
F --> G{read returned true}
G -- Yes --> H[qInfo img read success after can read, file path]
G -- No --> I[qWarning img read failed after can read, file path]
H --> J[Adjust DPI if needed - Qt5]
I --> J[Adjust DPI if needed - Qt5]
J --> K[Return QImage img]
D --> K[Return QImage img]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
deepin pr auto review这段代码主要针对图片加载逻辑进行了修改,增加了一些日志输出,并修改了图片读取的判断逻辑。以下是对这段 1. 语法逻辑审查
2. 代码质量审查
3. 代码性能审查
4. 代码安全审查
综合改进后的代码建议 if (reader.canRead()) {
QImage img;
// 尝试读取图片
if (!reader.read(&img)) {
// 读取失败,检查是否读取到了部分数据(针对特定损坏文件)
if (img.isNull()) {
qWarning() << "Failed to read image and data is null, file:" << path;
return QImage(); // 或者根据函数签名返回适当的错误状态
}
// 如果 img 不为空,虽然 read 返回 false,我们按注释要求继续处理
#ifdef QT_DEBUG
qWarning() << "Image read returned false but data is available (possibly corrupted), file:" << path;
#endif
}
// 确保 img 有效后再进行后续操作
if (!img.isNull()) {
#if (QT_VERSION_MAJOR == 5)
auto desktop = QApplication::desktop();
// 增加对 desktop 的有效性检查,尽管上面有检查,但这里再次确保 img 有效
if (Q_NULLPTR != desktop && img.logicalDpiX() != desktop->logicalDpiX()) {
// ... DPI 处理逻辑
}
#endif
// ... 其他后续逻辑
return img;
}
}总结修改点:
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The new qInfo/qWarning logs on every image load may be quite noisy in normal operation; consider downgrading to qDebug or guarding them behind a verbose/debug flag so routine loads don't flood the logs.
- When logging failures in
reader.read(&img), it could be more actionable to includereader.error()/reader.errorString()in the message so that log output directly indicates the underlying parsing issue.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The new qInfo/qWarning logs on every image load may be quite noisy in normal operation; consider downgrading to qDebug or guarding them behind a verbose/debug flag so routine loads don't flood the logs.
- When logging failures in `reader.read(&img)`, it could be more actionable to include `reader.error()` / `reader.errorString()` in the message so that log output directly indicates the underlying parsing issue.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Author
|
/merge |
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.
Some corrupted PNG files will trigger error messages during parsing, but data is still read from them, and we process them following the normal procedure.
某些已损坏的PNG文件解析时会报错,但同时也读取到了数据,我们按正常流程处理。
Bug: https://pms.uniontech.com//bug-view-346475.html
v20 BUG 分支合一到v25主线
Task: https://pms.uniontech.com/task-view-383477.html
Summary by Sourcery
Handle partially readable images from corrupted PNG files during image loading and add logging around the read process.
Bug Fixes:
Enhancements: