fix: handle multiple flag bits when unmarshalling (#241)

This commit is contained in:
J. Nick Koston 2023-09-07 10:16:07 -05:00 committed by GitHub
parent 0386dc2322
commit 6f6f5f86c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 8 deletions

View File

@ -11,6 +11,7 @@ cdef object ARRAY
cdef object UNIX_FDS_CMSG_LENGTH
cdef object SOL_SOCKET
cdef object SCM_RIGHTS
cdef object MESSAGE_FLAG_INTENUM
cdef unsigned int UINT32_SIZE
cdef unsigned int INT16_SIZE
@ -112,8 +113,8 @@ cdef class Unmarshaller:
cdef unsigned int _body_len
cdef unsigned int _serial
cdef unsigned int _header_len
cdef unsigned int _message_type
cdef unsigned int _flag
cdef object _message_type
cdef object _flag
cdef unsigned int _msg_len
cdef unsigned int _is_native
cdef object _uint32_unpack

View File

@ -6,12 +6,14 @@ import sys
from struct import Struct
from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Union
from ..constants import MESSAGE_FLAG_MAP, MESSAGE_TYPE_MAP
from ..constants import MESSAGE_FLAG_MAP, MESSAGE_TYPE_MAP, MessageFlag
from ..errors import InvalidMessageError
from ..message import Message
from ..signature import SignatureType, Variant, get_signature_tree
from .constants import BIG_ENDIAN, LITTLE_ENDIAN, PROTOCOL_VERSION
MESSAGE_FLAG_INTENUM = MessageFlag
MAX_UNIX_FDS = 16
MAX_UNIX_FDS_SIZE = array.array("i").itemsize
UNIX_FDS_CMSG_LENGTH = socket.CMSG_LEN(MAX_UNIX_FDS_SIZE)
@ -702,9 +704,12 @@ class Unmarshaller:
tree = get_signature_tree(signature)
body = [self._readers[t.token](self, t) for t in tree.types]
flags = MESSAGE_FLAG_MAP.get(self._flag)
if flags is None:
flags = MESSAGE_FLAG_INTENUM(self._flag)
self._message = Message(
message_type=MESSAGE_TYPE_MAP[self._message_type],
flags=MESSAGE_FLAG_MAP[self._flag],
flags=flags,
unix_fds=self._unix_fds,
signature=tree,
body=body,

View File

@ -1,13 +1,9 @@
import asyncio
import pytest
from dbus_fast import Message, MessageFlag, MessageType
from dbus_fast.aio import MessageBus
from dbus_fast.service import ServiceInterface, method
@pytest.mark.xfail
@pytest.mark.asyncio
async def test_multiple_flags_in_message():
class ExampleInterface(ServiceInterface):
@ -22,4 +18,5 @@ async def test_multiple_flags_in_message():
interface = ExampleInterface("test.interface")
bus.export("/test/path", interface)
await bus.request_name("test.name")
bus.disconnect()
await bus.wait_for_disconnect()