Skip to content
This repository has been archived by the owner on Nov 7, 2024. It is now read-only.

Commit

Permalink
chunking: Handle low amount of high-size packages
Browse files Browse the repository at this point in the history
If we have a low amount of high-size packages then we will drain with an
index higher than the size of the Vec which triggers a panic.

Fixes: coreos/rpm-ostree#4646
  • Loading branch information
travier committed Oct 9, 2023
1 parent ef9bcc4 commit 5724349
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/src/chunking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,12 @@ fn get_partitions_with_threshold<'a>(
}

// Extra high-size packages
let mut remaining_pkgs: Vec<_> = high_size.drain(limit_hs_bins..).collect();
assert_eq!(high_size.len(), limit_hs_bins);
let mut remaining_pkgs: Vec<_> = if high_size.len() < limit_hs_bins {
Vec::new()
} else {
high_size.drain(limit_hs_bins..).collect()
};
assert_lt!(high_size.len(), limit_hs_bins);

// Concatenate extra high-size packages + med_sizes to keep it descending sorted
remaining_pkgs.append(&mut med_size);
Expand Down

0 comments on commit 5724349

Please sign in to comment.