fix: prevent BOM character loss in path concatenation#320
Conversation
Use std::string for directory path concatenation to avoid QString's normalization of UTF-8 BOM (U+FEFF / zero-width no-break space). 使用 std::string 进行路径拼接,避免 QString 对 UTF-8 BOM (零宽不换行空格) 的规范化导致字节丢失。 Log: 修复路径拼接时 BOM 字符丢失的问题 Bug: https://pms.uniontech.com//bug-view-367075.html Influence: 修复后包含 BOM/零宽不换行空格的路径能正确拼接,避免文件操作失败。
There was a problem hiding this comment.
Sorry @liyigang1, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
deepin pr auto review★ 总体评分:100分■ 【总体评价】
■ 【详细分析】
■ 【改进建议代码示例】 QUrl DEnumeratorPrivate::buildUrl(const QUrl &url, const char *fileName)
{
// 防御空指针,避免std::string或QByteArray构造时崩溃
if (!fileName) {
return QUrl();
}
// 拦截路径遍历攻击,防止恶意文件名越权
QByteArray fileNameBa(fileName);
// 优化:精确匹配".."或以"../"开头的遍历序列,避免误杀"..foo"等合法文件名
if (fileNameBa == ".." || fileNameBa.startsWith("../") || fileNameBa.startsWith("..\\")) {
return QUrl();
}
QByteArray path;
QString urlPath = url.path();
if (urlPath == "/" || urlPath.isEmpty()) {
path = QByteArray("/") + fileNameBa;
} else {
QByteArray dirPath = urlPath.toUtf8();
if (!dirPath.endsWith('/')) {
dirPath.append('/');
}
// 使用QByteArray进行底层字节数组拼接,避免QString剥离BOM (efbbbf)
path = dirPath + fileNameBa;
}
// 保留原始 URL 的 scheme 和 host,而不是假定为本地文件
// ... 后续逻辑
} |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: liyigang1, 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 |
|
/forcemerge |
Use std::string for directory path concatenation to avoid QString's normalization of UTF-8 BOM (U+FEFF / zero-width no-break space).
使用 std::string 进行路径拼接,避免 QString 对 UTF-8 BOM
(零宽不换行空格) 的规范化导致字节丢失。
Log: 修复路径拼接时 BOM 字符丢失的问题
Bug: https://pms.uniontech.com//bug-view-367075.html
Influence: 修复后包含 BOM/零宽不换行空格的路径能正确拼接,避免文件操作失败。