Bug 454708 - storage-Legacy can throw when calling ConvertToUnicode. r=gavin
authorJustin Dolske <dolske@mozilla.com>
Wed, 24 Sep 2008 09:12:23 -0700
changeset 19641 5ba271f60a300d4b9bcec7a5fcdd276fccfbf71a
parent 19640 156b61daf6475f439cc1171c3e7e8707b09d173e
child 19642 0e49b86be866203e89936260fd34fac25cf2ba01
push idunknown
push userunknown
push dateunknown
reviewersgavin
bugs454708
milestone1.9.1b1pre
Bug 454708 - storage-Legacy can throw when calling ConvertToUnicode. r=gavin
toolkit/components/passwordmgr/src/storage-Legacy.js
toolkit/components/passwordmgr/test/unit/data/signons-454708.txt
toolkit/components/passwordmgr/test/unit/test_storage_legacy_3.js
--- a/toolkit/components/passwordmgr/src/storage-Legacy.js
+++ b/toolkit/components/passwordmgr/src/storage-Legacy.js
@@ -857,17 +857,21 @@ LoginManagerStorage_legacy.prototype = {
                         PASSFIELD : 5, PASSVALUE : 6, ACTIONURL : 7,
                         FILLER : 8 };
         var parseState = STATE.HEADER;
 
         var processEntry = false;
 
         do {
             var hasMore = lineStream.readLine(line);
-            line.value = this._utfConverter.ConvertToUnicode(line.value);
+            try {
+              line.value = this._utfConverter.ConvertToUnicode(line.value);
+            } catch (e) {
+              this.log("Bad UTF8 conversion: " + line.value);
+            }
 
             switch (parseState) {
                 // Check file header
                 case STATE.HEADER:
                     if (line.value == "#2c") {
                         formatVersion = 0x2c;
                     } else if (line.value == "#2d") {
                         formatVersion = 0x2d;
new file mode 100644
--- /dev/null
+++ b/toolkit/components/passwordmgr/test/unit/data/signons-454708.txt
@@ -0,0 +1,10 @@
+#2e
+.
+https://FcK.jp
+put_user_here
+MDoEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECEnlbhAkNBbBBBCexD5eaffSLGH/ORiFlQ4X
+*put_pw_here
+MDoEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECHmiTaseYjkkBBAA0ILJTFSa5CnlpD5PTEYR
+https://FcK.jp
+---
+.
--- a/toolkit/components/passwordmgr/test/unit/test_storage_legacy_3.js
+++ b/toolkit/components/passwordmgr/test/unit/test_storage_legacy_3.js
@@ -581,14 +581,41 @@ storage.setLoginSavingEnabled(utfHost, f
 
 LoginTest.checkStorageData(storage, [utfHost], [utfUser1, utfUser2]);
 
 testdesc = "[flush and reload for verification]"
 storage = LoginTest.reloadStorage(OUTDIR, "output-451155.txt");
 LoginTest.checkStorageData(storage, [utfHost], [utfUser1, utfUser2]);
 
 
+/*
+ * ---------------------- Bug 454708 ----------------------
+ * Check that previous saved entries that are not valid UTF8
+ * are read without blowing up.
+ */
+
+/* ========== 16 ========== */
+testnum++;
+testdesc = "ensure bogus UTF8 strings don't cause failures."
+
+var badHost = "https://FcK" + String.fromCharCode(0x8a) + ".jp";
+var bad8User = Cc["@mozilla.org/login-manager/loginInfo;1"].
+               createInstance(Ci.nsILoginInfo);
+bad8User.init(badHost, badHost, null,
+              "dummydude", "itsasecret", "put_user_here", "put_pw_here");
+
+storage = LoginTest.initStorage(INDIR, "signons-454708.txt",
+                               OUTDIR, "output-454708.txt");
+LoginTest.checkStorageData(storage, [], [bad8User]);
+
+// The output file should contain valid UTF8 now, but the resulting
+// JS string value remains the same.
+
+testdesc = "[flush and reload for verification]"
+storage = LoginTest.reloadStorage(OUTDIR, "output-454708.txt");
+LoginTest.checkStorageData(storage, [], [bad8User]);
+
 /* ========== end ========== */
 } catch (e) {
     throw ("FAILED in test #" + testnum + " -- " + testdesc + ": " + e);
 }
 
 };