Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .reuse/dep5
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Copyright: UnionTech Software Technology Co., Ltd.
License: CC0-1.0

# Config files
Files: com.deepin.Draw.service deepin-draw.desktop mimetype/deepin-draw.xml
Files: com.deepin.Draw.service deepin-draw.desktop mimetype/deepin-draw.xml config.h.in
Copyright: UnionTech Software Technology Co., Ltd.
License: CC0-1.0

Expand Down
39 changes: 34 additions & 5 deletions src/service/filehander.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2020 - 2022 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2020 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

Expand Down Expand Up @@ -760,10 +760,39 @@ bool FileHander::checkFileBeforeLoad(const QString &file, bool isDdf)
//4 check if file be supported.
QFileInfo info(legalPath);
auto stuff = info.suffix().toLower();
QStringList list = isDdf ? supDdfStuffix() : supPictureSuffix();
if (!list.contains(stuff)) {
d_pri()->setError(EUnSupportFile, tr("Unable to open \"%1\", unsupported file format").arg(info.fileName()));
return false;

if (isDdf) {
// DDF文件仍然通过后缀名检查
QStringList list = supDdfStuffix();
if (!list.contains(stuff)) {
d_pri()->setError(EUnSupportFile, tr("Unable to open \"%1\", unsupported file format").arg(info.fileName()));
return false;
}
} else {
// 图片文件通过文件内容判断格式,而不是仅依赖后缀名
QImageReader reader;
reader.setFileName(legalPath);

// 如果不能读取,尝试通过内容自动检测格式
if (!reader.canRead()) {
reader.setAutoDetectImageFormat(true);
reader.setDecideFormatFromContent(true);
reader.setFileName(legalPath);
}

// 检查文件格式是否支持
if (!reader.canRead()) {
d_pri()->setError(EUnSupportFile, tr("Unable to open \"%1\", unsupported file format").arg(info.fileName()));
return false;
}

// 获取实际格式并检查是否在支持列表中
QString actualFormat = reader.format().toLower();
QStringList supFormats = supPictureSuffix();
Comment on lines +790 to +791
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (bug_risk): Potential mismatch between QImageReader::format() and supPictureSuffix() contents.

QImageReader::format() returns names like "png" / "jpeg" without a dot, while suffix lists often use leading dots or alternate names (e.g. ".jpg" vs "jpeg"). Please ensure supPictureSuffix() uses the same normalization (case, dot, and jpg/jpeg mapping), or normalize both sides before comparison, otherwise some supported images may be rejected as unsupported.

if (!supFormats.contains(actualFormat)) {
d_pri()->setError(EUnSupportFile, tr("Unable to open \"%1\", unsupported file format").arg(info.fileName()));
return false;
}
}

if (isDdf) {
Expand Down
Loading