uriplaylistbin: prevent overflow panic with infinite playlist

enumerate() will panic if the index overflows.
This commit is contained in:
Guillaume Desmottes 2021-12-22 12:52:07 +01:00
parent 4a5815cc97
commit 9783d01a35

View file

@ -613,12 +613,15 @@ struct ItemInner {
struct Playlist {
items: Box<dyn Iterator<Item = Item> + Send>,
uris: Vec<String>,
}
impl Playlist {
fn new(uris: Vec<String>, iterations: u32) -> Self {
Self {
items: Self::create_items(uris, iterations),
items: Self::create_items(uris.clone(), iterations),
uris,
}
}
@ -664,6 +667,11 @@ impl Playlist {
Some(item) => item,
};
if item.index() == usize::MAX {
// prevent overflow with infinite playlist
self.items = Self::create_items(self.uris.clone(), 0);
}
item.set_waiting_for_stream_collection()?;
Ok(Some(item))