From d6324feafd8d138819534520f3193a5fe18a691e Mon Sep 17 00:00:00 2001 From: Jonathan White Date: Mon, 25 Mar 2019 08:40:55 -0400 Subject: [PATCH] Fix base64 check missing '/' as valid character * Issue introduced in 558cb3d * Corrects loading of legacy KeePass Key Files that included a '/' in their data section. Fix #2863 and Fix #2834 --- src/core/Tools.cpp | 2 +- tests/TestTools.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/Tools.cpp b/src/core/Tools.cpp index 09938b82a..46cde95bc 100644 --- a/src/core/Tools.cpp +++ b/src/core/Tools.cpp @@ -205,7 +205,7 @@ namespace Tools bool isBase64(const QByteArray& ba) { - constexpr auto pattern = R"(^(?:[a-z0-9+]{4})*(?:[a-z0-9+]{3}=|[a-z0-9+]{2}==)?$)"; + constexpr auto pattern = R"(^(?:[a-z0-9+/]{4})*(?:[a-z0-9+/]{3}=|[a-z0-9+/]{2}==)?$)"; QRegExp regexp(pattern, Qt::CaseInsensitive, QRegExp::RegExp2); QString base64 = QString::fromLatin1(ba.constData(), ba.size()); diff --git a/tests/TestTools.cpp b/tests/TestTools.cpp index de5a80c0a..100eb6306 100644 --- a/tests/TestTools.cpp +++ b/tests/TestTools.cpp @@ -59,6 +59,7 @@ void TestTools::testIsBase64() QVERIFY(Tools::isBase64(QByteArray("12=="))); QVERIFY(Tools::isBase64(QByteArray("abcd9876MN=="))); QVERIFY(Tools::isBase64(QByteArray("abcd9876DEFGhijkMNO="))); + QVERIFY(Tools::isBase64(QByteArray("abcd987/DEFGh+jk/NO="))); QVERIFY(not Tools::isBase64(QByteArray("abcd123=="))); QVERIFY(not Tools::isBase64(QByteArray("abc_"))); QVERIFY(not Tools::isBase64(QByteArray("123")));