Add PhotoSizeSource file_type checks.

GitOrigin-RevId: e2b79fa71a2547ea5f065bc94691f28a6fe3d904
This commit is contained in:
levlam 2019-06-20 03:51:37 +03:00
parent 5022fa26aa
commit 9675331eaa
2 changed files with 39 additions and 12 deletions

View File

@ -393,7 +393,7 @@ class FullRemoteFileLocation {
tl_object_ptr<telegram_api::InputFileLocation> as_input_file_location() const { tl_object_ptr<telegram_api::InputFileLocation> as_input_file_location() const {
switch (location_type()) { switch (location_type()) {
case LocationType::Photo: { case LocationType::Photo:
switch (photo().source_.get_type()) { switch (photo().source_.get_type()) {
case PhotoSizeSource::Type::Legacy: case PhotoSizeSource::Type::Legacy:
return make_tl_object<telegram_api::inputFileLocation>( return make_tl_object<telegram_api::inputFileLocation>(
@ -410,7 +410,7 @@ class FullRemoteFileLocation {
photo().id_, photo().access_hash_, BufferSlice(file_reference_), photo().id_, photo().access_hash_, BufferSlice(file_reference_),
std::string(1, static_cast<char>(narrow_cast<uint8>(thumbnail.thumbnail_type)))); std::string(1, static_cast<char>(narrow_cast<uint8>(thumbnail.thumbnail_type))));
default: default:
UNREACHABLE(); break;
} }
} }
case PhotoSizeSource::Type::DialogPhoto: { case PhotoSizeSource::Type::DialogPhoto: {
@ -424,8 +424,11 @@ class FullRemoteFileLocation {
return make_tl_object<telegram_api::inputStickerSetThumb>(sticker_set_thumbnail.get_input_sticker_set(), return make_tl_object<telegram_api::inputStickerSetThumb>(sticker_set_thumbnail.get_input_sticker_set(),
photo().volume_id_, photo().local_id_); photo().volume_id_, photo().local_id_);
} }
default:
break;
} }
} UNREACHABLE();
return nullptr;
case LocationType::Common: case LocationType::Common:
if (is_encrypted_secret()) { if (is_encrypted_secret()) {
return make_tl_object<telegram_api::inputEncryptedFileLocation>(common().id_, common().access_hash_); return make_tl_object<telegram_api::inputEncryptedFileLocation>(common().id_, common().access_hash_);

View File

@ -148,21 +148,45 @@ void FullRemoteFileLocation::parse(ParserT &parser) {
} }
switch (location_type()) { switch (location_type()) {
case LocationType::Web: { case LocationType::Web:
variant_ = WebRemoteFileLocation(); variant_ = WebRemoteFileLocation();
return web().parse(parser); return web().parse(parser);
} case LocationType::Photo:
case LocationType::Photo: {
variant_ = PhotoRemoteFileLocation(); variant_ = PhotoRemoteFileLocation();
return photo().parse(parser); photo().parse(parser);
if (parser.get_error() != nullptr) {
return;
} }
case LocationType::Common: { switch (photo().source_.get_type()) {
variant_ = CommonRemoteFileLocation(); case PhotoSizeSource::Type::Legacy:
return common().parse(parser); 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");
} }
case LocationType::None: { 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; break;
} }
return;
case LocationType::Common:
variant_ = CommonRemoteFileLocation();
return common().parse(parser);
case LocationType::None:
break;
} }
parser.set_error("Invalid FileType in FullRemoteFileLocation"); parser.set_error("Invalid FileType in FullRemoteFileLocation");
} }