2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 14:38:15 +00:00

Fix crash on invalid lottie file selection.

This commit is contained in:
John Preston
2019-05-30 18:09:44 +03:00
parent 325323e0b3
commit a968e112e8
3 changed files with 6 additions and 25 deletions

View File

@@ -54,28 +54,13 @@ QByteArray UnpackGzip(const QByteArray &bytes) {
} // namespace
bool ValidateFile(const QString &path) {
if (!path.endsWith(qstr(".json"), Qt::CaseInsensitive)
&& !path.endsWith(qstr(".tgs"), Qt::CaseInsensitive)) {
return false;
}
return true;
}
std::unique_ptr<Animation> FromFile(const QString &path) {
if (!path.endsWith(qstr(".json"), Qt::CaseInsensitive)
&& !path.endsWith(qstr(".tgs"), Qt::CaseInsensitive)) {
return nullptr;
}
auto f = QFile(path);
if (!f.open(QIODevice::ReadOnly)) {
return nullptr;
}
const auto content = f.readAll();
if (content.isEmpty()) {
return nullptr;
}
return FromData(std::move(content));
return FromData([&] {
auto f = QFile(path);
return (f.size() <= kMaxFileSize && f.open(QIODevice::ReadOnly))
? f.readAll()
: QByteArray();
}());
}
std::unique_ptr<Animation> FromData(const QByteArray &data) {