Skip to content

Add SDP parsing regression tests for malformed crypto and rtpmap lines#1658

Merged
sipsorcery merged 2 commits into
masterfrom
tests/sdp-parsing-edge-cases
Jun 1, 2026
Merged

Add SDP parsing regression tests for malformed crypto and rtpmap lines#1658
sipsorcery merged 2 commits into
masterfrom
tests/sdp-parsing-edge-cases

Conversation

@sipsorcery
Copy link
Copy Markdown
Member

Summary

Adds regression tests pinning the desired SDP parser behaviour for recognised-but-invalid lines — lines whose attribute type the parser understands but whose content is malformed. Tests only; no production code changes.

Test Input Expected
CryptoLineWithWhitespaceValueReturnsFalse a=crypto: TryParse returns false (no throw)
CryptoLineWithMissingCryptoSuiteReturnsFalse a=crypto:1 TryParse returns false (no throw)
CryptoLineWithMissingKeyParamsReturnsFalse a=crypto:1 AES_CM_128_HMAC_SHA1_80 TryParse returns false
NonNumericRtpmapIdIsDroppedNotRoundTripped a=rtpmap:xyz nonsense/1 line is dropped — no media format entry, valid formats intact, not re-emitted by ToString()

Behavioural principle being encoded

  • A genuinely unknown attribute line (parser doesn't recognise the type) → round-trip it, since the parser can't judge it.
  • A recognised-but-invalid line (parser knows it's an rtpmap/crypto but the content is bad) → drop it. RTP payload types are always numeric, so a non-numeric rtpmap id is known-bad and should not survive a round-trip.

⚠️ Expected to fail on master

These tests encode the behaviour delivered by #1655 (Span-based SDP rewrite). Against the current master parser they fail, by design:

  • the two malformed crypto lines throw IndexOutOfRangeException (latent crash in SDPSecurityDescription.TryParse, which indexes sCryptoParts[0]/[1] without a length guard);
  • the non-numeric rtpmap line is round-tripped as an extra attribute instead of being dropped.

Verified: 4/4 pass on the #1655 branch; on master 3 fail / 1 passes. They will go green once #1655 merges. The crash fixes themselves are coming in #1655, so this PR intentionally carries no production changes.

🤖 Generated with Claude Code

Adds regression tests asserting the desired SDP parser behaviour for
recognised-but-invalid lines:

- a crypto line with a whitespace-only value -> TryParse returns false
- a crypto line missing the crypto-suite field -> TryParse returns false
- a crypto line missing key parameters       -> TryParse returns false
- an rtpmap attribute with a non-numeric payload ID is dropped (not
  round-tripped): it produces no media format entry, does not corrupt
  the valid formats, and is not re-emitted by ToString().

These encode the intended behaviour delivered by #1655. They are
expected to fail against the current master parser (which throws an
IndexOutOfRangeException on the malformed crypto lines and round-trips
the invalid rtpmap line) and to pass once #1655 lands. Tests only; no
production code changes.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
{
private const string CRLF = "\r\n";

private Microsoft.Extensions.Logging.ILogger logger = null;
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
@sipsorcery sipsorcery merged commit b37e7a3 into master Jun 1, 2026
1 check passed
@sipsorcery sipsorcery deleted the tests/sdp-parsing-edge-cases branch June 1, 2026 14:57
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