Ensure that photo is not null.

This commit is contained in:
levlam 2022-06-05 22:39:03 +03:00
parent 3edf14b64e
commit 82c9d538ce

View File

@ -1193,6 +1193,9 @@ static void parse(unique_ptr<MessageContent> &content, ParserT &parser) {
is_bad = true;
}
}
if (m->photo.is_empty()) {
is_bad = true;
}
parse_caption(m->caption, parser);
content = std::move(m);
break;
@ -1776,7 +1779,8 @@ static Result<InputMessageContent> create_input_message_content(
if (file_view.has_remote_location() && !file_view.remote_location().is_web()) {
message_photo->photo.id = file_view.remote_location().get_id();
} else {
}
if (message_photo->photo.is_empty()) {
message_photo->photo.id = 0;
}
message_photo->photo.date = G()->unix_time();
@ -4933,9 +4937,13 @@ tl_object_ptr<td_api::MessageContent> get_message_content_object(const MessageCo
}
case MessageContentType::Photo: {
const auto *m = static_cast<const MessagePhoto *>(content);
return make_tl_object<td_api::messagePhoto>(
get_photo_object(td->file_manager_.get(), m->photo),
get_formatted_text_object(m->caption, skip_bot_commands, max_media_timestamp), is_content_secret);
auto photo = get_photo_object(td->file_manager_.get(), m->photo);
if (photo == nullptr) {
LOG(ERROR) << "Have empty " << m->photo;
return make_tl_object<td_api::messageExpiredPhoto>();
}
auto caption = get_formatted_text_object(m->caption, skip_bot_commands, max_media_timestamp);
return make_tl_object<td_api::messagePhoto>(std::move(photo), std::move(caption), is_content_secret);
}
case MessageContentType::Sticker: {
const auto *m = static_cast<const MessageSticker *>(content);