]> git.parisson.com Git - pdf.js.git/commitdiff
Protect against a malicious setDatabase. Remove unneeded save data.
authorBrendan Dahl <brendan.dahl@gmail.com>
Tue, 7 Feb 2012 05:04:53 +0000 (21:04 -0800)
committerBrendan Dahl <brendan.dahl@gmail.com>
Tue, 7 Feb 2012 05:04:53 +0000 (21:04 -0800)
extensions/firefox/components/PdfStreamConverter.js
web/viewer.js

index 54cc6890da492fd21051c0f83b83e70cc758627a..78a1f5a46ff31cb0c35ca6cc51cf8b61c34d87e3 100644 (file)
@@ -48,6 +48,9 @@ ChromeActions.prototype = {
   setDatabase: function(data) {
     if (this.inPrivateBrowswing)
       return;
+    // Protect against something sending tons of data to setDatabase.
+    if (data.length > 4096)
+      return;
     application.prefs.setValue(EXT_PREFIX + '.database', data);
   },
   getDatabase: function() {
@@ -142,7 +145,7 @@ PdfStreamConverter.prototype = {
     // Setup a global listener waiting for the next DOM to be created and verfiy
     // that its the one we want by its URL. When the correct DOM is found create
     // an event listener on that window for the pdf.js events that require
-    // chrome priviledges.
+    // chrome priviledges. Code snippet from John Galt.
     let window = aRequest.loadGroup.groupObserver
                   .QueryInterface(Ci.nsIWebProgress)
                   .DOMWindow;
index 3aca926e9394d459727b79d83093ca4fbaa3f96c..5a1a1df03d3c2c870ec3eabd6c49e0917e6cb406 100644 (file)
@@ -109,7 +109,7 @@ var Settings = (function SettingsClosure() {
     var database = null;
     var index;
     if (isFirefoxExtension)
-      database = FirefoxCom.request('getDatabase', null);
+      database = FirefoxCom.request('getDatabase', null) || '{}';
     else if (isLocalStorageEnabled)
       database = localStorage.getItem('database') || '{}';
     else
@@ -131,8 +131,6 @@ var Settings = (function SettingsClosure() {
       index = database.files.push({fingerprint: fingerprint}) - 1;
     this.file = database.files[index];
     this.database = database;
-    if (isLocalStorageEnabled)
-      localStorage.setItem('database', JSON.stringify(database));
   }
 
   Settings.prototype = {