Commit 8a69e75b authored by Volker Krause's avatar Volker Krause
Browse files

Add workarounds for known JSON syntax errors in pass.json

It seems we even have to expect invalid JSON in here, despite the signing
and validation tools that are presumably used to produce those...

CCBUG: 428358
parent e4a7d06f
Pipeline #39015 passed with stage
in 2 minutes and 43 seconds
......@@ -23,6 +23,7 @@
#include <QTextCodec>
#include <QImage>
#include <QUrl>
#include <QRegularExpression>
using namespace KPkPass;
......@@ -180,10 +181,20 @@ Pass *PassPrivate::fromData(std::unique_ptr<QIODevice> device, QObject *parent)
std::unique_ptr<QIODevice> dev(file->createDevice());
QJsonParseError error;
const auto passObj = QJsonDocument::fromJson(dev->readAll(), &error).object();
const auto data = dev->readAll();
auto passObj = QJsonDocument::fromJson(data, &error).object();
if (error.error != QJsonParseError::NoError) {
qCWarning(Log) << "Error parsing pass.json:" << error.errorString();
return nullptr;
qCWarning(Log) << "Error parsing pass.json:" << error.errorString() << error.offset;
// try to fix some known JSON syntax errors
auto s = QString::fromUtf8(data);
s.replace(QRegularExpression(QStringLiteral(R"(\}[\s\n]*,[\s\n]*\})")), QStringLiteral("}}"));
s.replace(QRegularExpression(QStringLiteral(R"(\][\s\n]*,[\s\n]*\})")), QStringLiteral("]}"));
passObj = QJsonDocument::fromJson(s.toUtf8(), &error).object();
if (error.error != QJsonParseError::NoError) {
qCWarning(Log) << "JSON syntax workarounds didn't help either:" << error.errorString() << error.offset;
return nullptr;
if (passObj.value(QLatin1String("formatVersion")).toInt() > 1) {
qCWarning(Log) << "pass.json has unsupported format version!";
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment