Skip to content

fix: Fix incorrect names when extracting encrypted folders#354

Merged
pengfeixx merged 1 commit intolinuxdeepin:develop/snipefrom
pengfeixx:fix-319251
Jan 20, 2026
Merged

fix: Fix incorrect names when extracting encrypted folders#354
pengfeixx merged 1 commit intolinuxdeepin:develop/snipefrom
pengfeixx:fix-319251

Conversation

@pengfeixx
Copy link
Contributor

@pengfeixx pengfeixx commented Jan 20, 2026

Fix incorrect names when extracting encrypted folders

Log: Fix incorrect names when extracting encrypted folders

Summary by Sourcery

Adjust ZIP password handling and password prompt display names during compression and extraction to fix naming issues with encrypted folders.

Bug Fixes:

  • Ensure libzip is used for ZIP archives whenever a password is set, avoiding incorrect handling of encrypted content.
  • Fix password prompt labels when extracting encrypted archives by showing the archive name for full-extract and using file vs. archive name appropriately based on selection count.

Fix incorrect names when extracting encrypted folders

Log: Fix incorrect names when extracting encrypted folders
@sourcery-ai
Copy link

sourcery-ai bot commented Jan 20, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts password handling for ZIP compression to always use the libzip plugin when a password is set, and fixes the name shown in password prompts during extraction to avoid incorrect file/folder names, especially for encrypted folders.

Sequence diagram for updated ZIP compression plugin selection

sequenceDiagram
    participant User
    participant MainWindow
    participant UiTools

    User->>MainWindow: slotCompress(val)
    MainWindow->>MainWindow: Check m_stCompressParameter.strMimeType
    alt MIME is application/zip and password not empty
        MainWindow->>MainWindow: useLibzipForPassword = true
        MainWindow->>MainWindow: eType = UiTools.APT_Libzip
    else other cases
        MainWindow->>MainWindow: Select eType based on options and bUseLibarchive
    end
    MainWindow->>UiTools: startCompression(eType, m_stCompressParameter)
Loading

Sequence diagram for updated password prompt naming during extraction

sequenceDiagram
    participant User
    participant LibzipPlugin
    participant PasswordNeededQuery
    participant UI

    User->>LibzipPlugin: extractFiles(files, options)
    alt Extract all files
        LibzipPlugin->>PasswordNeededQuery: create with m_strArchiveName
    else Extract selected files
        alt m_listCurIndex.count() == 1
            LibzipPlugin->>PasswordNeededQuery: create with strFileName
        else m_listCurIndex.count() > 1
            LibzipPlugin->>PasswordNeededQuery: create with m_strArchiveName
        end
    end
    LibzipPlugin->>UI: signalQuery(query)
    UI->>User: Show password dialog using display name
    User-->>UI: Enter password
    UI-->>PasswordNeededQuery: Provide password response
    PasswordNeededQuery-->>LibzipPlugin: waitForResponse() returns
    LibzipPlugin->>LibzipPlugin: Retry extraction with provided password
Loading

Class diagram for updated ZIP password handling

classDiagram
    class MainWindow {
        - CompressParameter m_stCompressParameter
        - Options options
        - bool bUseLibarchive
        + void slotCompress(QVariant val)
    }

    class CompressParameter {
        + QString strMimeType
        + QString strPassword
    }

    class Options {
        + bool bSplit
    }

    class UiTools {
        <<enumeration>> AssignPluginType
    }

    class AssignPluginType {
        <<enumeration>>
        + APT_Auto
        + APT_Libzip
    }

    MainWindow --> CompressParameter
    MainWindow --> Options
    MainWindow --> UiTools

    class LibzipPlugin {
        - QString m_strArchiveName
        - QList~int~ m_listCurIndex
        - ErrorType m_eErrorType
        + PluginFinishType extractFiles(QList~FileEntry~ files, Options options)
    }

    class ErrorType {
        <<enumeration>>
        + ET_WrongPassword
        + ET_NeedPassword
    }

    class PluginFinishType {
        <<enumeration>>
        + PFT_Error
        + PFT_Success
    }

    class FileEntry {
        + QString strFileName
    }

    class PasswordNeededQuery {
        + PasswordNeededQuery(QString displayName)
        + void waitForResponse()
    }

    LibzipPlugin --> FileEntry
    LibzipPlugin --> PasswordNeededQuery
    LibzipPlugin --> ErrorType
    LibzipPlugin --> PluginFinishType
