fix SIP body truncation with AudioCodes SBC - #45
Merged
Conversation
The CRLF normalizer was converting bare \n to \r\n across the entire UDP packet, including the message body. When an SBC (e.g. AudioCodes) sends bare LFs in a multipart SIPREC body, this expansion makes the body longer than Content-Length declares, so sipgo reads only Content-Length bytes and truncates the rest. The multipart reader then hits unexpected EOF before finding the rs-metadata part. Fix: find the header/body separator first, normalize only the header section, and pass the body through untouched. Adds findHeaderBodySplit which handles all four separator variants (\r\n\r\n, \n\n, \r\n\n, \n\r\n). Zero-copy fast path when no normalization is needed. Closes #44
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe CRLF normalizer now detects the SIP header/body boundary, normalizes bare line feeds in headers only, and preserves body bytes. Tests cover multipart, binary, UDP, separator, passthrough, and benchmark cases. ChangesSIP CRLF normalization
Estimated code review effort: 3 (Moderate) | ~20 minutes Severity of issue fixed: Medium ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Closed
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.
What happened
The CRLF normalizer (added for sipgo#292 bare-LF compat) was normalizing the entire UDP packet — headers and body. When an AudioCodes SBC sends a multipart SIPREC INVITE with bare
\nline endings in the body, the normalizer expands those to\r\n, making the body longer than theContent-Lengthheader says. sipgo then reads onlyContent-Lengthbytes, chopping the body mid-XML. The multipart reader hits EOF before finding the rs-metadata part and the call gets rejected.What this fixes
normalizeCRLFnow finds the header/body separator first and only normalizes the header section. The body passes through byte-for-byte, soContent-Lengthstays accurate and the multipart parser gets the full payload.findHeaderBodySplit()— handles all four separator variants (\r\n\r\n,\n\n,\r\n\n,\n\r\n)normalizeCRLFBytes(internal)\r\nTests
0x0abytes in body aren't mistaken for line endingscrlfPacketConnand checks body integrityCloses #44
Summary by CodeRabbit