Skip to content

Commit

Permalink
Merge pull request usnistgov#17 from vladimirralev/multipart-parse-ex…
Browse files Browse the repository at this point in the history
…ception

Multipart parse exception
  • Loading branch information
ranganathanm authored Oct 20, 2016
2 parents 4d1bc8a + 586f71b commit b06ec0e
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/gov/nist/javax/sip/message/MultipartMimeContentImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Scanner;

import javax.sip.header.ContentDispositionHeader;
Expand Down Expand Up @@ -121,9 +122,13 @@ public void createContentList(String body) throws ParseException {
// scanner.useDelimiter("--" + boundary + "(--)?\r?\n?");
scanner.useDelimiter("\r?\n?--" + boundary + "(--)?\r?\n?");
while (scanner.hasNext()) {
String bodyPart = scanner.next();
Content partContent = parseBodyPart(bodyPart);
contentList.add(partContent);
try {
String bodyPart = scanner.next();
Content partContent = parseBodyPart(bodyPart);
contentList.add(partContent);
} catch (NoSuchElementException e) {
//ignore
}
}
} else {
// No boundary had been set, we will consider the body as a single part
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,82 @@ public class MultipartMimeParserTest extends TestCase {
+ "Content-Type: application/x-nt-epid-frag-hex;version=ssLinux-6.00.18;base=x2611\r\n"
+ "Content-Disposition: signal;handling=optional\r\n\r\n" + "011201\r\n" + "00:1b:ba:fd:3d:0f\r\n"
+ "--unique-boundary-1\r\n";

private static final String usnistgovissue16 =
"--unique-boundary-1\n\r" +
"Content-Type: application/sdp\n\r" +
"\n\r" +
"v=0\n\r" +
"o=- 999999 999999 IN IP4 99.99.99.99\n\r" +
"s=-\n\r" +
"c=IN IP4 99.99.99.99\n\r" +
"t=0 0\n\r" +
"m=audio 99999 RTP/AVP 0 101\n\r" +
"a=rtpmap:0 PCMU/8000\n\r" +
"a=rtpmap:101 telephone-event/8000\n\r" +
"a=fmtp:101 0-15\n\r" +
"a=maxptime:20\n\r" +
"a=label:3199936\n\r" +
"a=inactive\n\r" +
"m=audio 0 RTP/AVP 0 101\n\r" +
"a=rtpmap:0 PCMU/8000\n\r" +
"a=rtpmap:101 telephone-event/8000\n\r" +
"a=fmtp:101 0-15\n\r" +
"a=maxptime:20\n\r" +
"a=inactive\n\r" +
"a=label:3199937\n\r" +
"\n\r" +
"--unique-boundary-1\n\r" +
"Content-Type: application/rs-metadata+xml\n\r" +
"Content-Disposition: recording-session\n\r" +
"\n\r" +
"<?xml version='1.0' encoding='UTF-8'?>\n" +
"<recording xmlns='urn:ietf:params:xml:ns:recording'>\n" +
"\t<datamode>complete</datamode>\n" +
"\t<session id=\"Rs1tZH5ISWxYdbRm/2R4fA==\">\n" +
"\t\t<associate-time>2016-10-12T12:07:18</associate-time>\n" +
"\t\t<extensiondata xmlns:apkt=\"http://acmepacket.com/siprec/extensiondata\">\n" +
"\t\t\t<apkt:ucid>00FA08XXXXXXXXXXXXXXXX;encoding=hex</apkt:ucid>\n" +
"\t\t\t<apkt:callerOrig>true</apkt:callerOrig>\n" +
"\t\t</extensiondata>\n" +
"\t</session>\n" +
"\t<participant id=\"nN+uOmP7TNBKfStkgTAKlw==\" session=\"Rs1tZH5ISWxYdbRm/2R4fA==\">\n" +
"\t\t<nameID aor=\"sip:[email protected]\">\n" +
"\t\t\t<name>&quot;XXXXXXXXXXXXXXX&quot;</name>\n" +
"\t\t</nameID>\n" +
"\t\t<send>GjCvWYoEQh9zN9TsyCVl/w==</send>\n" +
"\t\t<associate-time>2016-10-12T12:07:18</associate-time>\n" +
"\t\t<extensiondata xmlns:apkt=\"http://acmepacket.com/siprec/extensiondata\">\n" +
"\t\t\t<apkt:callingParty>true</apkt:callingParty>\n" +
"\t\t\t<apkt:request-uri>sip:[email protected]:5060</apkt:request-uri>\n" +
"\t\t\t<apkt:realm>outsideXO</apkt:realm>\n" +
"\t\t\t<apkt:header label=\"From\">\n" +
"\t\t\t\t<value>&quot;XXXXXXXXXXXXXXX&quot; &lt;sip:[email protected]:5060;pstn-params=9999999999&gt;;tag=xxxxxxxxxx</value>\n" +
"\t\t\t</apkt:header>\n" +
"\t\t\t<apkt:header label=\"To\">\n" +
"\t\t\t\t<value>&lt;sip:[email protected]:5060&gt;</value>\n" +
"\t\t\t</apkt:header>\n" +
"\t\t\t<apkt:header label=\"Call-ID\">\n" +
"\t\t\t\t<value>[email protected]</value>\n" +
"\t\t\t</apkt:header>\n" +
"\t\t</extensiondata>\n" +
"\t</participant>\n" +
"\t<participant id=\"xvlmDeIwSGZLYOtKGCUQvA==\" session=\"Rs1tZH5ISWxYdbRm/2R4fA==\">\n" +
"\t\t<nameID aor=\"sip:[email protected]\">\n" +
"\t\t\t<name>9999999999</name>\n" +
"\t\t</nameID>\n" +
"\t\t<associate-time>2016-10-12T12:07:18</associate-time>\n" +
"\t\t<extensiondata xmlns:apkt=\"http://acmepacket.com/siprec/extensiondata\">\n" +
"\t\t\t<apkt:callingParty>false</apkt:callingParty>\n" +
"\t\t</extensiondata>\n" +
"\t</participant>\n" +
"\t<stream id=\"GjCvWYoEQh9zN9TsyCVl/w==\" session=\"Rs1tZH5ISWxYdbRm/2R4fA==\">\n" +
"\t\t<label>3199936</label>\n" +
"\t\t<mode>separate</mode>\n" +
"\t\t<associate-time>2016-10-12T12:07:18</associate-time>\n" +
"\t</stream>\n" +
"</recording>\r\n" +
"--unique-boundary-1--\r\n";

private static String contentString2 =
"--boundary1\n"
Expand Down Expand Up @@ -288,6 +364,20 @@ public void testMultiPartMimeMarshallingAndUnMarshallingWithExtraHeadersAndSpace
checkMultiPartWithSpaces(multipartMimeContent2);
}

public void testMultiParUsnistgovtIssue16() throws Exception {
SIPRequest request = new SIPRequest();
byte[] content = usnistgovissue16.getBytes("UTF-8");
ContentType contentType = new ContentType("multipart", "mixed");
contentType.setParameter("boundary", "unique-boundary-1");

request.setContent(content, contentType);
MultipartMimeContent multipartMimeContent = request.getMultipartMimeContent();
Iterator<Content> partContentIterator = multipartMimeContent.getContents();
Content part1 = partContentIterator.next();
Content part2 = partContentIterator.next();
assertEquals("application/rs-metadata+xml", ((ContentType) part2.getContentTypeHeader()).getValue());
}

public void testMultiPartMimeMarshallingAndUnMarshallingWithANonMultiPartBodyWithAnEmptyLine() throws Exception {
SIPRequest request = new SIPRequest();
byte[] content = simpleContentWithEmptyLine.getBytes("UTF-8");
Expand Down Expand Up @@ -350,7 +440,7 @@ private void checkSimpleBody(MultipartMimeContent multipartMimeContent) {
assertNotNull(sdpPart.getContent());
assertFalse(partContentIterator.hasNext());
}

private byte[] toByteArray(InputStream input) throws IOException {
ByteArrayOutputStream output = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
Expand Down

0 comments on commit b06ec0e

Please sign in to comment.