Repository navigation
Description
Version and Platform (required):
- Binary Ninja Version: 6.1.11226-dev (also present on
devat 53c27b0) - Edition: not edition-specific (Python API)
- OS: Linux
- OS Version: Ubuntu
- CPU Architecture: x64
Bug Description:
CoreArchitecture.__init__ fills self.intrinsics without first giving the object a dict of its own, so it writes into the class-level Architecture.intrinsics, one dict shared by every CoreArchitecture (python/architecture.py, self.intrinsics[name] = self._intrinsics_info[name]). This has two effects:
- Every core architecture's
intrinsicslists the intrinsics of every architecture built so far in the process, not just its own. The private maps (_intrinsics,_intrinsics_info, ...) are correct. Architecture.__init__(called first throughsuper().__init__()) iteratesself.__class__.intrinsics, which is that same shared dict. Two threads buildingCoreArchitectureobjects at once (for example, two scripts first touchingbv.archon different views) can fail while one iterates the dict and the other adds to it:
File ".../binaryninja/binaryview.py", line 3898, in arch
return architecture.CoreArchitecture._from_cache(handle=arch)
File ".../binaryninja/architecture.py", line 3049, in _from_cache
return _architecture_cache.get(ctypes.addressof(handle.contents)) or cls(handle)
File ".../binaryninja/architecture.py", line 2782, in __init__
super().__init__()
File ".../binaryninja/architecture.py", line 1047, in __init__
for intrinsic in self.__class__.intrinsics.keys():
RuntimeError: dictionary changed size during iteration
Steps To Reproduce:
from binaryninja import Architecture
mips = Architecture['mips32']
print(len(mips.intrinsics)) # 77
Architecture['aarch64']
print(len(mips.intrinsics)) # 4342
print(mips.intrinsics is Architecture.intrinsics) # TrueExpected Behavior:
Each architecture's intrinsics holds only its own intrinsics, matching _intrinsics_info, and building architecture objects on several threads at once does not raise.
Additional Information:
Giving each CoreArchitecture an instance dict (self.intrinsics = {} before the loop that fills it) fixes both: nothing writes the shared dict, so the iteration in Architecture.__init__ sees an empty, unchanging dict for core architectures. A PR will follow.
Activity