diff options
author | Thanos Doukoudakis <thanos.doukoudakis@isode.com> | 2017-07-20 16:28:31 (GMT) |
---|---|---|
committer | Thanos Doukoudakis <thanos.doukoudakis@isode.com> | 2017-07-26 08:35:20 (GMT) |
commit | bc58d59636f28909d90464cea7ebf5eeb8f230be (patch) | |
tree | 67c77e5f10f15eb2ec6202591ed20e24cb1d9ede /Swift/Controllers/Highlighting | |
parent | 810d77181de6408d54fd3a07964317d4866c732d (diff) | |
download | swift-bc58d59636f28909d90464cea7ebf5eeb8f230be.zip swift-bc58d59636f28909d90464cea7ebf5eeb8f230be.tar.bz2 |
Workaround Boost bug to prevent crash in recents loading
Boost 1.64 introduced a regression where boost::optional deserialisation
could lead to a crash when loading the recent chats.
This fix updates the way we serialise the ChatListWindow::Chat and
HighlightAction classes to avoid these errors.
A flag has been added, to allow the use of the erroneous version of the
library during the build. During runtime if needed, the client will skip
loading the data, to avoid any unpredicted behaviour.
Test-Information:
Tested on windows 10 with different versions of boost 1.56(bundled), 1.63,
1.64, 1.65 and Ubuntu 17.04 with versions 1.56(bundled) and 1.64. Added
unit tests for the serialisation ChatListWindow::Chat class.
Change-Id: Idc5c3a6cfd92272b8eab2d77e243dda743803a31
Diffstat (limited to 'Swift/Controllers/Highlighting')
-rw-r--r-- | Swift/Controllers/Highlighting/HighlightAction.cpp | 2 | ||||
-rw-r--r-- | Swift/Controllers/Highlighting/HighlightAction.h | 56 |
2 files changed, 52 insertions, 6 deletions
diff --git a/Swift/Controllers/Highlighting/HighlightAction.cpp b/Swift/Controllers/Highlighting/HighlightAction.cpp index e9f14df..60ace42 100644 --- a/Swift/Controllers/Highlighting/HighlightAction.cpp +++ b/Swift/Controllers/Highlighting/HighlightAction.cpp @@ -12,6 +12,8 @@ #include <Swift/Controllers/Highlighting/HighlightAction.h> +BOOST_CLASS_VERSION(Swift::HighlightAction, 1) + namespace Swift { diff --git a/Swift/Controllers/Highlighting/HighlightAction.h b/Swift/Controllers/Highlighting/HighlightAction.h index da92901..d11f3ec 100644 --- a/Swift/Controllers/Highlighting/HighlightAction.h +++ b/Swift/Controllers/Highlighting/HighlightAction.h @@ -12,11 +12,14 @@ #pragma once +#include <map> +#include <memory> #include <string> #include <boost/archive/text_iarchive.hpp> #include <boost/archive/text_oarchive.hpp> #include <boost/optional.hpp> +#include <boost/serialization/map.hpp> #include <boost/serialization/optional.hpp> namespace Swift { @@ -57,12 +60,53 @@ namespace Swift { bool operator ==(const HighlightAction& a, const HighlightAction& b); bool operator !=(const HighlightAction& a, const HighlightAction& b); + template<class Archive> - void HighlightAction::serialize(Archive& ar, const unsigned int /*version*/) { - ar & frontColor_; - ar & backColor_; - ar & soundFilePath_; - ar & systemNotificaitonEnabled_; + void HighlightAction::serialize(Archive& ar, const unsigned int version) { + auto inputStream = dynamic_cast<boost::archive::text_iarchive*>(&ar); + auto outputStream = dynamic_cast<boost::archive::text_oarchive*>(&ar); + + if (version == 0) { + if (inputStream) { + const boost::archive::library_version_type BoostArchiveSkipVersion(15); + auto archiveLibraryVersion = boost::archive::BOOST_ARCHIVE_VERSION(); + //Due to https://svn.boost.org/trac10/ticket/13050 the boost::optional fields may fail to load and crash the client. Therefore we skip loading the values from previous versions. + if (archiveLibraryVersion == BoostArchiveSkipVersion && archiveLibraryVersion > inputStream->get_library_version()) { + return; + } + } + ar & frontColor_; + ar & backColor_; + ar & soundFilePath_; + ar & systemNotificaitonEnabled_; + } + else if (version == 1) { + //Using a map instead of optional values that may cause a problems when serialised with boost::archive 15 version + std::map<std::string, std::string> properties; + if (outputStream) { + if (frontColor_.is_initialized()) { + properties["frontColor"] = frontColor_.get(); + } + if (backColor_.is_initialized()) { + properties["backColor"] = backColor_.get(); + } + if (soundFilePath_.is_initialized()) { + properties["soundFilePath"] = soundFilePath_.get(); + } + } + ar & properties; + ar & systemNotificaitonEnabled_; + if (inputStream) { + if (properties.find("frontColor") != properties.end()) { + frontColor_ = properties["frontColor"]; + } + if (properties.find("backColor") != properties.end()) { + backColor_ = properties["backColor"]; + } + if (properties.find("soundFilePath") != properties.end()) { + soundFilePath_ = properties["soundFilePath"]; + } + } + } } - } |