Loading

File-Level Changes

Change Details Files
Update ZIP compression logic to select libzip whenever a password is provided.
  • Replace the Chinese-character-specific password detection with a simple non-empty password check.
  • Rename the flag indicating special password handling from a Chinese-specific name to a generic libzip selection flag.
  • Ensure that when a ZIP has any password, the libzip plugin is chosen as the compression backend, regardless of character set.
src/source/mainwindow.cpp
Fix password prompt display names during extraction to use archive or file name appropriately.
  • When extracting all files, change the password prompt to display the archive name instead of an individual file name.
  • When extraction encounters a wrong/missing password, choose the display name based on the number of files being extracted: show the file name for a single file and the archive name for multiple files.
  • Add comments explaining the rationale for using the archive name during full extraction and conditional display name selection based on file count.
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

@deepin-ci-robot
Copy link

deepin pr auto review

这段代码修改主要涉及压缩/解压时的密码处理逻辑和用户提示信息的优化。以下是对这段diff的详细审查意见:

1. 语法与逻辑审查

优点:

  1. 密码提示逻辑优化(libzipplugin.cpp):

    • 修改前:无论解压单个文件还是全部解压,密码提示框显示的都是文件名(strFileName)。如果是解压整个压缩包,且第一个文件名很长或很乱,用户体验不佳。
    • 修改后:区分了场景。全部解压时显示压缩包名称;部分解压时,如果是单个文件显示文件名,多个文件显示压缩包名称。逻辑更符合用户直觉,QString displayName = (m_listCurIndex.count() == 1) ? strFileName : m_strArchiveName; 判断逻辑清晰。
  2. 中文密码检测逻辑移除(mainwindow.cpp):

    • 修改前:通过遍历字符判断是否包含中文(Unicode范围 0x4E00-0x9FA5)来决定是否使用 libzip 插件。这种硬编码的字符范围判断不仅性能较差(O(n)),而且可能遗漏生僻字或包含非标准中文字符。
    • 修改后:只要设置了密码且是ZIP格式,就优先使用 libzip 插件(useLibzipForPassword)。这通常是因为 libzip 对密码处理(特别是兼容性)比 libarchive 更好,或者是为了统一处理逻辑。移除了字符遍历,逻辑更简洁。

潜在问题/建议:

  1. mainwindow.cpp 中的变量命名:

    • 新变量名 useLibzipForPassword 比旧的 zipPasswordIsChinese 更准确,因为它描述的是“行为”而非“状态”。
    • 建议:注释 // 对zip的中文加密使用libzip插件 已经过时,应该更新为 // 对zip的加密使用libzip插件,以反映代码不再局限于中文。
  2. mainwindow.cpp 逻辑冲突风险:

    • 代码逻辑是:如果有密码 -> 用 Libzip。
    • 后续的 else if 分支判断了 bUseLibarchive!options.bSplit
    • 疑问:如果 useLibzipForPassword 为 true,是否会强制覆盖后续针对 ARM 平台的性能优化逻辑?
      • 如果 libzip 在 ARM 平台性能不如 libarchive,那么“有密码就强制用 libzip”可能会导致性能回退。
      • 建议:确认 libzip 在所有目标平台(特别是 ARM)上处理密码的性能和兼容性是否优于 libarchive。如果 libarchive 也能很好地处理密码,可能需要更细致的条件判断。

