Bug 1057137 - Broken menu: NS_ERROR_ILLEGAL_VALUE: id, attribute, or value too long. r=enn
authorRoberto A. Vitillo <rvitillo@mozilla.com>
Fri, 29 Aug 2014 06:52:00 +0200
changeset 202949 7da521607978713ab7bf8783306135f6a25a7ff1
parent 202948 8dedad6ca4b33e755020e54ba21b4bcab7b97315
child 202950 ed1973bacb155edebbea3dcc679867d8dfd69569
push id27416
push userryanvm@gmail.com
push dateTue, 02 Sep 2014 17:59:34 +0000
treeherdermozilla-central@bfeddb24df7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersenn
bugs1057137
milestone34.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1057137 - Broken menu: NS_ERROR_ILLEGAL_VALUE: id, attribute, or value too long. r=enn
toolkit/components/xulstore/XULStore.js
toolkit/components/xulstore/tests/xpcshell/test_XULStore.js
--- a/toolkit/components/xulstore/XULStore.js
+++ b/toolkit/components/xulstore/XULStore.js
@@ -196,18 +196,24 @@ XULStore.prototype = {
     this.log("Saving " + attr + "=" + value + " for id=" + id + ", doc=" + docURI);
 
     if (!this._saveAllowed) {
       Services.console.logStringMessage("XULStore: Changes after profile-before-change are ignored!");
       return;
     }
 
     // bug 319846 -- don't save really long attributes or values.
-    if (id.length > 1024 || attr.length > 1024 || value.length > 1024)
-      throw Components.Exception("id, attribute, or value too long", Cr.NS_ERROR_ILLEGAL_VALUE);
+    if (id.length > 512 || attr.length > 512) {
+      throw Components.Exception("id or attribute name too long", Cr.NS_ERROR_ILLEGAL_VALUE);
+    }
+
+    if (value.length > 4096) {
+      Services.console.logStringMessage("XULStore: Warning, truncating long attribute value")
+      value = value.substr(0, 4096);
+    }
 
     let obj = this._data;
     if (!(docURI in obj)) {
       obj[docURI] = {};
     }
     obj = obj[docURI];
     if (!(id in obj)) {
       obj[id] = {};
--- a/toolkit/components/xulstore/tests/xpcshell/test_XULStore.js
+++ b/toolkit/components/xulstore/tests/xpcshell/test_XULStore.js
@@ -92,16 +92,31 @@ add_task(function* testImport(){
 
   yield OS.File.copy(src, dst);
 
   // Importing relies on XULStore not yet being loaded before this point.
   XULStore = Cc["@mozilla.org/xul/xulstore;1"].getService(Ci.nsIXULStore);
   checkOldStore();
 });
 
+add_task(function* testTruncation() {
+  let dos = Array(8192).join("~");
+  // Long id names should trigger an exception
+  Assert.throws(() => XULStore.setValue(browserURI, dos, "foo", "foo"), /NS_ERROR_ILLEGAL_VALUE/);
+
+  // Long attr names should trigger an exception
+  Assert.throws(() => XULStore.setValue(browserURI, "foo", dos, "foo"), /NS_ERROR_ILLEGAL_VALUE/);
+
+  // Long values should be truncated
+  XULStore.setValue(browserURI, "dos", "dos", dos);
+  dos =XULStore.getValue(browserURI, "dos", "dos");
+  do_check_true(dos.length == 4096)
+  XULStore.removeValue(browserURI, "dos", "dos")
+});
+
 add_task(function* testGetValue() {
   // Get non-existing property
   checkValue(browserURI, "side-window", "height", "");
 
   // Get existing property
   checkValue(browserURI, "main-window", "width", "994");
 });