From 3f1182691861e0ea68971431aeb87f06904819d1 Mon Sep 17 00:00:00 2001 From: xiaoyifang Date: Sun, 9 Jan 2022 11:36:48 +0800 Subject: [PATCH] fix: invalid bres url may cause webengine to crash. such as bres://upload.wikimedia.org/wikipedia/commons/2/23/Icons-mini-file_acrobat.gif --- articleview.cc | 2 +- resourceschemehandler.cpp | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/articleview.cc b/articleview.cc index 2541643b..e41c5b6a 100644 --- a/articleview.cc +++ b/articleview.cc @@ -518,7 +518,7 @@ void ArticleView::loadFinished( bool ) { setZoomFactor(cfg.preferences.zoomFactor); QUrl url = ui.definition->url(); - qDebug() << "article view loaded url:" << url; + qDebug() << "article view loaded url:" << url.url ().left (200); QVariant userDataVariant = ui.definition->property("currentArticle"); diff --git a/resourceschemehandler.cpp b/resourceschemehandler.cpp index 40cdcb3f..fa266dcb 100644 --- a/resourceschemehandler.cpp +++ b/resourceschemehandler.cpp @@ -8,16 +8,18 @@ void ResourceSchemeHandler::requestStarted(QWebEngineUrlRequestJob *requestJob) QUrl url = requestJob->requestUrl(); QNetworkRequest request; - request.setUrl( url ); - + request.setUrl(url); QNetworkReply *reply = this->mManager.createRequest(QNetworkAccessManager::GetOperation, request, NULL); - connect(reply, &QNetworkReply::finished, requestJob, [=]() { if (reply->error() == QNetworkReply::ContentNotFoundError) { requestJob->fail(QWebEngineUrlRequestJob::UrlNotFound); return; } - qDebug() << "resource scheme handler receive finished signal:" << reply->request().url(); + if (reply->error() != QNetworkReply::NoError) { + qDebug() << "resource handler failed:" << reply->error() << ":" << reply->request().url(); + requestJob->fail(QWebEngineUrlRequestJob::RequestFailed); + return; + } QMimeType mineType = db.mimeTypeForUrl(url); QString contentType = mineType.name(); // Reply segment