diff --git a/td/telegram/files/FileLocation.h b/td/telegram/files/FileLocation.h index 980840069..c6bf2eaec 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 c1a463a91..92d180652 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"); }