Browse Source

fix(sync v5): fix underflow when clamping room list indexes & allow empty range

both these issues could both previously cause panics when the user is not in many rooms
merge-requests/762/head
Matthias Ahouansou 9 months ago
parent
commit
263bc61ec8
No known key found for this signature in database
  1. 9
      src/api/client_server/sync.rs

9
src/api/client_server/sync.rs

@ -1531,10 +1531,13 @@ pub async fn sync_events_v5_route(
let mut new_known_rooms = BTreeSet::new();
for (mut start, mut end) in list.ranges {
start = start.clamp(uint!(0), UInt::from(all_joined_rooms.len() as u32 - 1));
end = end.clamp(start, UInt::from(all_joined_rooms.len() as u32 - 1));
start = start.clamp(
uint!(0),
UInt::from(all_joined_rooms.len().saturating_sub(1) as u32),
);
end = end.clamp(start, UInt::from(all_joined_rooms.len() as u32));
let room_ids =
all_joined_rooms[(u64::from(start) as usize)..=(u64::from(end) as usize)].to_vec();
all_joined_rooms[(u64::from(start) as usize)..(u64::from(end) as usize)].to_vec();
new_known_rooms.extend(room_ids.iter().cloned());
for room_id in &room_ids {
let todo_room =

Loading…
Cancel
Save