Skip to content

Conversation

@GongHeng2017
Copy link

@GongHeng2017 GongHeng2017 commented Nov 20, 2025

-- Fix the issue where entering an incorrect password for an encrypted
ZIP archive should prompt "Wrong password, extraction failed."

Log: fix issue
Bug: https://pms.uniontech.com/bug-view-301765.html

Summary by Sourcery

Improve handling of incorrect passwords during ZIP extraction by resetting the password and displaying an explicit error message.

Bug Fixes:

  • Detect when a wrong password is entered and return an error rather than prompting for a retry
  • Clear the stored password and close the archive upon wrong-password failure
  • Emit a "Wrong password." error message to inform the user of the failed extraction

-- Fix the issue where entering an incorrect password for an encrypted
   ZIP archive should prompt "Wrong password, extraction failed."

Log: fix issue
Bug: https://pms.uniontech.com/bug-view-301765.html
@sourcery-ai
Copy link

sourcery-ai bot commented Nov 20, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

The pull request enhances the extractFiles logic in libzipplugin.cpp by inserting explicit checks for an incorrect password entry and returning a dedicated error (PFT_Error) with a corresponding message, instead of falling through to the generic password-prompt flow.

Sequence diagram for error handling when wrong password is entered during ZIP extraction

sequenceDiagram
    participant User
    participant LibzipPlugin
    participant Archive
    User->>LibzipPlugin: Request to extract encrypted ZIP
    LibzipPlugin->>Archive: Attempt extraction with password
    Archive-->>LibzipPlugin: Return ET_WrongPassword error
    alt Password is not empty
        LibzipPlugin->>User: Show error "Wrong password, extraction failed."
        LibzipPlugin->>Archive: Close archive
        LibzipPlugin->>User: Extraction fails (PFT_Error)
    else Password is empty or other error
        LibzipPlugin->>User: Prompt for password
    end
Loading

Class diagram for updated error handling in LibzipPlugin

classDiagram
    class LibzipPlugin {
        - m_eErrorType
        - m_strPassword
        extractFiles(files: QList<FileEntry>, password: QString): PluginFinishType
    }
    LibzipPlugin : extractFiles() checks for ET_WrongPassword
    LibzipPlugin : On wrong password, clears m_strPassword, closes archive, returns PFT_Error
    LibzipPlugin : Emits error("Wrong password.") if password is incorrect
Loading

File-Level Changes

Change Details Files
Add explicit wrong-password exit in the first error branch
  • Detect ET_WrongPassword when a non-empty password is present
  • Close the ZIP archive, clear m_strPassword, and return PFT_Error immediately
3rdparty/libzipplugin/libzipplugin.cpp
Emit specific error message and exit in the second error branch
  • Detect ET_WrongPassword when a non-empty password is present
  • Emit error("Wrong password."), close the archive, clear m_strPassword, and return PFT_Error
3rdparty/libzipplugin/libzipplugin.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 there - I've reviewed your changes - here's some feedback:

  • Consider consolidating the duplicated wrong‐password handling into a single helper to reduce code repetition and ensure consistent behavior across both extraction paths.
  • Wrap the user‐facing error string "Wrong password." in your translation/localization function to support internationalization.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider consolidating the duplicated wrong‐password handling into a single helper to reduce code repetition and ensure consistent behavior across both extraction paths.
- Wrap the user‐facing error string "Wrong password." in your translation/localization function to support internationalization.

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.

@deepin-ci-robot
Copy link

deepin pr auto review

我来对这个diff进行代码审查:

  1. 代码逻辑分析:
    这段代码主要处理解压缩过程中的密码验证逻辑。新增的代码块主要处理密码错误的情况,当密码错误且之前已有密码时,会清空密码并返回错误状态。

  2. 代码质量评价:
    优点:

  • 增加了对密码错误的明确处理
  • 添加了错误提示信息
  • 及时释放了资源(zip_close)
  • 清空了错误的密码缓存

存在的问题:

  • 代码重复:两处新增的代码块几乎完全相同,违反了DRY(Don't Repeat Yourself)原则
  • 错误处理方式不一致:第一处密码错误没有发出error信号,而第二处有
  • 注释格式不规范:中文注释前缺少空格
  1. 性能分析:
  • 性能影响较小,主要是增加了条件判断
  • zip_close()的调用是必要的资源释放操作
  1. 安全性分析:
  • 及时清空错误的密码是好的安全实践
  • 密码处理逻辑合理

改进建议:

  1. 消除代码重复,建议将密码错误处理逻辑提取为单独的函数:
PluginFinishType LibzipPlugin::handlePasswordError(zip* archive) {
    if(ET_WrongPassword == m_eErrorType && !m_strPassword.isEmpty()) {
        zip_close(archive);
        m_strPassword = "";
        emit error(("Wrong password."));
        return PFT_Error;
    }
    return PFT_Normal;
}
  1. 统一错误处理方式,两处都应该发出error信号

  2. 规范化注释格式:

// 密码错误,给出错误提示
if(ET_WrongPassword == m_eErrorType && !m_strPassword.isEmpty()) {
  1. 建议将密码相关的错误处理逻辑集中到一个地方,避免代码分散

  2. 考虑添加日志记录,便于调试和追踪问题

这些修改将使代码更加健壮、可维护,并提高代码质量。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: GongHeng2017, lzwind

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

@GongHeng2017
Copy link
Author

/merge

@deepin-bot deepin-bot bot merged commit c626e3d into linuxdeepin:develop/snipe Nov 20, 2025
15 checks passed
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