Bug 1592288 - Handle bad data in WebExt API message handling; r=mkmelin a=jorgk
authorGeoff Lankow <geoff@darktrojan.net>
Fri, 15 Nov 2019 11:54:57 +1300
changeset 36414 004fc2991ce3d1e1b6f7c85e4540f69e9812e4ab
parent 36413 f2f7e2432a04fe3a25bf50da78b3fcd08381d129
child 36415 c18a70f1c20ed8c76564da22eed5566d7ff2ac45
push id2527
push usermozilla@jorgk.com
push dateTue, 19 Nov 2019 08:49:01 +0000
treeherdercomm-beta@3e2b07cf1397 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkmelin, jorgk
bugs1592288
Bug 1592288 - Handle bad data in WebExt API message handling; r=mkmelin a=jorgk
mail/components/extensions/parent/ext-mail.js
mail/components/extensions/parent/ext-messages.js
--- a/mail/components/extensions/parent/ext-mail.js
+++ b/mail/components/extensions/parent/ext-mail.js
@@ -1495,18 +1495,23 @@ var messageListTracker = {
   },
 
   _getNextPage(messageList) {
     let messageCount = Services.prefs.getIntPref(
       "extensions.webextensions.messagesPerPage",
       100
     );
     let page = [];
-    for (let i = 0; i < messageCount && messageList.hasMoreElements(); i++) {
-      page.push(messageList.getNext().QueryInterface(Ci.nsIMsgDBHdr));
+    let i = 0;
+    while (i < messageCount && messageList.hasMoreElements()) {
+      let next = messageList.getNext();
+      if (next) {
+        page.push(next.QueryInterface(Ci.nsIMsgDBHdr));
+        i++;
+      }
     }
     return page;
   },
 };
 
 class MessageManager {
   constructor(extension) {
     this.extension = extension;
--- a/mail/components/extensions/parent/ext-messages.js
+++ b/mail/components/extensions/parent/ext-messages.js
@@ -192,17 +192,19 @@ this.messages = class extends ExtensionA
 
           let collectionArray = await new Promise(resolve => {
             query.getCollection({
               onItemsAdded(items, collection) {},
               onItemsModified(items, collection) {},
               onItemsRemoved(items, collection) {},
               onQueryCompleted(collection) {
                 resolve(
-                  collection.items.map(glodaMsg => glodaMsg.folderMessage)
+                  collection.items
+                    .map(glodaMsg => glodaMsg.folderMessage)
+                    .filter(Boolean)
                 );
               },
             });
           });
 
           if (queryInfo.unread !== null) {
             collectionArray = collectionArray.filter(
               msg => msg.isRead == !queryInfo.unread