51 lines
1.9 KiB
Diff
51 lines
1.9 KiB
Diff
|
From 0e8493e24281d393cb08da3d13e55276f4578fd5 Mon Sep 17 00:00:00 2001
|
||
|
From: David Edmundson <kde@davidedmundson.co.uk>
|
||
|
Date: Fri, 17 Sep 2021 23:44:05 +0100
|
||
|
Subject: [PATCH 07/11] [Klipper] Guard against broken data fetches
|
||
|
|
||
|
QMimeData::data() can fail. Fetching is done on demand. It's also
|
||
|
possible for clients to advertise mimedata they don't really have.
|
||
|
|
||
|
This patch avoids putting those broken entries in klipper's history.
|
||
|
|
||
|
|
||
|
(cherry picked from commit 22ff0818cdd64ec205c084ffb1483d8635b8e5d7)
|
||
|
---
|
||
|
klipper/historyitem.cpp | 12 +++++++++++-
|
||
|
1 file changed, 11 insertions(+), 1 deletion(-)
|
||
|
|
||
|
diff --git a/klipper/historyitem.cpp b/klipper/historyitem.cpp
|
||
|
index fd0a5ad33..7ee2496f3 100644
|
||
|
--- a/klipper/historyitem.cpp
|
||
|
+++ b/klipper/historyitem.cpp
|
||
|
@@ -30,15 +30,25 @@ HistoryItemPtr HistoryItem::create(const QMimeData *data)
|
||
|
if (data->hasUrls()) {
|
||
|
KUrlMimeData::MetaDataMap metaData;
|
||
|
QList<QUrl> urls = KUrlMimeData::urlsFromMimeData(data, KUrlMimeData::PreferKdeUrls, &metaData);
|
||
|
+ if (urls.isEmpty()) {
|
||
|
+ return HistoryItemPtr();
|
||
|
+ }
|
||
|
QByteArray bytes = data->data(QStringLiteral("application/x-kde-cutselection"));
|
||
|
bool cut = !bytes.isEmpty() && (bytes.at(0) == '1'); // true if 1
|
||
|
return HistoryItemPtr(new HistoryURLItem(urls, metaData, cut));
|
||
|
}
|
||
|
if (data->hasText()) {
|
||
|
+ const QString text = data->text();
|
||
|
+ if (text.isEmpty()) { // reading mime data can fail. Avoid ghost entries
|
||
|
+ return HistoryItemPtr();
|
||
|
+ }
|
||
|
return HistoryItemPtr(new HistoryStringItem(data->text()));
|
||
|
}
|
||
|
if (data->hasImage()) {
|
||
|
- QImage image = qvariant_cast<QImage>(data->imageData());
|
||
|
+ const QImage image = qvariant_cast<QImage>(data->imageData());
|
||
|
+ if (image.isNull()) {
|
||
|
+ return HistoryItemPtr();
|
||
|
+ }
|
||
|
return HistoryItemPtr(new HistoryImageItem(QPixmap::fromImage(image)));
|
||
|
}
|
||
|
|
||
|
--
|
||
|
2.33.0
|
||
|
|