1
0
Fork 0
mirror of https://gitlab.com/famedly/conduit.git synced 2025-06-27 16:35:59 +00:00

Merge branch 'fix-panic-on-no-rooms-joined-sync-v5' into 'next'

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

Closes #476

See merge request famedly/conduit!753
This commit is contained in:
Matthias Ahouansou 2025-06-07 12:37:57 +00:00
commit 8ee8ea3e45

View file

@ -1531,10 +1531,13 @@ pub async fn sync_events_v5_route(
let mut new_known_rooms = BTreeSet::new(); let mut new_known_rooms = BTreeSet::new();
for (mut start, mut end) in list.ranges { for (mut start, mut end) in list.ranges {
start = start.clamp(uint!(0), UInt::from(all_joined_rooms.len() as u32 - 1)); start = start.clamp(
end = end.clamp(start, UInt::from(all_joined_rooms.len() as u32 - 1)); 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 = 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()); new_known_rooms.extend(room_ids.iter().cloned());
for room_id in &room_ids { for room_id in &room_ids {
let todo_room = let todo_room =