Skip to content

Commit

Permalink
Fix bug where hierarchy generator could loop infinitely (#238)
Browse files Browse the repository at this point in the history
Signed-off-by: John Kastner <jkastner@amazon.com>
  • Loading branch information
john-h-kastner-aws authored Feb 29, 2024
1 parent 9a93cb6 commit ebf0b80
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cedar-policy-generators/src/hierarchy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,11 @@ impl<'a, 'u> HierarchyGenerator<'a, 'u> {
let num_entities_per_type = num_entities / entity_types.len();
let mut uids = HashSet::new();
while uids.len() < num_entities_per_type {
// If we run out of bytes in `u`, then `uid` will be the same on every
// subsequent iteration, so the size of `uids` won't increase.
if self.u.is_empty() {
return Err(Error::NotEnoughData);
}
let uid =
generate_uid_with_type(name.clone(), &self.uid_gen_mode, self.u)?;
uids.insert(uid);
Expand Down

0 comments on commit ebf0b80

Please sign in to comment.