Bug 1445026: Don't try to decode a binary hash blob as UTF-8. r?rpl draft
authorKris Maglione <maglione.k@gmail.com>
Mon, 12 Mar 2018 14:18:43 -0700
changeset 766440 684d4ecf9ab7cf587d25bd5e9ce385305ba21d65
parent 766437 156cad0b9e1737d97b02b71710bdf649d1d9f855
push id102325
push usermaglione.k@gmail.com
push dateMon, 12 Mar 2018 21:28:43 +0000
reviewersrpl
bugs1445026
milestone60.0a1
Bug 1445026: Don't try to decode a binary hash blob as UTF-8. r?rpl MozReview-Commit-ID: 91QNBYVQgQU
toolkit/components/extensions/ExtensionContent.jsm
--- a/toolkit/components/extensions/ExtensionContent.jsm
+++ b/toolkit/components/extensions/ExtensionContent.jsm
@@ -29,17 +29,17 @@ const DocumentEncoder = Components.Const
   "nsIDocumentEncoder", "init");
 
 const Timer = Components.Constructor("@mozilla.org/timer;1", "nsITimer", "initWithCallback");
 
 ChromeUtils.import("resource://gre/modules/ExtensionChild.jsm");
 ChromeUtils.import("resource://gre/modules/ExtensionCommon.jsm");
 ChromeUtils.import("resource://gre/modules/ExtensionUtils.jsm");
 
-Cu.importGlobalProperties(["crypto", "TextDecoder", "TextEncoder"]);
+Cu.importGlobalProperties(["crypto", "TextEncoder"]);
 
 const {
   DefaultMap,
   DefaultWeakMap,
   defineLazyGetter,
   getInnerWindowID,
   getWinUtils,
   promiseDocumentIdle,
@@ -308,17 +308,17 @@ class Script {
 
   async addCSSCode(cssCode) {
     if (!cssCode) {
       return;
     }
 
     // Store the hash of the cssCode.
     const buffer = await crypto.subtle.digest("SHA-1", new TextEncoder().encode(cssCode));
-    this.cssCodeHash = new TextDecoder().decode(buffer);
+    this.cssCodeHash = String.fromCharCode(...new Uint16Array(buffer));
 
     // Cache and preload the cssCode stylesheet.
     this.cssCodeCache.addCSSCode(this.cssCodeHash, cssCode);
   }
 
   compileScripts() {
     return this.js.map(url => this.scriptCache.get(url));
   }