altdesktop / python-dbus-next

🚌 The next great DBus library for Python with asyncio support
https://python-dbus-next.readthedocs.io/en/latest/
MIT License
191 stars 60 forks source link

dbus_next.errors.InvalidSignatureError: got unexpected token: "" #67

Closed sbrown4 closed 3 years ago

sbrown4 commented 3 years ago

This occurs with the latest commit bb0a24789. The buffer self.buf length and contents is from dbus_next/_private/unmarshaller.py", line 260 and appears to be truncated. dbus-monitor shows the full message. The buffer and traceback is below.

buffer: 1499 bytearray(b'l\x02\x01\x01\x9b\x05\x00\x00\x15\x00\x00\x00/\x00\x00\x00l\x02\x01\x01\x00\x00\x00\x00\x08\x00\x00\x005\x00\x00\x00\x06\x01s\x00\x06\x00\x00\x00:1.326\x00\x00\x05\x01u\x00\x07\x00\x00\x00\x07\x01s\x00\x14\x00\x00\x00org.freedesktop.DBus\x00\x00\x00\x00\x06\x01s\x00\x06\x00\x00\x00:1.326\x00\x00\x05\x01u\x00\x08\x00\x00\x00\x08\x01g\x00\x01s\x00\x00\x07\x01s\x00\x06\x00\x00\x00:1.294\x00\x00\x96\x05\x00\x00<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"\n"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">\n<node>\n\t<interface name="org.freedesktop.DBus.Introspectable">\n\t\t<method name="Introspect">\n\t\t\t<arg name="xml" type="s" direction="out"/>\n\t\t</method>\n\t</interface>\n\t<interface name="org.bluez.mesh.Network1">\n\t\t<method name="Join">\n\t\t\t<arg name="app" type="o" direction="in"/>\n\t\t\t<arg name="uuid" type="ay" direction="in"/>\n\t\t</method>\n\t\t<method name="Cancel">\n\t\t</method>\n\t\t<method name="Attach">\n\t\t\t<arg name="app" type="o" direction="in"/>\n\t\t\t<arg name="token" type="t" direction="in"/>\n\t\t\t<arg name="node" type="o" direction="out"/>\n\t\t\t<arg name="configuration" type="a(ya(qa{sv}))" direction="out"/>\n\t\t</method>\n\t\t<method name="Leave">\n\t\t\t<arg name="token" type="t" direction="in"/>\n\t\t</method>\n\t\t<method name="CreateNetwork">\n\t\t\t<arg name="app" type="o" direction="in"/>\n\t\t\t<arg name="uuid" type="ay" direction="in"/>\n\t\t</method>\n\t\t<method name="Import">\n\t\t\t<arg name="app" type="o" direction="in"/>\n\t\t\t<arg name="uuid" type="ay" direction="in"/>\n\t\t\t<arg name="dev_key" type="ay" direction="in"/>\n\t\t\t<arg name="net_key" type="ay" direction="in"/>\n\t\t\t<arg name="net_index" type="q" direction="in"/>\n\t\t\t<arg name="flags" type="a{sv}" direction="in"/>\n\t\t\t<arg name="iv_index" type="u" direction="in"/>\n\t\t\t<arg name')


ERROR:asyncio:Exception in callback None()
handle: <Handle cancelled MessageBus._message_reader() created at /usr/lib/python3.8/asyncio/selector_events.py:257>
source_traceback: Object created at (most recent call last):
  File "/usr/lib/python3.8/asyncio/base_events.py", line 603, in run_until_complete
    self.run_forever()
  File "/usr/lib/python3.8/asyncio/base_events.py", line 570, in run_forever
    self._run_once()
  File "/usr/lib/python3.8/asyncio/base_events.py", line 1851, in _run_once
    handle._run()
  File "/usr/lib/python3.8/asyncio/events.py", line 81, in _run
    self._context.run(self._callback, *self._args)
  File "./prov_aio.py", line 1478, in start_up
    async with SampleApplication(addr, token, loop) as app:
  File "/home/ubuntu/.local/lib/python3.8/site-packages/bluetooth_mesh-0.2.28-py3.8.egg/bluetooth_mesh/application.py", line 275, in __aenter__
    await self.dbus_connect()
  File "/home/ubuntu/.local/lib/python3.8/site-packages/bluetooth_mesh-0.2.28-py3.8.egg/bluetooth_mesh/application.py", line 250, in dbus_connect
    self.bus = await message_bus.connect()
  File "/home/ubuntu/.local/lib/python3.8/site-packages/dbus_next-0.1.4-py3.8.egg/dbus_next/aio/message_bus.py", line 72, in connect
    self._loop.add_reader(self._fd, self._message_reader)
  File "/usr/lib/python3.8/asyncio/selector_events.py", line 332, in add_reader
    return self._add_reader(fd, callback, *args)
  File "/usr/lib/python3.8/asyncio/selector_events.py", line 257, in _add_reader
    handle = events.Handle(callback, args, self, None)
Traceback (most recent call last):
  File "/home/ubuntu/.local/lib/python3.8/site-packages/dbus_next-0.1.4-py3.8.egg/dbus_next/aio/message_bus.py", line 299, in _message_reader
    if self._unmarshaller.unmarshall():
  File "/home/ubuntu/.local/lib/python3.8/site-packages/dbus_next-0.1.4-py3.8.egg/dbus_next/_private/unmarshaller.py", line 302, in unmarshall
    self._unmarshall()
  File "/home/ubuntu/.local/lib/python3.8/site-packages/dbus_next-0.1.4-py3.8.egg/dbus_next/_private/unmarshaller.py", line 260, in _unmarshall
    for field_struct in self.read_argument(SignatureTree._get('a(yv)').types[0]):
  File "/home/ubuntu/.local/lib/python3.8/site-packages/dbus_next-0.1.4-py3.8.egg/dbus_next/_private/unmarshaller.py", line 233, in read_argument
    return self.readers[t](type_)
  File "/home/ubuntu/.local/lib/python3.8/site-packages/dbus_next-0.1.4-py3.8.egg/dbus_next/_private/unmarshaller.py", line 223, in read_array
    result.append(self.read_argument(child_type))
  File "/home/ubuntu/.local/lib/python3.8/site-packages/dbus_next-0.1.4-py3.8.egg/dbus_next/_private/unmarshaller.py", line 233, in read_argument
    return self.readers[t](type_)
  File "/home/ubuntu/.local/lib/python3.8/site-packages/dbus_next-0.1.4-py3.8.egg/dbus_next/_private/unmarshaller.py", line 186, in read_struct
    result.append(self.read_argument(child_type))
  File "/home/ubuntu/.local/lib/python3.8/site-packages/dbus_next-0.1.4-py3.8.egg/dbus_next/_private/unmarshaller.py", line 233, in read_argument
    return self.readers[t](type_)
  File "/home/ubuntu/.local/lib/python3.8/site-packages/dbus_next-0.1.4-py3.8.egg/dbus_next/_private/unmarshaller.py", line 177, in read_variant
    signature_tree = SignatureTree._get(signature)
  File "/home/ubuntu/.local/lib/python3.8/site-packages/dbus_next-0.1.4-py3.8.egg/dbus_next/signature.py", line 320, in _get    SignatureTree._cache[signature] = SignatureTree(signature)
  File "/home/ubuntu/.local/lib/python3.8/site-packages/dbus_next-0.1.4-py3.8.egg/dbus_next/signature.py", line 332, in __init__
    (type_, signature) = SignatureType._parse_next(signature)
  File "/home/ubuntu/.local/lib/python3.8/site-packages/dbus_next-0.1.4-py3.8.egg/dbus_next/signature.py", line 65, in _parse_next
    raise InvalidSignatureError(f'got unexpected token: "{token}"')
dbus_next.errors.InvalidSignatureError: got unexpected token: ""```
acrisci commented 3 years ago

I've gotten this once in the test cases, but it's unfortunately intermittent. If I need to I can revert that commit.

sbrown4 commented 3 years ago

dbus-monitor pcap output shows that the message length is 1499. But, the header in the wireshark output doesn't seem to match the dump. The dump header is longer. Below is a dump and the corresponding pcap file.

buffer: 1499 bytearray(b'l\x02\x01\x01\x9b\x05\x00\x00\n\x00\x00\x00/\x00\x00\x00l\x02\x01\x01\x00\x00\x00\x00\x08\x00\x00\x005\x00\x00\x00\x06\x01s\x00\x06\x00\x00\x00:1.345\x00\x00\x05\x01u\x00\x07\x00\x00\x00\x07\x01s\x00\x14\x00\x00\x00org.freedesktop.DBus\x00\x00\x00\x00\x06\x01s\x00\x06\x00\x00\x00:1.345\x00\x00\x05\x01u\x00\x08\x00\x00\x00\x08\x01g\x00\x01s\x00\x00\x07\x01s\x00\x06\x00\x00\x00:1.336\x00\x00\x96\x05\x00\x00<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"\n"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">\n<node>\n\t<interface name="org.freedesktop.DBus.Introspectable">\n\t\t<method name="Introspect">\n\t\t\t<arg name="xml" type="s" direction="out"/>\n\t\t</method>\n\t</interface>\n\t<interface name="org.bluez.mesh.Network1">\n\t\t<method name="Join">\n\t\t\t<arg name="app" type="o" direction="in"/>\n\t\t\t<arg name="uuid" type="ay" direction="in"/>\n\t\t</method>\n\t\t<method name="Cancel">\n\t\t</method>\n\t\t<method name="Attach">\n\t\t\t<arg name="app" type="o" direction="in"/>\n\t\t\t<arg name="token" type="t" direction="in"/>\n\t\t\t<arg name="node" type="o" direction="out"/>\n\t\t\t<arg name="configuration" type="a(ya(qa{sv}))" direction="out"/>\n\t\t</method>\n\t\t<method name="Leave">\n\t\t\t<arg name="token" type="t" direction="in"/>\n\t\t</method>\n\t\t<method name="CreateNetwork">\n\t\t\t<arg name="app" type="o" direction="in"/>\n\t\t\t<arg name="uuid" type="ay" direction="in"/>\n\t\t</method>\n\t\t<method name="Import">\n\t\t\t<arg name="app" type="o" direction="in"/>\n\t\t\t<arg name="uuid" type="ay" direction="in"/>\n\t\t\t<arg name="dev_key" type="ay" direction="in"/>\n\t\t\t<arg name="net_key" type="ay" direction="in"/>\n\t\t\t<arg name="net_index" type="q" direction="in"/>\n\t\t\t<arg name="flags" type="a{sv}" direction="in"/>\n\t\t\t<arg name="iv_index" type="u" direction="in"/>\n\t\t\t<arg name') prov-bad.pcap.gz

acrisci commented 3 years ago

cf7d499 should disable those unmarshaller changes by default. Let me know if that fixes it.

sbrown4 commented 3 years ago

That fixed it. The new buffer is below. Thanks buffer: 1499 bytearray(b'l\x02\x01\x01\x9b\x05\x00\x00\x0b\x00\x00\x00/\x00\x00\x00\x06\x01s\x00\x06\x00\x00\x00:1.346\x00\x00\x05\x01u\x00\x08\x00\x00\x00\x08\x01g\x00\x01s\x00\x00\x07\x01s\x00\x06\x00\x00\x00:1.336\x00\x00\x96\x05\x00\x00<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"\n"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">\n<node>\n\t<interface name="org.freedesktop.DBus.Introspectable">\n\t\t<method name="Introspect">\n\t\t\t<arg name="xml" type="s" direction="out"/>\n\t\t</method>\n\t</interface>\n\t<interface name="org.bluez.mesh.Network1">\n\t\t<method name="Join">\n\t\t\t<arg name="app" type="o" direction="in"/>\n\t\t\t<arg name="uuid" type="ay" direction="in"/>\n\t\t</method>\n\t\t<method name="Cancel">\n\t\t</method>\n\t\t<method name="Attach">\n\t\t\t<arg name="app" type="o" direction="in"/>\n\t\t\t<arg name="token" type="t" direction="in"/>\n\t\t\t<arg name="node" type="o" direction="out"/>\n\t\t\t<arg name="configuration" type="a(ya(qa{sv}))" direction="out"/>\n\t\t</method>\n\t\t<method name="Leave">\n\t\t\t<arg name="token" type="t" direction="in"/>\n\t\t</method>\n\t\t<method name="CreateNetwork">\n\t\t\t<arg name="app" type="o" direction="in"/>\n\t\t\t<arg name="uuid" type="ay" direction="in"/>\n\t\t</method>\n\t\t<method name="Import">\n\t\t\t<arg name="app" type="o" direction="in"/>\n\t\t\t<arg name="uuid" type="ay" direction="in"/>\n\t\t\t<arg name="dev_key" type="ay" direction="in"/>\n\t\t\t<arg name="net_key" type="ay" direction="in"/>\n\t\t\t<arg name="net_index" type="q" direction="in"/>\n\t\t\t<arg name="flags" type="a{sv}" direction="in"/>\n\t\t\t<arg name="iv_index" type="u" direction="in"/>\n\t\t\t<arg name="unicast" type="q" direction="in"/>\n\t\t</method>\n\t</interface>\n</node>\n\x00')