Skip to content

Unexpected behavior when copying FieldContainer #4657

@wb-airbus

Description

@wb-airbus

Brief description

Copying a FieldContainer instance yields a copy of the contained field instead of the container itself.

This is relevant in cases where a class uses the "field copy" feature in its fields_desc, e.g.:

class A(Packet):
   fields_desc = [ Emph(ByteField("foo", 0)) ]

class B(Packet):
   fields_desc = [ A, ByteField("bar", 0) ]

In this situation, B's foo field should be of type Emph, but it actually is a plain ByteField.

Scapy version

2f3f5dd

Python version

3.13.1

Operating system

Linux 6.12.11-200.fc41.x86_64

Additional environment information

No response

How to reproduce

Emph(ByteField("foo", 0)).copy()

Actual result

<ByteField ().foo>

Expected result

# output should be similar to that of
Emph(ByteField("foo", 0))
<scapy.fields.Emph at 0xdeadbeef>

Related resources

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions