Skip to content

Commit da44e6a

Browse files
committed
fix: Fix Chinese password compression failure
Fix Chinese password compression failure Log: Fix Chinese password compression failure
1 parent e7b9c40 commit da44e6a

3 files changed

Lines changed: 14 additions & 7 deletions

File tree

3rdparty/libzipplugin/libzipplugin.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ PluginFinishType LibzipPlugin::extractFiles(const QList<FileEntry> &files, const
216216
return PFT_Cancel;
217217
} else {
218218
setPassword(query.password());
219-
zip_set_default_password(archive, m_strPassword.toUtf8().constData());
219+
QByteArray passwordBytes = passwordUnicode(m_strPassword, 0);
220+
zip_set_default_password(archive, passwordBytes.constData());
220221
lastNeedPasswordIndex = i;
221222
i--;
222223
}
@@ -269,7 +270,8 @@ PluginFinishType LibzipPlugin::extractFiles(const QList<FileEntry> &files, const
269270
return PFT_Cancel;
270271
} else {
271272
setPassword(query.password());
272-
zip_set_default_password(archive, m_strPassword.toUtf8().constData());
273+
QByteArray passwordBytes = passwordUnicode(m_strPassword, 0);
274+
zip_set_default_password(archive, passwordBytes.constData());
273275
i--;
274276
}
275277
} else {
@@ -668,12 +670,13 @@ bool LibzipPlugin::writeEntry(zip_t *archive, const QString &entry, const Compre
668670
// 设置压缩的加密算法
669671
if (options.bEncryption && !options.strEncryptionMethod.isEmpty()) { //ReadOnlyArchiveInterface::password()
670672
int ret = 0;
673+
QByteArray passwordBytes = passwordUnicode(options.strPassword, 0);
671674
if (QLatin1String("AES128") == options.strEncryptionMethod) {
672-
ret = zip_file_set_encryption(archive, uindex, ZIP_EM_AES_128, options.strPassword.toUtf8().constData());
675+
ret = zip_file_set_encryption(archive, uindex, ZIP_EM_AES_128, passwordBytes.constData());
673676
} else if (QLatin1String("AES192") == options.strEncryptionMethod) {
674-
ret = zip_file_set_encryption(archive, uindex, ZIP_EM_AES_192, options.strPassword.toUtf8().constData());
677+
ret = zip_file_set_encryption(archive, uindex, ZIP_EM_AES_192, passwordBytes.constData());
675678
} else if (QLatin1String("AES256") == options.strEncryptionMethod) {
676-
ret = zip_file_set_encryption(archive, uindex, ZIP_EM_AES_256, options.strPassword.toUtf8().constData());
679+
ret = zip_file_set_encryption(archive, uindex, ZIP_EM_AES_256, passwordBytes.constData());
677680
}
678681
if (ret != 0) {
679682
emit error(("Failed to set compression options for entry: %1"));

3rdparty/libzipplugin/libzipplugin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ class LibzipPlugin : public ReadWriteArchiveInterface
198198
QMap<QString, int> m_mapRealDirValue; // 长文件真实文件统计
199199
QSet<QString> m_setLongName; // 存储被截取之后的文件名称(包含001之类的)
200200
bool m_bLnfs = false; //文件系统是否支持长文件
201+
QByteArray m_passwordData; // 存储编码后的密码数据,确保在压缩过程中保持有效
201202
};
202203

203204
#endif // LIBZIPPLUGIN_H

src/source/mainwindow.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,8 +1269,11 @@ void MainWindow::slotCompress(const QVariant &val)
12691269
// 判断zip格式是否使用了中文加密
12701270
bool zipPasswordIsChinese = false;
12711271
if ("application/zip" == m_stCompressParameter.strMimeType) {
1272-
if (m_stCompressParameter.strPassword.contains(REG_EXP("[\\x4e00-\\x9fa5]+"))) {
1273-
zipPasswordIsChinese = true;
1272+
for (const QChar &ch : m_stCompressParameter.strPassword) {
1273+
if (ch.unicode() >= 0x4E00 && ch.unicode() <= 0x9FA5) {
1274+
zipPasswordIsChinese = true;
1275+
break;
1276+
}
12741277
}
12751278
}
12761279

0 commit comments

Comments
 (0)