aaronst / macholibre

Mach-O & Universal Binary Parser
Apache License 2.0
143 stars 32 forks source link

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xfd in position 3: invalid start byte #21

Open LubosD opened 6 years ago

LubosD commented 6 years ago

This happens to me when I try to parse a core dump Mach-O file:

$ macholibre core.16057 
Traceback (most recent call last):
  File "/home/lubos/.local/bin/macholibre", line 11, in <module>
    load_entry_point('macholibre==1.0', 'console_scripts', 'macholibre')()
  File "/home/lubos/.local/lib64/python3.6/site-packages/macholibre/__init__.py", line 70, in main
    print(dumps(parse(args.input[0])))
  File "/home/lubos/.local/lib64/python3.6/site-packages/macholibre/__init__.py", line 45, in parse
    return parser.parse()
  File "/home/lubos/.local/lib64/python3.6/site-packages/macholibre/parser.py", line 1680, in parse
    self.parse_file()
  File "/home/lubos/.local/lib64/python3.6/site-packages/macholibre/parser.py", line 1671, in parse_file
    self.parse_macho(0, self.__output['size'])
  File "/home/lubos/.local/lib64/python3.6/site-packages/macholibre/parser.py", line 1588, in parse_macho
    self.parse_lcs(offset, size, nlcs, slcs)
  File "/home/lubos/.local/lib64/python3.6/site-packages/macholibre/parser.py", line 791, in parse_lcs
    self.parse_segment(offset, size, cmd, cmd_size))
  File "/home/lubos/.local/lib64/python3.6/site-packages/macholibre/parser.py", line 230, in parse_segment
    name = self.__file.read(16).decode().rstrip('\u0000')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xfd in position 3: invalid start byte
aaronst commented 6 years ago

@LubosD thanks for the info, I'll take a look.

jshlbrd commented 5 years ago

Adding to this issue -- I'm experiencing a similar (the same?) error when using the package.

 Traceback (most recent call last):
   File "[redacted]", line 237, in [redacted]
     [redacted]
   File "[redacted]", line 26, in [redacted]
     macho_dictionary = macholibre.parse(f.name)
   File "/usr/local/lib/python3.6/dist-packages/macholibre/__init__.py", line 45, in parse
     return parser.parse()
   File "/usr/local/lib/python3.6/dist-packages/macholibre/parser.py", line 1680, in parse
     self.parse_file()
   File "/usr/local/lib/python3.6/dist-packages/macholibre/parser.py", line 1671, in parse_file
     self.parse_macho(0, self.__output['size'])
   File "/usr/local/lib/python3.6/dist-packages/macholibre/parser.py", line 1588, in parse_macho
     self.parse_lcs(offset, size, nlcs, slcs)
   File "/usr/local/lib/python3.6/dist-packages/macholibre/parser.py", line 791, in parse_lcs
     self.parse_segment(offset, size, cmd, cmd_size))
   File "/usr/local/lib/python3.6/dist-packages/macholibre/parser.py", line 230, in parse_segment
     name = self.__file.read(16).decode().rstrip('\u0000')
 UnicodeDecodeError: 'utf-8' codec can't decode byte 0x99 in position 14: invalid start byte
aaronst commented 5 years ago

@jshlbrd , do you have a hash I can use to test?

jshlbrd commented 5 years ago

@aaronst yep, try this one: be55e8952a262d0e524239dbf82191ed

Happyholic1203 commented 4 years ago

@aaronst I attempted a fix on python2 branch here: https://github.com/aaronst/macholibre/pull/28