diff options
author | saturneric <[email protected]> | 2024-01-29 09:57:41 +0000 |
---|---|---|
committer | saturneric <[email protected]> | 2024-01-29 09:57:41 +0000 |
commit | dfd95b751d44a749d6f2cb7edf941f978cb93ccb (patch) | |
tree | 92ce44eec39dc84b8d1bcce256327d53f751b02f /src/ui/UserInterfaceUtils.cpp | |
parent | fix: slove some discovered issues on windows (diff) | |
download | GpgFrontend-dfd95b751d44a749d6f2cb7edf941f978cb93ccb.tar.gz GpgFrontend-dfd95b751d44a749d6f2cb7edf941f978cb93ccb.zip |
fix: solve reported issues
Diffstat (limited to 'src/ui/UserInterfaceUtils.cpp')
-rw-r--r-- | src/ui/UserInterfaceUtils.cpp | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/src/ui/UserInterfaceUtils.cpp b/src/ui/UserInterfaceUtils.cpp index b915b5ab..c66b9845 100644 --- a/src/ui/UserInterfaceUtils.cpp +++ b/src/ui/UserInterfaceUtils.cpp @@ -28,6 +28,8 @@ #include "UserInterfaceUtils.h" +#include <cstddef> + #include "core/GpgConstants.h" #include "core/function/CoreSignalStation.h" #include "core/function/gpg/GpgKeyGetter.h" @@ -273,19 +275,25 @@ void CommonUtils::SlotImportKeys(QWidget *parent, const QString &in_buffer) { } void CommonUtils::SlotImportKeyFromFile(QWidget *parent) { - auto file_name = QFileDialog::getOpenFileName(this, tr("Open Key"), QString(), - tr("Key Files")) + - " (*.asc *.txt);;" + tr("Keyring files") + - " (*.gpg);;All Files (*)"; - if (!file_name.isNull()) { - QByteArray key_buffer; - if (!ReadFile(file_name, key_buffer)) { - QMessageBox::critical(nullptr, tr("File Open Failed"), - tr("Failed to open file: ") + file_name); - return; - } - SlotImportKeys(parent, key_buffer); + auto file_name = + QFileDialog::getOpenFileName(parent, tr("Open Key"), QString(), + tr("Keyring files") + " (*.asc *.gpg)"); + if (file_name.isEmpty()) return; + + QFileInfo file_info(file_name); + if (file_info.size() > static_cast<qint64>(1024 * 1024)) { + QMessageBox::critical(parent, tr("Error"), + tr("The target file is too large for a keyring.")); + return; + } + + QByteArray key_buffer; + if (!ReadFile(file_name, key_buffer)) { + QMessageBox::critical(nullptr, tr("File Open Failed"), + tr("Failed to open file: ") + file_name); + return; } + SlotImportKeys(parent, key_buffer); } void CommonUtils::SlotImportKeyFromKeyServer(QWidget *parent) { |