Add sanity checks for polls voter count.

GitOrigin-RevId: dba4406f261609a78f4eddd32b93e94793fecc7b
This commit is contained in:
levlam 2019-02-25 00:00:17 +03:00
parent 812398ae7b
commit e27354bf8a

View File

@ -723,6 +723,10 @@ PollId PollManager::on_get_poll(PollId poll_id, tl_object_ptr<telegram_api::poll
if ((poll_results->flags_ & telegram_api::pollResults::TOTAL_VOTERS_MASK) != 0 &&
poll_results->total_voters_ != poll->total_voter_count) {
poll->total_voter_count = poll_results->total_voters_;
if (poll->total_voter_count < 0) {
LOG(ERROR) << "Receive " << poll->total_voter_count << " voters in " << poll_id;
poll->total_voter_count = 0;
}
is_changed = true;
}
for (auto &poll_result : poll_results->results_) {
@ -740,6 +744,19 @@ PollId PollManager::on_get_poll(PollId poll_id, tl_object_ptr<telegram_api::poll
}
if (poll_result->voters_ != option.voter_count) {
option.voter_count = poll_result->voters_;
if (option.voter_count < 0) {
LOG(ERROR) << "Receive " << option.voter_count << " voters for an option in " << poll_id;
option.voter_count = 0;
}
if (option.is_chosen && option.voter_count == 0) {
LOG(ERROR) << "Receive 0 voters for the chosen option";
option.voter_count = 1;
}
if (option.voter_count > poll->total_voter_count) {
LOG(ERROR) << "Have only " << poll->total_voter_count << " poll voters, but there are " << option.voter_count
<< " voters for an option";
poll->total_voter_count = option.voter_count;
}
is_changed = true;
}
}