<p>I finally had some time to look into the source code, the issue comes from the file textops/textops.c:2071</p>
<div class="highlight highlight-source-c"><pre> <span class="pl-k">while</span> (find_line_start(<span class="pl-s"><span class="pl-pds">"</span>Content-Type: <span class="pl-pds">"</span></span>, <span class="pl-c1">14</span>, &start, &len))
{
end = start + <span class="pl-c1">14</span>;
len = len - <span class="pl-c1">14</span>;
<span class="pl-k">if</span> (len > (content_type.<span class="pl-smi">len</span> + <span class="pl-c1">2</span>)) {
<span class="pl-k">if</span> (<span class="pl-c1">strncasecmp</span>(end, content_type.<span class="pl-smi">s</span>, content_type.<span class="pl-smi">len</span>)== <span class="pl-c1">0</span>)
{
<span class="pl-c1">LM_DBG</span>(<span class="pl-s"><span class="pl-pds">"</span>found content type <span class="pl-c1">%.*s</span><span class="pl-cce">\n</span><span class="pl-pds">"</span></span>,
content_type.<span class="pl-smi">len</span>, content_type.<span class="pl-smi">s</span>);
end = end + content_type.<span class="pl-smi">len</span>;
<span class="pl-k">if</span> ((*end != <span class="pl-c1">13</span>) || (*(end + <span class="pl-c1">1</span>) != <span class="pl-c1">10</span>))
{
<span class="pl-c1">LM_ERR</span>(<span class="pl-s"><span class="pl-pds">"</span>no CRLF found after content type<span class="pl-cce">\n</span><span class="pl-pds">"</span></span>);
<span class="pl-k">goto</span> err;
}
end = end + <span class="pl-c1">2</span>;
len = len - content_type.<span class="pl-smi">len</span> - <span class="pl-c1">2</span>;
body_headers_end = end;
<span class="pl-k">if</span> (<span class="pl-c1">find_line_start</span>(boundary.<span class="pl-smi">s</span>, boundary.<span class="pl-smi">len</span>, &end,
&len))
{</pre></div>
<p>Thanks to the pull "textops: Fix get_body_part() end of body headers <a href="https://github.com/kamailio/kamailio/pull/423" class="issue-link js-issue-link" data-url="https://github.com/kamailio/kamailio/issues/423" data-id="119286013" data-error-text="Failed to load issue title" data-permission-text="Issue title is private">#423</a>" by smititelu, textops is now able to find the end of multipart headers in the simple case of just a "Content-type" header. But it is not able to handle more complex cases like this one for instance (from RFC 5621 <a href="https://tools.ietf.org/html/rfc5621#section-3.1">https://tools.ietf.org/html/rfc5621#section-3.1</a>):</p>
<pre><code> INVITE sip:conf-fact@example.com SIP/2.0
Content-Type: multipart/mixed;boundary="boundary1"
Content-Length: 619
--boundary1
Content-Type: application/sdp
v=0
o=alice 2890844526 2890842807 IN IP4 atlanta.example.com
s=-
c=IN IP4 192.0.2.1
t=0 0
m=audio 20000 RTP/AVP 0
a=rtpmap:0 PCMU/8000
m=video 20002 RTP/AVP 31
a=rtpmap:31 H261/90000
--boundary1
Content-Type: application/resource-lists+xml
Content-Disposition: recipient-list
<?xml version="1.0" encoding="UTF-8"?>
<resource-lists xmlns="urn:ietf:params:xml:ns:resource-lists">
<list>
<entry uri="sip:bill@example.com"/>
<entry uri="sip:randy@example.net"/>
<entry uri="sip:joe@example.org"/>
</list>
</resource-lists>
--boundary1--
Figure 2: SIP message carrying a body
</code></pre>
<p>Here "Content-Disposition: recipient-list" would be taken into the second body because the variable body_headers_end would be set just after the content type header by find_line_start("Content-Type: ", 14, &start, &len).</p>
<p>I think that maybe something like:</p>
<div class="highlight highlight-source-c"><pre>body_headers_end = find_line_start(<span class="pl-s"><span class="pl-pds">"</span><span class="pl-cce">\r\n</span><span class="pl-pds">"</span></span>, <span class="pl-c1">14</span>, &start, &len);</pre></div>
<p>Instead of:</p>
<div class="highlight highlight-source-c"><pre>body_headers_end = end;</pre></div>
<p>Might help. Because a \r\n should always separate headers from the body as it is specified for instance in RFC 3261 (<a href="https://tools.ietf.org/html/rfc3261#section-7">https://tools.ietf.org/html/rfc3261#section-7</a>) for SIP headers:</p>
<pre><code> generic-message = start-line
*message-header
CRLF
[ message-body ]
start-line = Request-Line / Status-Line
</code></pre>
<p>I will test this solution as soon I will have more spare time.</p>
<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you commented.<br />Reply to this email directly or <a href="https://github.com/kamailio/kamailio/issues/564#issuecomment-213852048">view it on GitHub</a><img alt="" height="1" src="https://github.com/notifications/beacon/AF36ZUPvanqOefhJ27iO78bsqEppyr05ks5p6qcHgaJpZM4IESnF.gif" width="1" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
<div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
<link itemprop="url" href="https://github.com/kamailio/kamailio/issues/564#issuecomment-213852048"></link>
<meta itemprop="name" content="View Issue"></meta>
</div>
<meta itemprop="description" content="View this Issue on GitHub"></meta>
</div>