From 5761474bec55df68712a6ca173ab5f632c58a3de Mon Sep 17 00:00:00 2001 From: Jennifer Taylor Date: Mon, 26 Apr 2021 01:24:25 +0000 Subject: [PATCH] Enforce another invariant for dominator calculation that would have caught another hard-to-find bug. --- bemani/format/afp/decompile.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/bemani/format/afp/decompile.py b/bemani/format/afp/decompile.py index faa6b13..e495c8e 100644 --- a/bemani/format/afp/decompile.py +++ b/bemani/format/afp/decompile.py @@ -957,6 +957,9 @@ class BitVector: def __ne__(self, other: object) -> bool: return not self.__eq__(other) + def __len__(self) -> int: + return len(self.__bits) + @property def bitsSet(self) -> Set[int]: return {i for i in self.__bits if self.__bits[i]} @@ -1270,6 +1273,12 @@ class ByteCodeDecompiler(VerboseOutput): dominators: Dict[int, BitVector] = {chunk.id: BitVector(chunklen, init=True) for chunk in chunks} dominators[start_id].setAllBitsTo(False).setBit(start_id) + # Verify that the chunk IDs are contiguous. Otherwise this algorithm fails, since it + # assigns an integer ID to each bit in a bitfield contiguously. + for chunk in chunks: + if chunk.id < 0 or chunk.id >= len(chunks): + raise Exception("Chunk ID {chunk.id} is outside of our created BitVector, the ID space of chunks is non-contiguous!") + changed = True while changed: changed = False