mirror of
https://gitlab.com/famedly/conduit.git
synced 2025-06-27 16:35:59 +00:00
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
This commit is contained in:
parent
09e1713c30
commit
263bc61ec8
1 changed files with 6 additions and 3 deletions
|
@ -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 =
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue