Prevent loading of foreign files

This commit is contained in:
mandlm 2019-01-30 20:41:22 +01:00
parent 531554d124
commit f3249b8720

View File

@ -46,10 +46,14 @@ void DataModel::write(const QString &filename) const
QFile outFile(filename); QFile outFile(filename);
if (!outFile.open(QIODevice::WriteOnly)) 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) void DataModel::read(const QString &filename)
@ -57,11 +61,15 @@ void DataModel::read(const QString &filename)
QFile inFile(filename); QFile inFile(filename);
if (!inFile.open(QIODevice::ReadOnly)) if (!inFile.open(QIODevice::ReadOnly))
{ {
throw std::runtime_error("open failed"); throw std::runtime_error("failed to read file");
} }
ESGRAF48::DataModel dataModel; 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_metaData.read(dataModel.metadata());
m_v2Svk.read(dataModel.v2svk()); m_v2Svk.read(dataModel.v2svk());