Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[loki] Simplify aggression checks #453

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions loki/loki.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,17 @@ class Loki:
__slots__ = ("aggr", "byte_order")

def __init__(
self, aggression: Optional[float] = 0.0, byte_order: Optional[str] = None
self, aggression: float = 0.0, byte_order: Optional[str] = None
) -> None:
"""
Arguments:
aggression: Amount of fuzzing to perform. 0 for 0% up to 1.0 for 100%.
byte_order: Used to indicate big or little endian when mutating multiple
bytes at once.
"""
assert aggression is not None
assert aggression >= 0
assert aggression <= 1
assert 0 <= aggression <= 1
assert byte_order is None or byte_order in self.BYTE_ORDERS
self.aggr = min(max(aggression, 0.0), 1.0)
self.aggr = aggression
self.byte_order = byte_order

@staticmethod
Expand Down Expand Up @@ -100,7 +98,7 @@ def _fuzz(self, tgt_fp: IO[bytes]) -> None:
LOG.debug("cannot fuzz empty file")
return
# minimum number of mutations should be 1
max_mutations = max(int(round(length * self.aggr)), 1)
max_mutations = max(round(length * self.aggr), 1)
mutations = randint(1, max_mutations)
LOG.debug(
"%d of a possible %d mutations will be performed", mutations, max_mutations
Expand Down
Loading