From f3249b8720dde82149e6344a08e0f38d0d5fb2c1 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Wed, 30 Jan 2019 20:41:22 +0100 Subject: [PATCH] Prevent loading of foreign files --- source/DataModel.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/source/DataModel.cpp b/source/DataModel.cpp index eef2e2f..0b94963 100644 --- a/source/DataModel.cpp +++ b/source/DataModel.cpp @@ -46,10 +46,14 @@ void DataModel::write(const QString &filename) const QFile outFile(filename); if (!outFile.open(QIODevice::WriteOnly)) { - throw std::runtime_error("open failed"); + throw std::runtime_error("failed to open file"); } - dataModel.SerializeToFileDescriptor(outFile.handle()); + bool success = dataModel.SerializeToFileDescriptor(outFile.handle()); + if (success == false) + { + throw std::runtime_error("filed to write file"); + } } void DataModel::read(const QString &filename) @@ -57,11 +61,15 @@ void DataModel::read(const QString &filename) QFile inFile(filename); if (!inFile.open(QIODevice::ReadOnly)) { - throw std::runtime_error("open failed"); + throw std::runtime_error("failed to read file"); } ESGRAF48::DataModel dataModel; - dataModel.ParseFromFileDescriptor(inFile.handle()); + bool success = dataModel.ParseFromFileDescriptor(inFile.handle()); + if (success == false) + { + throw std::runtime_error("invalid file format"); + } m_metaData.read(dataModel.metadata()); m_v2Svk.read(dataModel.v2svk());