#4657·scapy

Unexpected behavior when copying FieldContainer

Author: wb-airbusCreated Feb 5, 2025Updated Jun 1, 2026

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.:

python
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

2f3f5dd56bb114b96ce51ce71e2f4ab059b69a42

Python version

3.13.1

Operating system

Linux 6.12.11-200.fc41.x86_64

Additional environment information

No response

How to reproduce

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

Actual result

python
<ByteField ().foo>

Expected result

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

Related resources

No response