Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

CoreArchitecture.intrinsics is shared by every core architecture #8738

Backlog

Description

@jrozner

Version and Platform (required):

  • Binary Ninja Version: 6.1.11226-dev (also present on dev at 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:

  1. Every core architecture's intrinsics lists the intrinsics of every architecture built so far in the process, not just its own. The private maps (_intrinsics, _intrinsics_info, ...) are correct.
  2. Architecture.__init__ (called first through super().__init__()) iterates self.__class__.intrinsics, which is that same shared dict. Two threads building CoreArchitecture objects at once (for example, two scripts first touching bv.arch on 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)  # True

Expected 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions