From 89a8b0f60d89c8cd1292d36b1d5ba4d0c48041d0 Mon Sep 17 00:00:00 2001 From: Mathieu Tarral Date: Wed, 11 Sep 2024 07:35:41 -0700 Subject: [PATCH] csv: use parent init_buffer() to reinit insn buffer --- vmsifter/fuzzer/csv.py | 2 +- vmsifter/fuzzer/types.py | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/vmsifter/fuzzer/csv.py b/vmsifter/fuzzer/csv.py index dae7eed..45323b9 100644 --- a/vmsifter/fuzzer/csv.py +++ b/vmsifter/fuzzer/csv.py @@ -33,7 +33,7 @@ def __init__(self, insn_buffer: Optional[bytearray] = None, extra_params: Option self.reader = csv.DictReader(f) self.row = next(self.reader) insn = bytearray.fromhex(self.row["insn"]) - super().__init__(insn_buffer=insn, extra_params=extra_params) + self.init_buffer(buffer=insn) if settings.extra_byte != 0: self.insn_length += settings.extra_byte diff --git a/vmsifter/fuzzer/types.py b/vmsifter/fuzzer/types.py index 2852777..1a0bfde 100644 --- a/vmsifter/fuzzer/types.py +++ b/vmsifter/fuzzer/types.py @@ -263,9 +263,14 @@ def _get_default_buffer(): cache_dyna_insn_buf_size: int = field(init=False, default=settings.insn_buf_size) def __attrs_post_init__(self): + self.init_buffer(self.insn_buffer) + + # open this method since we might need to reinit the buffer in a child class + # due to additional fuzzer params + def init_buffer(self, buffer): min_len = settings.min_prefix_count + 1 - if self.insn_buffer is None: - self.insn_length = min_len # type: ignore[unreachable] + if buffer is None: + self.insn_length = min_len self.insn_buffer = self.__class__._get_default_buffer() else: self.insn_length = len(self.insn_buffer)