UnicodeDecodeError when getting data var name

Open
#7,604 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
python

Research direction

Reproduce the failure with the provided Python snippet and binary, then inspect pyNativeStr in binaryninja/_binaryninjacore.py and the Symbol.name path in binaryninja/types.py. Trace how data_var.name reaches BNGetSymbolRawName and verify that accessing names from the sample library no longer raises UnicodeDecodeError.

Written by the indexing model from the issue text.

Description

Version and Platform (required):

  • Binary Ninja Version: 5.1.8005
  • Edition: Commercial
  • OS: Ubuntu Linux
  • OS Version: 24
  • CPU Architecture: x64

Bug Description:

Crashed because of unicode decode error.

Steps To Reproduce:

Python 3.12.4 (main, Jul 25 2024, 22:42:01) [Clang 18.1.8 ]
Type 'copyright', 'credits' or 'license' for more information
IPython 9.4.0 -- An enhanced Interactive Python. Type '?' for help.
Tip: You can use Ctrl-O to force a new line in terminal IPython

In [1]: import binaryninja

In [2]: bv = binaryninja.load("/usr/lib/x86_64-linux-gnu/libQt6Quick.so.6")

In [3]: for dv in bv.data_vars.values():
   ...:     foo = dv.name
---------------------------------------------------------------------------
UnicodeDecodeError                        Traceback (most recent call last)
<ipython-input-3-2af7a19e6385> in ?()
      1 for dv in bv.data_vars.values():
----> 2     foo = dv.name

/mnt/tide_comes_in_tide_goes_out_you_cant_explain_that/magnets_how_do_they_work/binaryninja/binaryninja/python/binaryninja/binaryview.py in ?(self)
  11311         @property
  11312         def name(self) -> Optional[str]:
  11313                 if self.symbol is None:
  11314                         return None
> 11315                 return self.symbol.name

/mnt/tide_comes_in_tide_goes_out_you_cant_explain_that/magnets_how_do_they_work/binaryninja/binaryninja/python/binaryninja/types.py in ?(self)
    339         @property
    340         def name(self) -> str:
    341                 """Symbol name (read-only)"""
--> 342                 return core.BNGetSymbolRawName(self._handle)

/mnt/tide_comes_in_tide_goes_out_you_cant_explain_that/magnets_how_do_they_work/binaryninja/binaryninja/python/binaryninja/_binaryninjacore.py in ?(sym)
  42501         result = _BNGetSymbolRawName(sym)
  42502         casted = ctypes.cast(result, ctypes.c_char_p).value
  42503         if casted is None:
  42504                 return None
> 42505         string = str(pyNativeStr(casted))
  42506         BNFreeString(result)
  42507         return string

/mnt/tide_comes_in_tide_goes_out_you_cant_explain_that/magnets_how_do_they_work/binaryninja/binaryninja/python/binaryninja/_binaryninjacore.py in ?(arg)
     32 def pyNativeStr(arg: AnyStr) -> str:
     33         if isinstance(arg, str):
     34                 return arg
     35         else:
---> 36                 return arg.decode('utf8')

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe8 in position 12: invalid continuation byte

In [4]: binaryninja.core_version_info()
Out[4]: CoreVersionInfo(major=5, minor=1, build=8005, channel='Stable')

Expected Behavior:
data_var.name doesn't cause unicode error

Screenshots/Video Recording:
N/A

Binary:

blazing guard blazes persistently

Additional Information:

Please add any other context about the problem here.

Dominant language
C++
Stars
1.3k
Forks
298
Avg merge
5d 5h
Merged PRs (30d)
19

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Vector35/binaryninja-api

All issues in Vector35/binaryninja-api

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.