2. 代码质量审查

  1. 可读性:

    • 代码结构清晰,注释添加得当(如 // 全部解压时显示压缩包名称)。
    • 三元运算符使用恰当,逻辑一目了然。
  2. 维护性:

    • 移除硬编码的 Unicode 范围判断是一个很好的改进,减少了维护特定字符集的负担。

3. 代码性能审查

  1. libzipplugin.cpp:

    • m_listCurIndex.count() 涉及容器大小查询,通常是 O(1) 操作(取决于 QList 实现),对性能影响极小,可以忽略。
  2. mainwindow.cpp:

    • 显著提升:移除了对密码字符串的逐字符遍历检查。对于长密码,这减少了不必要的 CPU 开销。

4. 代码安全审查

  1. 密码处理:

    • 代码逻辑倾向于对 ZIP 密码使用 libzip。如果这是为了修复 libarchive 在处理 ZIP 加密时的已知漏洞或弱加密算法支持问题,那么这是一个安全增强。
    • 建议:确保 m_stCompressParameter.strPassword 在内存中的生命周期管理得当,解压完成后应尽快清除内存中的明文密码(虽然这超出了当前 diff 的范围,但属于安全最佳实践)。
  2. 输入验证:

    • strFileNamem_strArchiveName 用于 UI 显示。如果文件名包含恶意构造的非常长的字符串或特殊控制字符,可能会导致 UI 渲染问题或缓冲区溢出(取决于 PasswordNeededQuery 的实现)。
    • 建议:虽然 Qt 的 QString 通常能处理长字符串,但在显示前最好对超长文件名进行截断或转义处理。

总结与改进建议

总体评价:这是一次质量较高的重构。它提升了用户体验(更清晰的提示信息)和代码性能(移除不必要的遍历),并简化了逻辑。

具体改进建议

  1. 更新注释
    mainwindow.cpp 中的注释 // 对zip的中文加密使用libzip插件 修改为 // 对zip的加密使用libzip插件,确保文档与代码一致。

  2. 确认插件选择策略
    建议在代码提交前,确认在 ARM 平台上,当 ZIP 文件包含密码时,使用 libzip 是否仍然满足性能要求。如果 libarchive 支持更好的多线程解压(在 ARM 上),可能需要权衡:是优先保证密码兼容性,还是优先保证解压速度。

  3. 字符串截断(防御性编程)
    在传递给 PasswordNeededQuery 之前,可以考虑对 displayName 做一个简单的长度限制,防止异常文件名破坏 UI 布局。

    // 示例代码
    const int MAX_DISPLAY_NAME_LENGTH = 100;
    if (displayName.length() > MAX_DISPLAY_NAME_LENGTH) {
        displayName = displayName.left(MAX_DISPLAY_NAME_LENGTH) + "...";
    }
  4. 布尔值比较
    代码中出现了 if (true == useLibzipForPassword)。虽然这是合法的 C++(Yoda 条件写法),但在现代 C++ 风格中,更推荐 if (useLibzipForPassword),这样阅读更自然,且编译器会对误写(如 if (useLibzipForPassword = true))发出警告。建议统一风格。

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 if (true == useLibzipForPassword) style checks can be simplified to if (useLibzipForPassword) for readability and consistency with typical Qt/C++ code style.
  • The logic for choosing the display name in password prompts (archive name vs. file name) is now split across two branches in extractFiles; consider extracting this into a small helper or a single place to avoid subtle divergence in future changes.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `if (true == useLibzipForPassword)` style checks can be simplified to `if (useLibzipForPassword)` for readability and consistency with typical Qt/C++ code style.
- The logic for choosing the display name in password prompts (archive name vs. file name) is now split across two branches in `extractFiles`; consider extracting this into a small helper or a single place to avoid subtle divergence in future changes.

## Individual Comments

### Comment 1
<location> `3rdparty/libzipplugin/libzipplugin.cpp:209-213` </location>
<code_context>
                     }

-                    PasswordNeededQuery query(strFileName);
+                    // 全部解压时显示压缩包名称
+                    PasswordNeededQuery query(m_strArchiveName);
                     emit signalQuery(&query);
</code_context>

<issue_to_address>
**suggestion:** The display-name selection for password prompts is now duplicated and slightly divergent between the two branches.

One branch now always uses `m_strArchiveName` for the prompt, while the other switches between `strFileName` and `m_strArchiveName` based on `m_listCurIndex.count()`. If these are intended to be the same flow, consider a small helper that derives a single `displayName` from the current file and selection count and reuse it in both places to keep behavior and labels consistent as the logic evolves.
</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.

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

@pengfeixx pengfeixx merged commit 385d501 into linuxdeepin:develop/snipe Jan 20, 2026
15 checks passed
@pengfeixx pengfeixx deleted the fix-319251 branch January 20, 2026 12:26
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