fix(compressor): fix MIME type detection failure for spanned ZIP files#428
Merged
deepin-bot[bot] merged 1 commit intoJun 11, 2026
Merged
Conversation
- Some spanned ZIP files start with PK\x07\x08 signature (non-standard PK\x03\x04), which Qt MIME detection cannot recognize - When file extension is .zip but content detection returns non-ZIP type, fall back to file command for re-detection Qt 无法识别以 PK\x07\x08 开头的分卷 ZIP 文件,当扩展名为 .zip 但内容检测结果非 ZIP 类型时,回退使用 file 命令二次检测以确保 正确识别。 PMS: ztgd2026060900011 Influence: spanned ZIP files can be correctly detected and extracted
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdjusts MIME type detection logic to better handle ZIP files, particularly WinZip-style spanned ZIPs, by refining when the system falls back to the Flow diagram for updated ZIP MIME detection fallback logicflowchart TD
A[determineMimeType filename] --> B[mimeFromExtension]
B --> C[extName = mimeFromExtension.name]
C --> D[isZipExtension = extName == application/zip]
D --> E[mimeFromContent]
E --> F[isContentZip = mimeFromContent.inherits application/zip]
F --> G["needFileCommandFallback = mimeFromContent.isDefault OR (isZipExtension AND NOT isContentZip)"]
G -->|true| H[Run file command for detection]
G -->|false| I[Use mimeFromContent]
H --> J[Return MIME type]
I --> J
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 left some high level feedback:
- Binding
mimeFromExtension.name()toconst QString &extNamecreates a dangling reference becausename()returns a temporary; store it by value (QString extName = mimeFromExtension.name();) instead. - Since the string literal
"application/zip"is used in multiple places, consider extracting it into a constexpr/constant or reusing the same QStringLiteral to avoid duplication and keep type checks consistent.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Binding `mimeFromExtension.name()` to `const QString &extName` creates a dangling reference because `name()` returns a temporary; store it by value (`QString extName = mimeFromExtension.name();`) instead.
- Since the string literal `"application/zip"` is used in multiple places, consider extracting it into a constexpr/constant or reusing the same QStringLiteral to avoid duplication and keep type checks consistent.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
deepin pr auto review我对这段代码的改进意见如下:
改进后的代码示例: // 定义MIME类型常量
namespace {
const QString APPLICATION_ZIP = QStringLiteral("application/zip");
}
// 将检测逻辑封装为单独的函数
bool shouldUseFileCommandFallback(const QString& mimeContent, const QString& mimeExtension) {
bool isZipExtension = (mimeExtension == APPLICATION_ZIP);
bool isContentZip = mimeContent.inherits(APPLICATION_ZIP);
return mimeContent.isDefault() || (isZipExtension && !isContentZip);
}
CustomMimeType determineMimeType(const QString &filename) {
// ... 前面的代码 ...
const QString &extName = mimeFromExtension.name();
if (shouldUseFileCommandFallback(mimeFromContent, extName)) {
qDebug() << "Using file command to detect MIME type for:" << filename;
QProcess process;
QStringList args;
// ... 后面的代码 ...
// 添加错误处理
if (!process.waitForFinished()) {
qWarning() << "File command execution failed:" << process.errorString();
return mimeFromExtension; // 或其他适当的错误处理
}
// ... 其余代码 ...
}
// ... 其余代码 ...
}这些改进可以提高代码的可维护性、性能和安全性,同时保持原有功能的完整性。 |
lzwind
approved these changes
Jun 11, 2026
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: dengzhongyuan365-dev, lzwind 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 |
Member
Author
|
/forcemerge |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Qt 无法识别以 PK\x07\x08 开头的分卷 ZIP 文件,当扩展名为 .zip
但内容检测结果非 ZIP 类型时,回退使用 file 命令二次检测以确保
正确识别。
PMS: ztgd2026060900011
Influence: spanned ZIP files can be correctly detected and extracted
Summary by Sourcery
Bug Fixes: