Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Python3] pf.parse fails when data is a bytes object #135

Open
zachriggle opened this issue Jan 20, 2021 · 2 comments
Open

[Python3] pf.parse fails when data is a bytes object #135

zachriggle opened this issue Jan 20, 2021 · 2 comments
Assignees
Labels
bug needs-triage A fresh user-reported issue that needs triage (i.e. is not a concrete-issue)

Comments

@zachriggle
Copy link

It looks like pfp does not like being given bytes-like objects on Python3.

>>> template='uchar mybyte;'
>>> pfp.parse('a', template)
<pfp.fields.Dom object at 0x10fbdab50>

However...

>>> pfp.parse(b'a', template)

Throws the following error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
~/github.com/pfp/pfp/interp.py in _run(self, keep_successfull)
   1043             # may change (e.g. compressed data)
-> 1044             res = self._handle_node(self._ast, None, None, self._stream)
   1045         except errors.InterpReturn as e:

~/github.com/pfp/pfp/interp.py in _handle_node(self, node, scope, ctxt, stream)
   1152
-> 1153         res = self._node_switch[node.__class__](node, scope, ctxt, stream)
   1154

~/github.com/pfp/pfp/interp.py in _handle_file_ast(self, node, scope, ctxt, stream)
   1168         """
-> 1169         self._root = ctxt = fields.Dom(stream)
   1170         ctxt._pfp__scope = scope

~/github.com/pfp/pfp/fields.py in __init__(self, *args, **kwargs)
   1217     def __init__(self, *args, **kwargs):
-> 1218         super(self.__class__, self).__init__(*args, **kwargs)
   1219

~/github.com/pfp/pfp/fields.py in __init__(self, stream, metadata_processor)
    772         if stream is not None:
--> 773             self._pfp__offset = stream.tell()
    774

~/github.com/pfp/pfp/bitwrap.py in tell(self)
    191         """
--> 192         res = self._stream.tell()
    193         if len(self._bits) > 0:

AttributeError: 'bytes' object has no attribute 'tell'
@zachriggle zachriggle added bug needs-triage A fresh user-reported issue that needs triage (i.e. is not a concrete-issue) labels Jan 20, 2021
@d0c-s4vage
Copy link
Owner

Oh interesting, thank you for the bug report! I thought I had addressed all Python 3 compatability issues already.

@tostercx
Copy link

A workaround - pass io.BytesIO(bytes) as data

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug needs-triage A fresh user-reported issue that needs triage (i.e. is not a concrete-issue)
Projects
None yet
Development

No branches or pull requests

3 participants