Avoid logging to error if invalid dimensions were provided by app.

This commit is contained in:
levlam 2022-05-26 17:13:31 +03:00
parent 83b7be1af9
commit a90dd653af
5 changed files with 18 additions and 20 deletions

View File

@ -1723,7 +1723,7 @@ static Result<InputMessageContent> create_input_message_content(
td->animations_manager_->create_animation(
file_id, string(), thumbnail, AnimationSize(), has_stickers, std::move(sticker_file_ids),
std::move(file_name), std::move(mime_type), input_animation->duration_,
get_dimensions(input_animation->width_, input_animation->height_, "inputMessageAnimation"), false);
get_dimensions(input_animation->width_, input_animation->height_, nullptr), false);
content = make_unique<MessageAnimation>(file_id, std::move(caption));
break;
@ -1792,7 +1792,7 @@ static Result<InputMessageContent> create_input_message_content(
PhotoSize s;
s.type = type;
s.dimensions = get_dimensions(input_photo->width_, input_photo->height_, "inputMessagePhoto");
s.dimensions = get_dimensions(input_photo->width_, input_photo->height_, nullptr);
s.size = static_cast<int32>(file_view.size());
s.file_id = file_id;
@ -1815,10 +1815,9 @@ static Result<InputMessageContent> create_input_message_content(
emoji = std::move(input_sticker->emoji_);
td->stickers_manager_->create_sticker(
file_id, string(), thumbnail,
get_dimensions(input_sticker->width_, input_sticker->height_, "inputMessageSticker"), nullptr,
StickerFormat::Unknown, nullptr);
td->stickers_manager_->create_sticker(file_id, string(), thumbnail,
get_dimensions(input_sticker->width_, input_sticker->height_, nullptr),
nullptr, StickerFormat::Unknown, nullptr);
content = make_unique<MessageSticker>(file_id);
break;
@ -1829,11 +1828,10 @@ static Result<InputMessageContent> create_input_message_content(
ttl = input_video->ttl_;
bool has_stickers = !sticker_file_ids.empty();
td->videos_manager_->create_video(file_id, string(), thumbnail, AnimationSize(), has_stickers,
std::move(sticker_file_ids), std::move(file_name), std::move(mime_type),
input_video->duration_,
get_dimensions(input_video->width_, input_video->height_, "inputMessageVideo"),
input_video->supports_streaming_, false);
td->videos_manager_->create_video(
file_id, string(), thumbnail, AnimationSize(), has_stickers, std::move(sticker_file_ids),
std::move(file_name), std::move(mime_type), input_video->duration_,
get_dimensions(input_video->width_, input_video->height_, nullptr), input_video->supports_streaming_, false);
content = make_unique<MessageVideo>(file_id, std::move(caption));
break;
@ -1847,7 +1845,7 @@ static Result<InputMessageContent> create_input_message_content(
}
td->video_notes_manager_->create_video_note(file_id, string(), thumbnail, input_video_note->duration_,
get_dimensions(length, length, "inputMessageVideoNote"), false);
get_dimensions(length, length, nullptr), false);
content = make_unique<MessageVideoNote>(file_id, false);
break;
@ -2083,7 +2081,7 @@ Result<InputMessageContent> get_input_message_content(
LOG(WARNING) << "Ignore thumbnail file: " << r_thumbnail_file_id.error().message();
} else {
thumbnail.type = 't';
thumbnail.dimensions = get_dimensions(input_thumbnail->width_, input_thumbnail->height_, "inputThumbnail");
thumbnail.dimensions = get_dimensions(input_thumbnail->width_, input_thumbnail->height_, nullptr);
thumbnail.file_id = r_thumbnail_file_id.ok();
CHECK(thumbnail.file_id.is_valid());

View File

@ -734,8 +734,7 @@ Result<InputInvoice> process_input_message_invoice(
PhotoSize s;
s.type = 'n';
s.dimensions =
get_dimensions(input_invoice->photo_width_, input_invoice->photo_height_, "process_input_message_invoice");
s.dimensions = get_dimensions(input_invoice->photo_width_, input_invoice->photo_height_, nullptr);
s.size = input_invoice->photo_size_; // TODO use invoice_file_id size
s.file_id = invoice_file_id;

View File

@ -267,7 +267,7 @@ Photo get_encrypted_file_photo(FileManager *file_manager, unique_ptr<EncryptedFi
PhotoSize s;
s.type = 'i';
s.dimensions = get_dimensions(photo->w_, photo->h_, "get_encrypted_file_photo");
s.dimensions = get_dimensions(photo->w_, photo->h_, nullptr);
s.size = photo->size_;
s.file_id = file_id;
res.photos.push_back(s);

View File

@ -24,7 +24,9 @@ namespace td {
static uint16 get_dimension(int32 size, const char *source) {
if (size < 0 || size > 65535) {
LOG(ERROR) << "Wrong image dimension = " << size << " from " << source;
if (source != nullptr) {
LOG(ERROR) << "Wrong image dimension = " << size << " from " << source;
}
return 0;
}
return narrow_cast<uint16>(size);
@ -175,7 +177,7 @@ PhotoSize get_secret_thumbnail_photo_size(FileManager *file_manager, BufferSlice
}
PhotoSize res;
res.type = 't';
res.dimensions = get_dimensions(width, height, "get_secret_thumbnail_photo_size");
res.dimensions = get_dimensions(width, height, nullptr);
res.size = narrow_cast<int32>(bytes.size());
// generate some random remote location to save

View File

@ -5647,8 +5647,7 @@ Result<std::tuple<FileId, bool, bool, StickerFormat>> StickersManager::prepare_i
if (format == StickerFormat::Tgs) {
int32 width = for_thumbnail ? 100 : 512;
create_sticker(file_id, string(), PhotoSize(), get_dimensions(width, width, "prepare_input_file"), nullptr, format,
nullptr);
create_sticker(file_id, string(), PhotoSize(), get_dimensions(width, width, nullptr), nullptr, format, nullptr);
} else if (format == StickerFormat::Webm) {
td_->documents_manager_->create_document(file_id, string(), PhotoSize(), "sticker.webm", "video/webm", false);
} else {