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 36155 bae5d67808ad7c1e3ddaa48b69bc1ac2a10b3c95
parent 36154 fc518fe0390daf5a4af94692f775839bc43b2a00
child 36156 ba79c4381e0c7b431bf955603ddc3ba809d6391f
push id97
push userthunderbird@calypsoblue.org
push dateTue, 07 Apr 2020 16:09:32 +0000
treeherdercomm-esr68@f7099fd16d6f [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
@@ -54,17 +54,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;
 
@@ -76,26 +76,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;