aboutsummaryrefslogtreecommitdiffhomepage
path: root/td/telegram/ThemeManager.cpp
diff options
context:
space:
mode:
authorlevlam <levlam@telegram.org>2023-11-27 18:40:02 +0300
committerlevlam <levlam@telegram.org>2023-11-27 18:40:02 +0300
commit16e3eb2a8a6a22957be78d4d952e1c858ffcf498 (patch)
tree188d616d5bf7e9d556e08249c67688e2b0e3fcd8 /td/telegram/ThemeManager.cpp
parent86a78f725ff15708f13cd9dcecd8a8bd35d6c5e9 (diff)
Check color validness.
Diffstat (limited to 'td/telegram/ThemeManager.cpp')
-rw-r--r--td/telegram/ThemeManager.cpp58
1 files changed, 51 insertions, 7 deletions
diff --git a/td/telegram/ThemeManager.cpp b/td/telegram/ThemeManager.cpp
index 62ddb7a33..07ec13a69 100644
--- a/td/telegram/ThemeManager.cpp
+++ b/td/telegram/ThemeManager.cpp
@@ -26,6 +26,18 @@
namespace td {
+static bool are_colors_valid(const vector<int32> &colors, size_t min_size, size_t max_size) {
+ if (min_size > colors.size() || colors.size() > max_size) {
+ return false;
+ }
+ for (auto &color : colors) {
+ if (color < 0 || color > 0xFFFFFF) {
+ return false;
+ }
+ }
+ return true;
+}
+
class GetChatThemesQuery final : public Td::ResultHandler {
Promise<telegram_api::object_ptr<telegram_api::account_Themes>> promise_;
@@ -637,6 +649,8 @@ td_api::object_ptr<td_api::updateAccentColors> ThemeManager::AccentColors::get_u
auto light_colors = it.second;
auto dark_it = dark_colors_.find(it.first);
auto dark_colors = dark_it != dark_colors_.end() ? dark_it->second : light_colors;
+ CHECK(!light_colors.empty());
+ CHECK(!dark_colors.empty());
auto first_color = light_colors[0];
int best_index = 0;
int32 best_distance = get_distance(base_colors[0], first_color);
@@ -659,6 +673,11 @@ td_api::object_ptr<td_api::updateProfileAccentColors> ThemeManager::get_update_p
return profile_accent_colors_.get_update_profile_accent_colors_object();
}
+bool ThemeManager::ProfileAccentColor::is_valid() const {
+ return are_colors_valid(palette_colors_, 1, 2) && are_colors_valid(background_colors_, 1, 2) &&
+ are_colors_valid(story_colors_, 2, 2);
+}
+
td_api::object_ptr<td_api::profileAccentColors> ThemeManager::ProfileAccentColor::get_profile_accent_colors_object()
const {
return td_api::make_object<td_api::profileAccentColors>(
@@ -822,16 +841,35 @@ void ThemeManager::on_get_accent_colors(Result<telegram_api::object_ptr<telegram
LOG(ERROR) << "Receive " << to_string(option);
continue;
}
- if (!option->hidden_) {
- accent_color_ids.push_back(accent_color_id);
- }
+ bool is_valid = true;
+ vector<int32> current_light_colors;
+ vector<int32> current_dark_colors;
if (option->colors_ != nullptr) {
auto colors = telegram_api::move_object_as<telegram_api::help_peerColorSet>(option->colors_);
- light_colors[accent_color_id] = std::move(colors->colors_);
+ current_light_colors = std::move(colors->colors_);
+ if (!are_colors_valid(current_light_colors, 1, 3)) {
+ is_valid = false;
+ }
}
if (option->dark_colors_ != nullptr) {
auto colors = telegram_api::move_object_as<telegram_api::help_peerColorSet>(option->dark_colors_);
- dark_colors[accent_color_id] = std::move(colors->colors_);
+ current_dark_colors = std::move(colors->colors_);
+ if (!are_colors_valid(current_dark_colors, 1, 3)) {
+ is_valid = false;
+ }
+ }
+ if (!is_valid) {
+ LOG(ERROR) << "Receive invalid colors for " << accent_color_id;
+ continue;
+ }
+ if (!option->hidden_) {
+ accent_color_ids.push_back(accent_color_id);
+ }
+ if (!current_light_colors.empty()) {
+ light_colors[accent_color_id] = std::move(current_light_colors);
+ }
+ if (!current_dark_colors.empty()) {
+ dark_colors[accent_color_id] = std::move(current_dark_colors);
}
}
@@ -892,11 +930,17 @@ void ThemeManager::on_get_profile_accent_colors(
LOG(ERROR) << "Receive " << to_string(option);
continue;
}
+ auto current_light_color = get_profile_accent_color(std::move(option->colors_));
+ auto current_dark_color = get_profile_accent_color(std::move(option->dark_colors_));
+ if (!current_light_color.is_valid() || !current_dark_color.is_valid()) {
+ LOG(ERROR) << "Receive invalid colors for " << accent_color_id;
+ continue;
+ }
if (!option->hidden_) {
accent_color_ids.push_back(accent_color_id);
}
- light_colors[accent_color_id] = get_profile_accent_color(std::move(option->colors_));
- dark_colors[accent_color_id] = get_profile_accent_color(std::move(option->dark_colors_));
+ light_colors[accent_color_id] = std::move(current_light_color);
+ dark_colors[accent_color_id] = std::move(current_dark_color);
}
bool is_changed = false;