Vector35 / binaryninja-api

Public API, examples, documentation and issues for Binary Ninja
https://binary.ninja/
MIT License
927 stars 209 forks source link

Index out of bounds in TypedDataAccessor when accessing members of an array #4234

Closed joelreymont closed 1 year ago

joelreymont commented 1 year ago

Version 3.4.4230-dev

>>> tab = bv.get_data_var_at(0x13c0c0)
>>> tab
<var 0x13c0c0: struct init_func_t[0xe0]>
>>> for x in tab:
...     print(f"name = {x.value['name']}")
... 
name = 1107056
...
name = 1127241
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Applications/Binary Ninja.app/Contents/MacOS/plugins/../../Resources/python/binaryninja/binaryview.py", line 9235, in __getitem__
    return self._accessor[item]
  File "/Applications/Binary Ninja.app/Contents/MacOS/plugins/../../Resources/python/binaryninja/binaryview.py", line 9044, in __getitem__
    raise ValueError(f"Index {key} out of bounds array has {_type.count} elements")
ValueError: Index 224 out of bounds array has 224 elements
xusheng6 commented 1 year ago

Looks like a off-by-one error. I scanned the code and did not find the problem immediately. Will need more scrutiny later

xusheng6 commented 1 year ago

Related to #4325

plafosse commented 1 year ago

Iterating a DataVariable object was unintentional; however, it is a good idea. The root cause is that we implemented a __getitem__ without an __iter__ which is apparently a really bad idea because python will just wrongly assume it knows how to iterate the thing correctly.

This will be fixed in 3.5.4305