FieldListFields used non-exclusively in a MultipleTypeField don't build correctly
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 12.6k
- Forks
- 2.2k
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 56
Description
Brief description
I am using a MultipleTypeField to switch between a complex field (itself a MultipleTypeField) and a FieldListField of that field for array types. The definition works while dissecting, but it does not work when trying to build the packet unless that packet was constructed from bytes.
I tried doing some debugging to see if I could come up with a workaround, and I did notice something: during building, Packet.getfieldval returns the first element of the value array instead of the entire array as I would expect. This may mean that the outer MultipleTypeField is returning dflt when it's not supposed to, though strangely the inner MultipleTypeField is working correctly.
Scapy version
scapy-2.4.5rc1.dev293 (commit ba9fff2)
Python version
3.10.4
Operating system
Ubuntu 22.04 LTS on WSL2
Additional environment information
No response
How to reproduce
Gist with a script to reproduce the issue
Actual result
Traceback (most recent call last):
File "/<project>/scapybug.py", line 64, in <module>
test_pkt_arr_filled = DataPacket(raw(test_pkt_arr))
File "/<project>/venv/lib/python3.10/site-packages/scapy/compat.py", line 294, in raw
return bytes(x)
File "/<project>/venv/lib/python3.10/site-packages/scapy/packet.py", line 586, in __bytes__
return self.build()
File "/<project>/venv/lib/python3.10/site-packages/scapy/packet.py", line 727, in build
p = self.do_build()
File "/<project>/venv/lib/python3.10/site-packages/scapy/packet.py", line 707, in do_build
pkt = self.self_build()
File "/<project>/venv/lib/python3.10/site-packages/scapy/packet.py", line 686, in self_build
raise ex
File "/<project>/venv/lib/python3.10/site-packages/scapy/packet.py", line 677, in self_build
p = f.addfield(self, p, val)
File "/<project>/venv/lib/python3.10/site-packages/scapy/fields.py", line 537, in addfield
return fld.addfield(pkt, s, val)
File "/<project>/venv/lib/python3.10/site-packages/scapy/fields.py", line 2002, in addfield
for v in val:
TypeError: While dissecting field 'value': 'int' object is not iterable
Expected result
The program should not crash, and test_pkt_arr_filled == test_pkt_arr_raw should be True.
Related resources
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the reproduction script linked in the issue, then inspect the build path around scapy/packet.py and scapy/fields.py, especially the FieldListField addfield traceback. Trace why the outer MultipleTypeField supplies a scalar during construction; done means the packet builds without the TypeError and test_pkt_arr_filled == test_pkt_arr_raw.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100