http: return one Content-Length message per packet - #5134
Open
KernelClint wants to merge 1 commit into
Open
Conversation
AI-Assisted: yes (GPT-5.6-Cyber)
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #5134 +/- ##
==========================================
- Coverage 80.63% 80.63% -0.01%
==========================================
Files 390 390
Lines 96936 96943 +7
==========================================
+ Hits 78168 78172 +4
- Misses 18768 18771 +3
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Scapy's HTTP stream session accumulates bytes until a message is complete, then returns it. For a
message with
Content-Length, completeness is decided atscapy/layers/http.py:665-745by comparing the buffer length against the header length plus the declared body length.
The test is correct, but the packet returned is built from the whole accumulated buffer. If one
socket read carried two complete requests, the extra bytes ride along inside the first packet.
ForwardMachinethen calls its policy callback once and forwards the serialisation of everything itwas given, so the second request crosses without ever being offered to the callback.
The change records where the message actually ends and represents the remainder as padding:
The stream session already carries padding forward to the next message, so the second request is
returned on the following iteration and gets its own callback. No
ForwardMachine-specific parsingis added.
The added regression feeds two complete requests in one read and asserts the callback sees both.
Without the source change it fails.
Performance was measured on one computer, before and after the fix: a forwarded request took
32.5 µs before and 32.0 µs after. Repeat runs of this test moved by about 7%, which is wide enough
that only a large change would show — this is not one.