Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
1 const charset = "GB2312";
3 function error(inString, outString, msg){
4 var dispIn = "";
5 var dispOut = "";
6 var i;
7 for (i = 0; i < inString.length; ++i) {
8 dispIn += " x" + inString.charCodeAt(i).toString(16);
9 }
10 if (outString.length == 0) {
11 dispOut = "<empty>";
12 } else {
13 for (i = 0; i < outString.length; ++i) {
14 dispOut += " x" + outString.charCodeAt(i).toString(16);
15 }
16 }
17 dump("\"" + dispIn + "\" ==> \"" + dispOut + "\"\n");
18 do_throw("security risk: " + msg);
19 }
21 function run_test() {
22 var ScriptableUnicodeConverter =
23 Components.Constructor("@mozilla.org/intl/scriptableunicodeconverter",
24 "nsIScriptableUnicodeConverter");
26 var converter = new ScriptableUnicodeConverter();
27 converter.charset = charset;
29 var leadByte, trailByte;
30 var inString;
31 for (leadByte = 1; leadByte < 0x100; ++leadByte) {
32 for (trailByte = 1; trailByte < 0x100; ++trailByte) {
33 inString = String.fromCharCode(leadByte, trailByte, 65);
34 var outString = converter.ConvertToUnicode(inString) + converter.Finish();
35 switch (outString.length) {
36 case 1:
37 error(inString, outString, "2 byte sequence eaten");
38 break;
39 case 2:
40 if (outString.charCodeAt(0) < 0x80 &&
41 outString.charCodeAt(1) < 0x80) {
42 error(inString, outString, "2 byte sequence converted to 1 ASCII");
43 }
44 break;
45 case 3:
46 if (outString != inString &&
47 outString.charCodeAt(0) < 0x80 &&
48 outString.charCodeAt(1) < 0x80) {
49 error(inString, outString,
50 "2 byte sequence converted to 2 ASCII");
51 }
52 break;
53 }
54 }
55 }
56 }