fix: auto-detect Deflate64 in ZIP files#389
fix: auto-detect Deflate64 in ZIP files#389max-lvs merged 1 commit intolinuxdeepin:release/eaglefrom
Conversation
Reviewer's GuideAdds a libzip-based pre-scan for ZIP files to detect Deflate64 compression and automatically route such archives to the cli7z plugin, wiring in the new helper into UiTools and linking against libzip in the build system. Sequence diagram for ZIP open with Deflate64 auto-routing to cli7zsequenceDiagram
actor User
participant UiTools
participant libzip
participant PluginManager
participant Plugin_cli7z as Plugin_cli7z
participant Plugin_default as Plugin_default
User->>UiTools: createInterface(fileName, bWrite=false, eType=APT_Auto)
UiTools->>UiTools: determineMimeType(fileName)
UiTools->>libzip: checkZipNeedsAlternativePlugin(fileName)
libzip-->>UiTools: needsAlternative (true/false)
alt needsAlternative == true
UiTools->>UiTools: eType = APT_Cli7z
end
UiTools->>PluginManager: preferredReadPluginsFor(mimeType)
PluginManager-->>UiTools: [Plugin_cli7z, Plugin_default, ...]
alt eType == APT_Cli7z
UiTools->>Plugin_cli7z: create ReadOnlyArchiveInterface
else eType != APT_Cli7z
UiTools->>Plugin_default: create ReadOnlyArchiveInterface
end
UiTools-->>User: ReadOnlyArchiveInterface
Class diagram for UiTools Deflate64 detection and plugin selectionclassDiagram
class UiTools {
+static ReadOnlyArchiveInterface* createInterface(QString fileName, bool bWrite, AssignPluginType eType)
+static ReadOnlyArchiveInterface* createInterface(QString fileName, CustomMimeType mimeType, Plugin* plugin)
+static bool checkZipNeedsAlternativePlugin(QString strFileName)
}
class PluginManager {
+static PluginManager& get_instance()
+QVector~Plugin*~ preferredWritePluginsFor(CustomMimeType mimeType)
+QVector~Plugin*~ preferredReadPluginsFor(CustomMimeType mimeType)
}
class ReadOnlyArchiveInterface
class Plugin
class AssignPluginType {
<<enumeration>>
APT_Auto
APT_Cli7z
APT_Other
}
class libzip_API {
+zip_t* zip_open(const char* path, int flags, int* errorp)
+zip_int64_t zip_get_num_entries(zip_t* archive, int flags)
+int zip_stat_index(zip_t* archive, zip_uint64_t index, int flags, zip_stat* sb)
+void zip_stat_init(zip_stat* sb)
+int zip_close(zip_t* archive)
}
UiTools --> PluginManager : uses
UiTools --> ReadOnlyArchiveInterface : creates
UiTools --> Plugin : selects
UiTools --> AssignPluginType : sets
UiTools --> libzip_API : calls
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- In
checkZipNeedsAlternativePlugin, avoid magic numbers for compression methods (0,9) and use libzip’s named constants (e.g.,ZIP_CM_STORE,ZIP_CM_DEFLATE64) to improve readability and reduce the chance of mistakes if values change. - The detection logic stops after the first non-stored entry; if you need to handle archives with mixed compression methods, consider scanning all entries up to
maxCheckinstead of breaking after the first non-Deflate64 compressed file.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `checkZipNeedsAlternativePlugin`, avoid magic numbers for compression methods (`0`, `9`) and use libzip’s named constants (e.g., `ZIP_CM_STORE`, `ZIP_CM_DEFLATE64`) to improve readability and reduce the chance of mistakes if values change.
- The detection logic stops after the first non-stored entry; if you need to handle archives with mixed compression methods, consider scanning all entries up to `maxCheck` instead of breaking after the first non-Deflate64 compressed file.
## Individual Comments
### Comment 1
<location path="src/source/common/uitools.cpp" line_range="496-505" />
<code_context>
+ zip_stat_init(&stat_buffer);
+
+ if (zip_stat_index(archive, static_cast<zip_uint64_t>(i), 0, &stat_buffer) == 0) {
+ // 跳过 stored 文件(comp_method == 0)
+ if (stat_buffer.comp_method == 0) {
+ continue;
+ }
+
+ // 检查压缩方法
+ // ZIP_CM_DEFLATE (8) = 标准 Deflate
+ // ZIP_CM_DEFLATE64 (9) = Deflate64
+ if (stat_buffer.comp_method == 9) { // ZIP_CM_DEFLATE64
+ qInfo() << "Detected Deflate64 compression method, switching to cli7z plugin"
+ << "file:" << strFileName
</code_context>
<issue_to_address>
**suggestion:** Prefer libzip compression-method constants over magic numbers for clarity and robustness.
Use `ZIP_CM_STORE` instead of `0` and `ZIP_CM_DEFLATE64` (and optionally `ZIP_CM_DEFLATE`) instead of `9` when checking `stat_buffer.comp_method`. This keeps the code self-documenting and avoids relying on magic numbers that could be misread or change in future libzip versions.
```suggestion
if (zip_stat_index(archive, static_cast<zip_uint64_t>(i), 0, &stat_buffer) == 0) {
// 跳过 stored 文件(comp_method == ZIP_CM_STORE)
if (stat_buffer.comp_method == ZIP_CM_STORE) {
continue;
}
// 检查压缩方法
// ZIP_CM_DEFLATE = 标准 Deflate
// ZIP_CM_DEFLATE64 = Deflate64
if (stat_buffer.comp_method == ZIP_CM_DEFLATE64) {
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Use libzip API to detect Deflate64 compression and automatically switch to cli7z plugin for better compatibility. log: fix bug Bug:https://pms.uniontech.com//bug-view-357127.html
deepin pr auto review这段代码的目的是在处理 ZIP 文件时,检测其是否使用了不常见的压缩算法(如 Deflate64),如果检测到,则自动切换到 以下是对这段代码的详细审查和改进建议: 1. 语法与逻辑审查
2. 代码质量改进建议
3. 代码性能改进建议
4. 代码安全改进建议
5. 其他建议
总结这段代码整体质量不错,逻辑清晰,能够解决特定的兼容性问题。主要改进点在于使用 RAII 增强资源管理的安全性,以及注意文件名编码和库版本兼容性。性能方面存在双重打开文件的微小开销,但在当前场景下通常可以接受。 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: LiHua000, max-lvs 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 |
|
/merge |
1 similar comment
|
/merge |
Use libzip API to detect Deflate64 compression and automatically switch to cli7z plugin for better compatibility.
log: fix bug
Bug:https://pms.uniontech.com//bug-view-357127.html
Summary by Sourcery
Detect Deflate64-compressed ZIP archives using libzip and automatically route them to the cli7z plugin for improved compatibility.
New Features:
Enhancements: