You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[bug] Avoid modifying default values of packet list fields #4735
When a packet list field is provided with a default list for value, instances of the given packet then just .copy() the packet list without copying the packets inside.
Consequently, modifying anything in a packet of the list from an instance of the owner packet modifies the thing for other instances (except for clones!)
a0:
###[ A ]###
\b \
|###[ B ]###
| value = 0
|###[ B ]###
| value = 10
|###[ B ]###
| value = 2
a1:
###[ A ]###
\b \
|###[ B ]###
| value = 0
|###[ B ]###
| value = 10
|###[ B ]###
| value = 2
Clone of a1:
###[ A ]###
\b \
|###[ B ]###
| value = 0
|###[ B ]###
| value = 1
|###[ B ]###
| value = 2
a2:
###[ A ]###
\b \
|###[ B ]###
| value = 0
|###[ B ]###
| value = 10
|###[ B ]###
| value = 2
a3:
###[ A ]###
\b \
|###[ B ]###
| value = 0
|###[ B ]###
| value = 10
|###[ B ]###
| value = 2
changed the title [-][bug] Avoid modifying default values of packet list fileds[/-][+][bug] Avoid modifying default values of packet list fields[/+]on May 9, 2025
For the reminder, the #4727 PR I'm working onto proposes a fix for this issue. Shall we reopen?
If you're bringing a performance improvement, it's a good PR but separate from this issue. I don't consider the behavior described in this issue to be something we want to fix.
Activity
[-][bug] Avoid modifying default values of packet list fileds[/-][+][bug] Avoid modifying default values of packet list fields[/+]gpotter2 commentedon May 29, 2025
I would argue that this is the expected behavior. In the same way that Python's default parameters can be modified, like in the following:
Modifying a default is unsupported.
alxroyer-thales commentedon Jun 2, 2025
Oh! I was not aware of that default behaviour of Python 😄
But that makes it clear why IDEs like PyCharm raise warnings on it.
I still think that this is some unwanted behaviour, and that Scapy should not rely on that to keep it the current way.
For the reminder, the #4727 PR I'm working onto proposes a fix for this issue. Shall we reopen?
gpotter2 commentedon Jun 2, 2025
If you're bringing a performance improvement, it's a good PR but separate from this issue. I don't consider the behavior described in this issue to be something we want to fix.
alxroyer-thales commentedon Jun 2, 2025
Understood. I'll remove the fix for this issue in PR #4727.