Ensure that user photos offset doesn't exceed total photo count.
GitOrigin-RevId: 06bc1057cbcffe6e6a4911f236d2d7500057c1ec
This commit is contained in:
parent
585a8f19fa
commit
a40bdeca4c
@ -8836,9 +8836,11 @@ void ContactsManager::on_get_user_full(tl_object_ptr<telegram_api::userFull> &&u
|
|||||||
void ContactsManager::on_get_user_photos(UserId user_id, int32 offset, int32 limit, int32 total_count,
|
void ContactsManager::on_get_user_photos(UserId user_id, int32 offset, int32 limit, int32 total_count,
|
||||||
vector<tl_object_ptr<telegram_api::Photo>> photos) {
|
vector<tl_object_ptr<telegram_api::Photo>> photos) {
|
||||||
int32 photo_count = narrow_cast<int32>(photos.size());
|
int32 photo_count = narrow_cast<int32>(photos.size());
|
||||||
if (total_count < 0 || total_count < photo_count) {
|
int32 min_total_count = (offset >= 0 && photo_count > 0 ? offset : 0) + photo_count;
|
||||||
LOG(ERROR) << "Wrong photos total_count " << total_count << ". Receive " << photo_count << " photos";
|
if (total_count < min_total_count) {
|
||||||
total_count = photo_count;
|
LOG(ERROR) << "Wrong photos total_count " << total_count << ". Receive " << photo_count << " photos with offset "
|
||||||
|
<< offset;
|
||||||
|
total_count = min_total_count;
|
||||||
}
|
}
|
||||||
LOG_IF(ERROR, limit < photo_count) << "Requested not more than " << limit << " photos, but " << photo_count
|
LOG_IF(ERROR, limit < photo_count) << "Requested not more than " << limit << " photos, but " << photo_count
|
||||||
<< " returned";
|
<< " returned";
|
||||||
@ -8905,6 +8907,10 @@ void ContactsManager::on_get_user_photos(UserId user_id, int32 offset, int32 lim
|
|||||||
user_photos->photos.push_back(std::move(user_photo));
|
user_photos->photos.push_back(std::move(user_photo));
|
||||||
add_user_photo_id(u, user_id, user_photos->photos.back().id, photo_get_file_ids(user_photos->photos.back()));
|
add_user_photo_id(u, user_id, user_photos->photos.back().id, photo_get_file_ids(user_photos->photos.back()));
|
||||||
}
|
}
|
||||||
|
if (user_photos->offset > user_photos->count) {
|
||||||
|
user_photos->offset = user_photos->count;
|
||||||
|
user_photos->photos.clear();
|
||||||
|
}
|
||||||
|
|
||||||
auto known_photo_count = narrow_cast<int32>(user_photos->photos.size());
|
auto known_photo_count = narrow_cast<int32>(user_photos->photos.size());
|
||||||
CHECK(user_photos->count >= known_photo_count);
|
CHECK(user_photos->count >= known_photo_count);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user