From 7c8d475d24627999a0705f226f5e3243e11f7bb9 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Tue, 12 Jun 2018 19:23:30 +0200 Subject: [PATCH] Do not crash if the zim file is invalid or corrupted. --- kiwixapp.cpp | 6 +++++- kiwixschemehandler.cpp | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/kiwixapp.cpp b/kiwixapp.cpp index 060282c..7732617 100644 --- a/kiwixapp.cpp +++ b/kiwixapp.cpp @@ -19,7 +19,11 @@ void KiwixApp::openZimFile(const QString &zimfile) delete reader; const std::string zimfile_ = zimfile.toLocal8Bit().constData(); std::cout << "Opening " << zimfile_ << std::endl; - reader = new kiwix::Reader(zimfile_); + try { + reader = new kiwix::Reader(zimfile_); + } catch (...) { + reader = nullptr; + } } kiwix::Reader* KiwixApp::getReader() diff --git a/kiwixschemehandler.cpp b/kiwixschemehandler.cpp index c4d6b39..d4b1013 100644 --- a/kiwixschemehandler.cpp +++ b/kiwixschemehandler.cpp @@ -20,6 +20,10 @@ KiwixSchemeHandler::requestStarted(QWebEngineUrlRequestJob *request) zim::Article art; std::cout << "Url is " << url << std::endl; auto reader = static_cast(KiwixApp::instance())->getReader(); + if ( reader == nullptr) { + request->fail(QWebEngineUrlRequestJob::UrlNotFound); + return; + } if ( !reader->getArticleObjectByDecodedUrl(url, art)) { url = "A/" + url;