1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
From: Markus Koschany <apo@debian.org>
Date: Sun, 23 Jun 2019 01:50:54 +0200
Subject: really fix debian bug 930417
Bug-Upstream: https://github.com/freeorion/freeorion/issues/2406
Origin: https://github.com/freeorion/freeorion/commit/3e840f8d747fd0e6a513f3ef0278d3931f813109
---
util/SaveGamePreviewUtils.cpp | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/util/SaveGamePreviewUtils.cpp b/util/SaveGamePreviewUtils.cpp
index b9d49df..92122b1 100644
--- a/util/SaveGamePreviewUtils.cpp
+++ b/util/SaveGamePreviewUtils.cpp
@@ -65,7 +65,14 @@ namespace {
DebugLogger() << "LoadSaveGamePreviewData: Loading preview from: " << path.string();
try {
- try {
+ // read the first five letters of the stream and check if it is opening an xml file
+ std::string xxx5(5, ' ');
+ ifs.read(&xxx5[0], 5);
+ const std::string xml5{"<?xml"};
+ // reset to start of stream
+ boost::iostreams::seek(ifs, 0, std::ios_base::beg);
+ // binary deserialization iff document is not xml
+ if (xml5 != xxx5) {
ScopedTimer timer("LoadSaveGamePreviewData (binary): " + path.string(), true);
// first attempt binary deserialziation
@@ -74,12 +81,7 @@ namespace {
ia >> BOOST_SERIALIZATION_NVP(save_preview_data);
ia >> BOOST_SERIALIZATION_NVP(galaxy_setup_data);
- } catch (...) {
- // if binary deserialization failed, try more-portable XML deserialization
-
- // reset to start of stream (attempted binary serialization will have consumed some input...)
- boost::iostreams::seek(ifs, 0, std::ios_base::beg);
-
+ } else {
DebugLogger() << "Deserializing XML data";
freeorion_xml_iarchive ia(ifs);
ia >> BOOST_SERIALIZATION_NVP(save_preview_data);
|