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 {
switch (location_type()) {
case LocationType::Photo: {
case LocationType::Photo:
switch (photo().source_.get_type()) {
case PhotoSizeSource::Type::Legacy:
return make_tl_object<telegram_api::inputFileLocation>(
@ -410,7 +410,7 @@ class FullRemoteFileLocation {
photo().id_, photo().access_hash_, BufferSlice(file_reference_),
std::string(1, static_cast<char>(narrow_cast<uint8>(thumbnail.thumbnail_type))));
default:
UNREACHABLE();
break;
}
}
case PhotoSizeSource::Type::DialogPhoto: {
@ -424,8 +424,11 @@ class FullRemoteFileLocation {
return make_tl_object<telegram_api::inputStickerSetThumb>(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<telegram_api::inputEncryptedFileLocation>(common().id_, common().access_hash_);

View File

@ -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");
}