From 9675331eaa0fa81c36de83ab2c2f8e85c3a66c06 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 20 Jun 2019 03:51:37 +0300 Subject: [PATCH] Add PhotoSizeSource file_type checks. GitOrigin-RevId: e2b79fa71a2547ea5f065bc94691f28a6fe3d904 --- td/telegram/files/FileLocation.h | 9 ++++--- td/telegram/files/FileLocation.hpp | 42 +++++++++++++++++++++++------- 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/td/telegram/files/FileLocation.h b/td/telegram/files/FileLocation.h index 98084006..c6bf2eae 100644 --- a/td/telegram/files/FileLocation.h +++ b/td/telegram/files/FileLocation.h @@ -393,7 +393,7 @@ class FullRemoteFileLocation { tl_object_ptr as_input_file_location() const { switch (location_type()) { - case LocationType::Photo: { + case LocationType::Photo: switch (photo().source_.get_type()) { case PhotoSizeSource::Type::Legacy: return make_tl_object( @@ -410,7 +410,7 @@ class FullRemoteFileLocation { photo().id_, photo().access_hash_, BufferSlice(file_reference_), std::string(1, static_cast(narrow_cast(thumbnail.thumbnail_type)))); default: - UNREACHABLE(); + break; } } case PhotoSizeSource::Type::DialogPhoto: { @@ -424,8 +424,11 @@ class FullRemoteFileLocation { return make_tl_object(sticker_set_thumbnail.get_input_sticker_set(), photo().volume_id_, photo().local_id_); } + default: + break; } - } + UNREACHABLE(); + return nullptr; case LocationType::Common: if (is_encrypted_secret()) { return make_tl_object(common().id_, common().access_hash_); diff --git a/td/telegram/files/FileLocation.hpp b/td/telegram/files/FileLocation.hpp index c1a463a9..92d18065 100644 --- a/td/telegram/files/FileLocation.hpp +++ b/td/telegram/files/FileLocation.hpp @@ -148,21 +148,45 @@ void FullRemoteFileLocation::parse(ParserT &parser) { } switch (location_type()) { - case LocationType::Web: { + case LocationType::Web: variant_ = WebRemoteFileLocation(); return web().parse(parser); - } - case LocationType::Photo: { + case LocationType::Photo: variant_ = PhotoRemoteFileLocation(); - return photo().parse(parser); - } - case LocationType::Common: { + photo().parse(parser); + if (parser.get_error() != nullptr) { + return; + } + switch (photo().source_.get_type()) { + case PhotoSizeSource::Type::Legacy: + break; + case PhotoSizeSource::Type::Thumbnail: + if (photo().source_.get_file_type() != file_type_ || + (file_type_ != FileType::Photo && file_type_ != FileType::Thumbnail && + file_type_ != FileType::EncryptedThumbnail)) { + parser.set_error("Invalid FileType in PhotoRemoteFileLocation Thumbnail"); + } + break; + case PhotoSizeSource::Type::DialogPhoto: + if (file_type_ != FileType::ProfilePhoto) { + parser.set_error("Invalid FileType in PhotoRemoteFileLocation DialogPhoto"); + } + break; + case PhotoSizeSource::Type::StickerSetThumbnail: + if (file_type_ != FileType::Thumbnail) { + parser.set_error("Invalid FileType in PhotoRemoteFileLocation StickerSetThumbnail"); + } + break; + default: + UNREACHABLE(); + break; + } + return; + case LocationType::Common: variant_ = CommonRemoteFileLocation(); return common().parse(parser); - } - case LocationType::None: { + case LocationType::None: break; - } } parser.set_error("Invalid FileType in FullRemoteFileLocation"); }