Skip to content

Conversation

@lichaofan2008
Copy link

@lichaofan2008 lichaofan2008 commented Jan 5, 2026

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

Summary by Sourcery

Handle image loading from PNG files that report parse errors but still contain readable data, adding logging around the read process.

Bug Fixes:

  • Ensure partially corrupted PNG files that can still be read are processed consistently after a successful read operation.

Enhancements:

  • Add diagnostic logging for image readability and read success or failure when loading images.

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
@sourcery-ai
Copy link

sourcery-ai bot commented Jan 5, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts image loading for readable PNGs by switching from value-returning read() to pointer-based read(QImage*) with added logging around success/failure, ensuring partially readable corrupted PNGs still go through normal processing.

Sequence diagram for updated PNG image loading and logging

sequenceDiagram
    participant Caller
    participant FileHander
    participant QImageReader
    participant QApplication
    participant Desktop

    Caller->>FileHander: loadImage_helper(path, hander)
    FileHander->>QImageReader: construct_with_path(path)
    QImageReader-->>FileHander: instance_ready

    FileHander->>QImageReader: canRead()
    QImageReader-->>FileHander: true

    FileHander->>FileHander: create QImage img
    FileHander->>FileHander: log(info) img can read, file path

    FileHander->>QImageReader: read(&img)
    QImageReader-->>FileHander: bool success

    alt read success
        FileHander->>FileHander: log(info) img read success after can read
    else read failed
        FileHander->>FileHander: log(warning) img read failed after can read
    end

    FileHander->>QApplication: desktop()
    QApplication-->>FileHander: Desktop

    alt desktop not null and img dpi != desktop dpi
        FileHander->>Desktop: logicalDpiX()
        Desktop-->>FileHander: dpiX
        FileHander->>FileHander: img.setDotsPerMeterX(...)
        FileHander->>FileHander: img.setDotsPerMeterY(...)
    end

    FileHander-->>Caller: QImage img
Loading

File-Level Changes

Change Details Files
Change QImageReader usage to pointer-based read with logging to better handle corrupted-but-readable PNG files.
  • Replace value-returning reader.read() with reader.read(&img) on a pre-declared QImage instance
  • Add informational log when reader.canRead() is true to trace file paths being processed
  • Log success when reader.read(&img) returns true after canRead()
  • Log a warning when reader.read(&img) returns false after canRead() but allow subsequent processing of img
src/service/filehander.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • The new qInfo/qWarning logs inside loadImage_helper will run for every readable image and may be noisy in normal use; consider downgrading to qDebug or guarding them behind a verbose/log-level flag.
  • When reader.read(&img) fails, you log a generic warning but still proceed with img; consider including reader.error() / reader.errorString() in the warning to make diagnosing corrupted PNG cases easier.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new qInfo/qWarning logs inside loadImage_helper will run for every readable image and may be noisy in normal use; consider downgrading to qDebug or guarding them behind a verbose/log-level flag.
- When reader.read(&img) fails, you log a generic warning but still proceed with img; consider including reader.error() / reader.errorString() in the warning to make diagnosing corrupted PNG cases easier.

## Individual Comments

### Comment 1
<location> `src/service/filehander.cpp:337-345` </location>
<code_context>
     if (reader.canRead()) {
-        QImage img = reader.read();
+        QImage img;
+        qInfo() << "img can read, file:" << path;
+        // 某些已损坏的PNG文件这里会返回false,但同时也读取到了数据,我们按正常流程处理
+        if (reader.read(&img)) {
+            qInfo() << "img read success after can read, file:" << path;
+        } else {
+            qWarning() << "img read failed after can read, file:" << path;
+        }
         auto desktop = QApplication::desktop();
</code_context>

<issue_to_address>
**suggestion:** Consider lowering log level or reducing verbosity for per-image success logs.

These `qInfo()` calls will run for every successfully readable image and can flood production logs when this path is hot. Consider either switching success logs to `qDebug()`, guarding them behind a verbose/debug flag, or relying only on the `qWarning()` on failures to keep logs focused and useful.

```suggestion
    if (reader.canRead()) {
        QImage img;
        qDebug() << "img can read, file:" << path;
        // 某些已损坏的PNG文件这里会返回false,但同时也读取到了数据,我们按正常流程处理
        if (reader.read(&img)) {
            qDebug() << "img read success after can read, file:" << path;
        } else {
            qWarning() << "img read failed after can read, file:" << path;
        }
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@lichaofan2008
Copy link
Author

/forcemerge

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Jan 5, 2026

This pr force merged! (status: unstable)

@deepin-bot deepin-bot bot merged commit b013f77 into linuxdeepin:release/eagle Jan 5, 2026
17 of 18 checks passed
@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: lichaofan2008, max-lvs

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants