diff --git a/toolkit/components/xulstore/XULStore.js b/toolkit/components/xulstore/XULStore.js index dcf425d359b..52329000059 100644 --- a/toolkit/components/xulstore/XULStore.js +++ b/toolkit/components/xulstore/XULStore.js @@ -201,8 +201,14 @@ XULStore.prototype = { } // 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)) { diff --git a/toolkit/components/xulstore/tests/xpcshell/test_XULStore.js b/toolkit/components/xulstore/tests/xpcshell/test_XULStore.js index a8c093b54c6..ad511396d45 100644 --- a/toolkit/components/xulstore/tests/xpcshell/test_XULStore.js +++ b/toolkit/components/xulstore/tests/xpcshell/test_XULStore.js @@ -97,6 +97,21 @@ add_task(function* testImport(){ 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", "");