Fix crash on invalid utf8 in decrypted events

This commit is contained in:
Nicolas Werner 2021-07-26 18:57:46 +02:00
parent e8e48305c8
commit 6222ae88ce
No known key found for this signature in database
GPG Key ID: C8D75E610773F2D9
1 changed files with 13 additions and 13 deletions

View File

@ -1048,24 +1048,24 @@ decryptEvent(const MegolmSessionIndex &index,
return {DecryptionErrorCode::DecryptionFailed, e.what(), std::nullopt};
}
// Add missing fields for the event.
json body = json::parse(msg_str);
body["event_id"] = event.event_id;
body["sender"] = event.sender;
body["origin_server_ts"] = event.origin_server_ts;
body["unsigned"] = event.unsigned_data;
// relations are unencrypted in content...
mtx::common::add_relations(body["content"], event.content.relations);
mtx::events::collections::TimelineEvent te;
try {
// Add missing fields for the event.
json body = json::parse(msg_str);
body["event_id"] = event.event_id;
body["sender"] = event.sender;
body["origin_server_ts"] = event.origin_server_ts;
body["unsigned"] = event.unsigned_data;
// relations are unencrypted in content...
mtx::common::add_relations(body["content"], event.content.relations);
mtx::events::collections::TimelineEvent te;
mtx::events::collections::from_json(body, te);
return {std::nullopt, std::nullopt, std::move(te.data)};
} catch (std::exception &e) {
return {DecryptionErrorCode::ParsingFailed, e.what(), std::nullopt};
}
return {std::nullopt, std::nullopt, std::move(te.data)};
}
crypto::Trust