From a90dd653af8021bbb73cc2833b93d26c2b8e8e03 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 26 May 2022 17:13:31 +0300 Subject: [PATCH] Avoid logging to error if invalid dimensions were provided by app. --- td/telegram/MessageContent.cpp | 24 +++++++++++------------- td/telegram/Payments.cpp | 3 +-- td/telegram/Photo.cpp | 2 +- td/telegram/PhotoSize.cpp | 6 ++++-- td/telegram/StickersManager.cpp | 3 +-- 5 files changed, 18 insertions(+), 20 deletions(-) diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index d48ad794e..8f6bbc49a 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -1723,7 +1723,7 @@ static Result 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(file_id, std::move(caption)); break; @@ -1792,7 +1792,7 @@ static Result 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(file_view.size()); s.file_id = file_id; @@ -1815,10 +1815,9 @@ static Result 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(file_id); break; @@ -1829,11 +1828,10 @@ static Result 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(file_id, std::move(caption)); break; @@ -1847,7 +1845,7 @@ static Result 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(file_id, false); break; @@ -2083,7 +2081,7 @@ Result 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()); diff --git a/td/telegram/Payments.cpp b/td/telegram/Payments.cpp index 96ef21013..82ebb7888 100644 --- a/td/telegram/Payments.cpp +++ b/td/telegram/Payments.cpp @@ -734,8 +734,7 @@ Result 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; diff --git a/td/telegram/Photo.cpp b/td/telegram/Photo.cpp index f0d733eec..e4db76724 100644 --- a/td/telegram/Photo.cpp +++ b/td/telegram/Photo.cpp @@ -267,7 +267,7 @@ Photo get_encrypted_file_photo(FileManager *file_manager, unique_ptrw_, 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); diff --git a/td/telegram/PhotoSize.cpp b/td/telegram/PhotoSize.cpp index 4772c4d39..6c8af6d0f 100644 --- a/td/telegram/PhotoSize.cpp +++ b/td/telegram/PhotoSize.cpp @@ -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(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(bytes.size()); // generate some random remote location to save diff --git a/td/telegram/StickersManager.cpp b/td/telegram/StickersManager.cpp index 819a65d86..6d2dd91cd 100644 --- a/td/telegram/StickersManager.cpp +++ b/td/telegram/StickersManager.cpp @@ -5647,8 +5647,7 @@ Result> 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 {