ms_nrtp: bound NRBF string lengths to 31 bits - #5135
Open
KernelClint wants to merge 1 commit into
Open
Conversation
AI-Assisted: yes (GPT-5.6-Cyber)
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #5135 +/- ##
=======================================
Coverage 80.63% 80.64%
=======================================
Files 390 390
Lines 96936 96941 +5
=======================================
+ Hits 78168 78181 +13
+ Misses 18768 18760 -8
🚀 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.
NRTP reassembly decodes an
application/octet-streambody as .NET Remoting Binary Format. NRBFencodes a string's length as a variable-length integer, seven bits per byte, and the format caps it
at five bytes and 31 bits.
scapy/layers/ms_nrtp.py:333-350uses the generic extended-integer decoder for that field, and the generic decoder has no cap. It
keeps consuming continuation bytes and shifting a Python integer that grows with the input, so the
work is quadratic in the number of bytes supplied — all before it looks for the string data, which
does not exist.
The change enforces the limit the format already defines, in the NRBF-specific field, before the
generic decoder runs:
The largest valid encoding,
ff ff ff ff 07, is still accepted; only encodings the format does notpermit are rejected.
The added regression parses that maximum encoding and then an over-wide one, asserting the first is
accepted and the second raises. Without the source change the NRTP suite reports 2 passed and 1
failed; with it, 3 passed and 0 failed.
Performance was measured on one computer, before and after the fix: parsing a valid NRBF body took
4,430.4 ns before and 4,598.5 ns after. Repeat runs of this test moved by about 9%, which is wide
enough that only a large change would show — this is not one.