Bug 1423432 - remove null characters from headers (idea by jcranmer). r=mkmelin
authorJorg K <jorgk@jorgk.com>
Thu, 07 Dec 2017 22:27:47 +0100
changeset 22821 356b95d1856cf1ff45367c4d666a69d141695dea
parent 22820 b38e2320eddafb839458a962e55c381a9dce1848
child 22822 564d515b57a1fd5ea737fe8589065e6747221e67
push id13823
push usermozilla@jorgk.com
push dateThu, 07 Dec 2017 22:20:08 +0000
treeherdercomm-central@356b95d1856c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkmelin
bugs1423432
Bug 1423432 - remove null characters from headers (idea by jcranmer). r=mkmelin
mailnews/mime/src/mimeJSComponents.js
mailnews/mime/test/unit/test_nsIMsgHeaderParser5.js
--- a/mailnews/mime/src/mimeJSComponents.js
+++ b/mailnews/mime/src/mimeJSComponents.js
@@ -220,18 +220,23 @@ var EmailGroup = {
 };
 
 // A helper method for parse*Header that takes into account the desire to
 // preserve group and also tweaks the output to support the prototypes for the
 // XPIDL output.
 function fixArray(addresses, preserveGroups, count) {
   function resetPrototype(obj, prototype) {
     let prototyped = Object.create(prototype);
-    for (var key of Object.getOwnPropertyNames(obj))
-      prototyped[key] = obj[key];
+    for (let key of Object.getOwnPropertyNames(obj)) {
+      if (typeof obj[key] == "string") {
+        prototyped[key] = obj[key].replace(/\x00/g, '');
+      } else {
+        prototyped[key] = obj[key];
+      }
+    }
     return prototyped;
   }
   let outputArray = [];
   for (let element of addresses) {
     if ('group' in element) {
       // Fix up the prototypes of the group and the list members
       element = resetPrototype(element, EmailGroup);
       element.group = element.group.map(e => resetPrototype(e, Mailbox));
--- a/mailnews/mime/test/unit/test_nsIMsgHeaderParser5.js
+++ b/mailnews/mime/test/unit/test_nsIMsgHeaderParser5.js
@@ -38,16 +38,25 @@ function run_test() {
      [{name: "foo\u00D0 bar", email: "foo@bar.invalid"},
       {name: "\u00C3\u00B6foo", email: "ghj@foo.invalid"}],
      [{name: "foo\uFFFD bar", email: "foo@bar.invalid"},
       {name: "\u00F6foo", email: "ghj@foo.invalid"}]],
     // Bug 961564
     ["someone <>",
      [{name: "someone", email: ""}],
      [{name: "someone", email: ""}]],
+    // Bug 1423432: Encoded strings with null bytes,
+    // in base64 a single null byte can be encoded as AA== to AP==.
+    // parseEncodedHeader will remove the nullbyte.
+    ["\"null=?UTF-8?Q?=00?=byte\" <nullbyte@example.com>",
+      [{name: "null=?UTF-8?Q?=00?=byte", email: "nullbyte@example.com"}],
+      [{name: "nullbyte", email: "nullbyte@example.com"}]],
+    ["\"null=?UTF-8?B?AA==?=byte\" <nullbyte@example.com>",
+      [{name: "null=?UTF-8?B?AA==?=byte", email: "nullbyte@example.com"}],
+      [{name: "nullbyte", email: "nullbyte@example.com"}]],
   ];
 
   for (let check of checks) {
     equalArrays(MailServices.headerParser.parseDecodedHeader(check[0]),
       check[1]);
     equalArrays(MailServices.headerParser.parseEncodedHeader(check[0], "UTF-8"),
       check[2]);
   }