From 1e95bac65998513794a2be5db742adc12eb6334a Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Fri, 4 Jan 2008 20:48:03 +0000 Subject: [PATCH] BUGFIX: Catch all possible exceptions when adding a torrent to avoid crashing --- Changelog | 1 + TODO | 2 +- src/bittorrent.cpp | 16 ++++++++++++++++ src/torrentAddition.h | 21 ++++++++++++++++++++- 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/Changelog b/Changelog index ea33357ad..038b3d8b8 100644 --- a/Changelog +++ b/Changelog @@ -52,6 +52,7 @@ - BUGFIX: Fixed a crash when filtering all the files in a torrent - BUGFIX: Reload torrent only when necessary (properties) - BUGFIX: qBittorrent is not exiting anymore when a dialog is closed and main window is hidden + - BUGFIX: Catch all possible exceptions when adding a torrent to avoid crashing - BUGFIX: Search plugin update is not making the GUI freeze anymore (moved to a thread) - BUGFIX: DHT settings were not saved correctly - BUGFIX: Workaround to build on Fedora system (pkg-config problem) diff --git a/TODO b/TODO index 9caee29d8..ccbdedbc5 100644 --- a/TODO +++ b/TODO @@ -46,4 +46,4 @@ rc11 -> final? changelog: BUGFIX: Fixed systray integration when qbittorrent is launched on system startup - +BUGFIX: Catch all possible exceptions when adding a torrent to avoid crashing diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index 8f07b2838..521d60aeb 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -546,6 +546,22 @@ void bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url, bo QFile::rename(file,file+".corrupt"); } } + catch (std::exception& e) { + std::cerr << "Could not decode file, reason: " << e.what() << '\n'; + // Display warning to tell user we can't decode the torrent file + if(!from_url.isNull()) { + emit invalidTorrent(from_url); + QFile::remove(file); + }else{ + emit invalidTorrent(file); + } + if(fromScanDir) { + // Remove .corrupt file in case it already exists + QFile::remove(file+".corrupt"); + //Rename file extension so that it won't display error message more than once + QFile::rename(file,file+".corrupt"); + } + } } // Check in .priorities file if the user filtered files diff --git a/src/torrentAddition.h b/src/torrentAddition.h index ca4c865b1..d4bdc7c72 100644 --- a/src/torrentAddition.h +++ b/src/torrentAddition.h @@ -121,7 +121,8 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{ delete arb; connect(PropListModel, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(updatePriorities(QStandardItem*))); torrentContentList->expandAll(); - }catch (invalid_torrent_file&){ // Raised by torrent_info constructor + } + catch (invalid_torrent_file&){ // Raised by torrent_info constructor // Display warning to tell user we can't decode the torrent file if(!from_url.isNull()){ emit setInfoBarGUI(tr("Unable to decode torrent file:")+QString::fromUtf8(" '")+from_url+QString::fromUtf8("'"), QString::fromUtf8("red")); @@ -157,6 +158,24 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{ } close(); } + catch(std::exception& e){ + std::cerr << "Could not decode file, reason: " << e.what() << '\n'; + if(!from_url.isNull()){ + emit setInfoBarGUI(tr("Unable to decode torrent file:")+QString::fromUtf8(" '")+from_url+QString::fromUtf8("'"), QString::fromUtf8("red")); + QFile::remove(filePath); + }else{ + emit setInfoBarGUI(tr("Unable to decode torrent file:")+QString::fromUtf8(" '")+filePath+QString::fromUtf8("'"), QString::fromUtf8("red")); + } + qDebug("path is %s", filePath.toUtf8().data()); + emit setInfoBarGUI(tr("This file is either corrupted or this isn't a torrent."), QString::fromUtf8("red")); + if(fromScanDir){ + // Remove .corrupt file in case it already exists + QFile::remove(filePath+QString::fromUtf8(".corrupt")); + //Rename file extension so that it won't display error message more than once + QFile::rename(filePath,filePath+QString::fromUtf8(".corrupt")); + } + close(); + } show(); }