From 39a02e649d88ba226340607c5d92768b615d24f7 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 2 May 2022 15:36:34 +0400 Subject: [PATCH] Fix crash on invalid data in local cache. --- Telegram/SourceFiles/storage/serialize_document.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Telegram/SourceFiles/storage/serialize_document.cpp b/Telegram/SourceFiles/storage/serialize_document.cpp index 50e4c51ac..fef3bdd21 100644 --- a/Telegram/SourceFiles/storage/serialize_document.cpp +++ b/Telegram/SourceFiles/storage/serialize_document.cpp @@ -150,14 +150,17 @@ DocumentData *Document::readFromStreamHelper( } } - const auto storage = std::get_if( - &thumb->file().data); if ((stream.status() != QDataStream::Ok) || (!dc && !access) || !thumb - || !videoThumb - || (thumb->valid() - && (!storage || !storage->isDocumentThumbnail()))) { + || !videoThumb) { + stream.setStatus(QDataStream::ReadCorruptData); + return nullptr; + } + const auto storage = std::get_if( + &thumb->file().data); + if (thumb->valid() + && (!storage || !storage->isDocumentThumbnail())) { stream.setStatus(QDataStream::ReadCorruptData); // We can't convert legacy thumbnail location to modern, because // size letter ('s' or 'm') is lost, it was not saved in legacy.