8000 [bug] Allow empty payloads · Issue #4733 · secdev/scapy · GitHub
[go: up one dir, main page]

Skip to content
[bug] Allow empty payloads #4733
@alxroyer-thales

Description

@alxroyer-thales

Brief description

Even though a binding exists with an empty packet, the empty packet class does not get instantiated for payload on dissection.

Scapy version

2.6.1

Python version

3.8.6

Operating system

Windows

Additional environment information

No response

How to reproduce

class A(Packet):
fields_desc = [
XByteField("b", default=0),
]

class B1(Packet):
fields_desc = [
XByteField("value", default=0)
]

class B0(Packet):
fields_desc = []

bind_layers(A, B1, b=0x01)
bind_layers(A, B0, b=0x00)

a = A(bytes.fromhex("0101"))
assert isinstance(a.payload, B1), f"Payload of {a!r} is not {B1!r}"
a = A(bytes.fromhex("00"))
assert isinstance(a.payload, B0), f"Payload of {a!r} is not {B0!r}"

Actual result

AssertionError: Payload of <A b=0x0 |> is not <class 'main.B0'>

Expected result

No exception.

Related resources

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0