Bug 1623896 - Embedded NULL bytes in text/* throws off parsing. r=benc a=wsmwk
authoralex <alex@grundis.de>
Mon, 23 Mar 2020 18:54:46 +0200
changeset 37554 c46c32f10db06e9528bb2f38035c506c700e93f7
parent 37553 2827caab16c9ea714b33f349246845e1fd9840d0
child 37555 9e5d4c565ea0451f5a20006b386f3558448e7df0
push id2573
push userthunderbird@calypsoblue.org
push dateWed, 25 Mar 2020 02:15:38 +0000
treeherdercomm-beta@c46c32f10db0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbenc, wsmwk
bugs1623896
Bug 1623896 - Embedded NULL bytes in text/* throws off parsing. r=benc a=wsmwk
mailnews/mime/src/nsSimpleMimeConverterStub.cpp
--- a/mailnews/mime/src/nsSimpleMimeConverterStub.cpp
+++ b/mailnews/mime/src/nsSimpleMimeConverterStub.cpp
@@ -53,17 +53,17 @@ static int GatherLine(const char *line, 
 
   if (!obj->output_p || !obj->options || !obj->options->output_fn) {
     return 0;
   }
 
   if (!obj->options->write_html_p)
     return MimeObject_write(obj, line, length, true);
 
-  ssobj->buffer->Append(line);
+  ssobj->buffer->Append(line, length);
   return 0;
 }
 
 static int EndGather(MimeObject *obj, bool abort_p) {
   MimeSimpleStub *ssobj = (MimeSimpleStub *)obj;
 
   if (obj->closed_p) return 0;
 
@@ -75,26 +75,30 @@ static int EndGather(MimeObject *obj, bo
 
   mime_stream_data *msd = (mime_stream_data *)(obj->options->stream_closure);
   nsIChannel *channel = msd->channel;  // note the lack of ref counting...
   if (channel) {
     nsCOMPtr<nsIURI> uri;
     channel->GetURI(getter_AddRefs(uri));
     ssobj->innerScriptable->SetUri(uri);
   }
+  // Remove possible embedded NULL bytes.
+  // Parsers can't handle this but e.g. calendar invitation might contain such
+  // as fillers.
+  ssobj->buffer->StripChar('\0');
   nsCString asHTML;
   nsresult rv = ssobj->innerScriptable->ConvertToHTML(
       nsDependentCString(obj->content_type), *ssobj->buffer, asHTML);
   if (NS_FAILED(rv)) {
     NS_ASSERTION(NS_SUCCEEDED(rv), "converter failure");
     return -1;
   }
 
   // MimeObject_write wants a non-const string for some reason, but it doesn't
-  // mutate it
+  // mutate it.
   status = MimeObject_write(obj, asHTML.get(), asHTML.Length(), true);
   if (status < 0) return status;
   return 0;
 }
 
 static int Initialize(MimeObject *obj) {
   MimeSimpleStub *ssobj = (MimeSimpleStub *)obj;