diff options
| -rw-r--r-- | miasm/core/types.py | 2 | ||||
| -rwxr-xr-x | test/core/test_types.py | 25 |
2 files changed, 26 insertions, 1 deletions
diff --git a/miasm/core/types.py b/miasm/core/types.py index 466d136d..4f99627d 100644 --- a/miasm/core/types.py +++ b/miasm/core/types.py @@ -994,7 +994,7 @@ class BitField(Union): for name, bits in bit_list: fields.append((name, Bits(self._num, bits, offset))) offset += bits - if offset > self._num.size == 8: + if offset > self._num.size * 8: raise ValueError("sum of bit lengths is > to the backing num size") super(BitField, self).__init__(fields) diff --git a/test/core/test_types.py b/test/core/test_types.py index 1b15630c..13a7824e 100755 --- a/test/core/test_types.py +++ b/test/core/test_types.py @@ -351,6 +351,31 @@ assert bit.flags.f2_5 == 0b01110 assert bit.flags.f3_8 == 0b01010101 assert bit.flags.f4_1 == 1 +try: + class BitStruct(MemUnion): + fields = [ + ("ValueB", BitField(Num("<Q"), [ + ("field_00", 32), + ("field_01", 32), + ])), + ("Value", Num("<Q")), + ] +except ValueError: + assert False, "Should not raise" + +try: + class BitStruct(MemUnion): + fields = [ + ("ValueB", BitField(Num("<Q"), [ + ("field_00", 32), + ("field_01", 32), + ("field_02", 1), + ])), + ("Value", Num("<Q")), + ] + assert False, "Should raise" +except ValueError: + pass # Unhealthy ideas class UnhealthyIdeas(MemStruct): |