Skip to content

[receive] Universe discovery has_all_pages() can panic #47

@bruingineer

Description

@bruingineer
pub fn has_all_pages(&mut self) -> bool {
    self.pages.sort_by(|a, b| a.page.cmp(&b.page));
    for i in 0..(self.last_page + 1) {
        if self.pages[i as usize].page != i {
            return false;
        }
    }
    true
}

This indexes self.pages[i] without checking length.

If

  • receive page 1 before page 0, or
  • miss any page, or
  • receive duplicates and still don’t have a full contiguous set,

then

  • self.pages.len() can be < last_page+1 and this will panic.

In handle_universe_discovery_packet(), if the first packet seen from a source is page > 0, it still creates a partially discovered source with that single page. Later, has_all_pages() can be called while still missing page 0, and will panic.

Fix: check self.pages.len() >= (self.last_page as usize + 1) before indexing, or rewrite to a set/bitmask presence check.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions