Bug 1341932 - Ignore preamble in multimixed converter. r=valentin
authorHonza Bambas <honzab.moz@firemni.cz>
Thu, 23 Feb 2017 09:14:00 -0500
changeset 373810 6a9d8f01342be19b7b82f5e91fd71e814a38aeed
parent 373809 d97694450aada1b671c8d01e55eec5f893289344
child 373811 973ab774ff18859d5a451a7fe3dc09debed49605
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvalentin
bugs1341932
milestone54.0a1
Bug 1341932 - Ignore preamble in multimixed converter. r=valentin
netwerk/streamconv/converters/nsMultiMixedConv.cpp
netwerk/streamconv/converters/nsMultiMixedConv.h
netwerk/test/unit/test_multipart_streamconv_missing_boundary_lead_dashes.js
netwerk/test/unit/test_multipart_streamconv_missing_lead_boundary.js
--- a/netwerk/streamconv/converters/nsMultiMixedConv.cpp
+++ b/netwerk/streamconv/converters/nsMultiMixedConv.cpp
@@ -601,38 +601,32 @@ nsMultiMixedConv::OnStopRequest(nsIReque
 }
 
 nsresult
 nsMultiMixedConv::ConsumeToken(Token const & token)
 {
   nsresult rv;
 
   switch (mParserState) {
-    case BOUNDARY:
+    case PREAMBLE:
       if (token.Equals(mBoundaryTokenWithDashes)) {
         // The server first used boundary '--boundary'.  Hence, we no longer
         // accept plain 'boundary' token as a delimiter.
         mTokenizer.RemoveCustomToken(mBoundaryToken);
         mParserState = BOUNDARY_CRLF;
         break;
       }
       if (token.Equals(mBoundaryToken)) {
         // And here the opposite from the just above block...
         mTokenizer.RemoveCustomToken(mBoundaryTokenWithDashes);
         mParserState = BOUNDARY_CRLF;
         break;
       }
 
-      // In case the server didn't send the first boundary...
-      // This may be either a line-feed or a header.  Turn header tokens
-      // on and retry in a shifted parser state.
-      mParserState = HEADER_NAME;
-      mResponseHeader = HEADER_UNKNOWN;
-      SetHeaderTokensEnabled(true);
-      mTokenizer.Rollback();
+      // This is a preamble, just ignore it and wait for the boundary.
       break;
 
     case BOUNDARY_CRLF:
       if (token.Equals(Token::NewLine())) {
         mParserState = HEADER_NAME;
         mResponseHeader = HEADER_UNKNOWN;
         HeadersToDefault();
         SetHeaderTokensEnabled(true);
--- a/netwerk/streamconv/converters/nsMultiMixedConv.h
+++ b/netwerk/streamconv/converters/nsMultiMixedConv.h
@@ -169,28 +169,28 @@ protected:
     uint32_t            mCurrentPartID;
 
     // Flag preventing reenter of OnDataAvailable in case the target listener
     // ends up spinning the event loop.
     bool                mInOnDataAvailable;
 
     // Current state of the incremental parser
     enum EParserState {
-      BOUNDARY,
+      PREAMBLE,
       BOUNDARY_CRLF,
       HEADER_NAME,
       HEADER_SEP,
       HEADER_VALUE,
       BODY_INIT,
       BODY,
       TRAIL_DASH1,
       TRAIL_DASH2,
       EPILOGUE,
 
-      INIT = BOUNDARY
+      INIT = PREAMBLE
     } mParserState;
 
     // Response part header value, valid when we find a header name
     // we recognize.
     enum EHeader : uint32_t {
       HEADER_FIRST,
       HEADER_CONTENT_TYPE = HEADER_FIRST,
       HEADER_CONTENT_LENGTH,
--- a/netwerk/test/unit/test_multipart_streamconv_missing_boundary_lead_dashes.js
+++ b/netwerk/test/unit/test_multipart_streamconv_missing_boundary_lead_dashes.js
@@ -6,17 +6,17 @@ var httpserver = null;
 XPCOMUtils.defineLazyGetter(this, "uri", function() {
   return "http://localhost:" + httpserver.identity.primaryPort + "/multipart";
 });
 
 function make_channel(url) {
   return NetUtil.newChannel({uri: url, loadUsingSystemPrincipal: true});
 }
 
-var multipartBody = "\r\nSome text\r\nboundary\r\n\r\n<?xml version='1.0'?><root/>\r\nboundary--";
+var multipartBody = "\r\nboundary\r\n\r\nSome text\r\nboundary\r\n\r\n<?xml version='1.0'?><root/>\r\nboundary--";
 
 function contentHandler(metadata, response)
 {
   response.setHeader("Content-Type", 'multipart/mixed; boundary="boundary"');
   response.bodyOutputStream.write(multipartBody, multipartBody.length);
 }
 
 var numTests = 2;
--- a/netwerk/test/unit/test_multipart_streamconv_missing_lead_boundary.js
+++ b/netwerk/test/unit/test_multipart_streamconv_missing_lead_boundary.js
@@ -6,17 +6,17 @@ var httpserver = null;
 XPCOMUtils.defineLazyGetter(this, "uri", function() {
   return "http://localhost:" + httpserver.identity.primaryPort + "/multipart";
 });
 
 function make_channel(url) {
   return NetUtil.newChannel({uri: url, loadUsingSystemPrincipal: true});
 }
 
-var multipartBody = "\r\nSome text\r\n--boundary\r\n\r\n<?xml version='1.0'?><root/>\r\n--boundary--";
+var multipartBody = "Preamble\r\n--boundary\r\n\r\nSome text\r\n--boundary\r\n\r\n<?xml version='1.0'?><root/>\r\n--boundary--";
 
 function contentHandler(metadata, response)
 {
   response.setHeader("Content-Type", 'multipart/mixed; boundary="boundary"');
   response.bodyOutputStream.write(multipartBody, multipartBody.length);
 }
 
 var numTests = 2;