From e9faa6d2312ee31c7f589258ba13c8ab1b7ee3ea Mon Sep 17 00:00:00 2001 From: fxliang Date: Tue, 11 Jun 2024 18:04:55 +0800 Subject: [PATCH] fix: if IPC serialization exception happens, client app would crash cause not exception handle provided. --- WeaselIPC/ContextUpdater.cpp | 2 +- WeaselIPC/Deserializer.h | 10 ++++++++++ WeaselIPC/Styler.cpp | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/WeaselIPC/ContextUpdater.cpp b/WeaselIPC/ContextUpdater.cpp index 8563b888a..8d8c2f0e0 100644 --- a/WeaselIPC/ContextUpdater.cpp +++ b/WeaselIPC/ContextUpdater.cpp @@ -73,7 +73,7 @@ void ContextUpdater::_StoreCand(Deserializer::KeyType k, std::wstringstream ss(value); boost::archive::text_wiarchive ia(ss); - ia >> cinfo; + TryDeserialize(ia, cinfo); for (auto& cand : cinfo.candies) cand.str = unescape_string(cand.str); diff --git a/WeaselIPC/Deserializer.h b/WeaselIPC/Deserializer.h index c1a1ee452..aa7d6a0f0 100644 --- a/WeaselIPC/Deserializer.h +++ b/WeaselIPC/Deserializer.h @@ -4,6 +4,16 @@ namespace weasel { +template +void TryDeserialize(boost::archive::text_wiarchive& ia, T& t) { + try { + ia >> t; + } catch (const boost::archive::archive_exception& e) { + const std::string msg = + std::string("boost::archive::archive_exception: ") + e.what(); + MessageBoxA(NULL, msg.c_str(), "IPC exception", MB_OK | MB_ICONERROR); + } +} class Deserializer { public: typedef std::vector KeyType; diff --git a/WeaselIPC/Styler.cpp b/WeaselIPC/Styler.cpp index 42698e97f..1bba12350 100644 --- a/WeaselIPC/Styler.cpp +++ b/WeaselIPC/Styler.cpp @@ -17,7 +17,7 @@ void Styler::Store(weasel::Deserializer::KeyType const& key, std::wstringstream ss(value); boost::archive::text_wiarchive ia(ss); - ia >> sty; + TryDeserialize(ia, sty); } weasel::Deserializer::Ptr Styler::Create(weasel::ResponseParser* pTarget) {