-
Notifications
You must be signed in to change notification settings - Fork 38
fix: issue of corrupted PNG file. #187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: issue of corrupted PNG file. #187
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
|
/merge |
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: