Skip to content

ms_nrtp: bound NRBF string lengths to 31 bits - #5135

Open
KernelClint wants to merge 1 commit into
secdev:masterfrom
KernelClint:nrbf-bound-string-length
Open

ms_nrtp: bound NRBF string lengths to 31 bits#5135
KernelClint wants to merge 1 commit into
secdev:masterfrom
KernelClint:nrbf-bound-string-length

Conversation

@KernelClint

Copy link
Copy Markdown
Contributor

NRTP reassembly decodes an application/octet-stream body as .NET Remoting Binary Format. NRBF
encodes 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-350
uses 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:

+    def getfield(self, pkt, s):
+        if len(s) >= 5 and min(s[:4]) >= 0x80 and s[4] > 0x07:
+            raise Scapy_Exception("NRBF string length exceeds 31 bits")
+        return super(MSBExtendedFieldLen, self).getfield(pkt, s)

The largest valid encoding, ff ff ff ff 07, is still accepted; only encodings the format does not
permit 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.

AI-Assisted: yes (GPT-5.6-Cyber)
@codecov

codecov Bot commented Sep 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.64%. Comparing base (b3bbcc8) to head (d4b745d).

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     
Files with missing lines Coverage Δ
scapy/layers/ms_nrtp.py 82.08% <100.00%> (+0.29%) ⬆️

... and 10 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant