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 // 2-byte charsets:
2 const charsets = [ "Big5", "EUC-KR", "x-euc-tw", "x-johab" ]
3 const ScriptableUnicodeConverter =
4 Components.Constructor("@mozilla.org/intl/scriptableunicodeconverter",
5 "nsIScriptableUnicodeConverter");
6 var gConverter;
8 function error(inString, outString, msg) {
9 var dispIn = "";
10 var dispOut = "";
11 var i;
12 for (i = 0; i < inString.length; ++i) {
13 dispIn += " x" + inString.charCodeAt(i).toString(16);
14 }
15 if (outString.length == 0) {
16 dispOut = "<empty>";
17 } else {
18 for (i = 0; i < outString.length; ++i) {
19 dispOut += " x" + outString.charCodeAt(i).toString(16);
20 }
21 }
22 dump("\"" + dispIn + "\" ==> \"" + dispOut + "\"\n");
23 do_throw("security risk: " + msg);
24 }
26 function IsASCII(charCode) {
27 return (charCode <= 0x7e);
28 }
30 function test(inString) {
31 var outString = gConverter.ConvertToUnicode(inString) +
32 gConverter.Finish();
34 var outLen = outString.length;
36 if (IsASCII(inString.charCodeAt(1)) &&
37 (outLen < 4 || outString.charCodeAt(outLen - 4) == 0xFFFD)) {
38 error(inString, outString, "ASCII input eaten in " + gConverter.charset);
39 }
40 }
42 function run_test() {
43 gConverter = new ScriptableUnicodeConverter();
44 for (var i = 0; i < charsets.length; ++i) {
45 gConverter.charset = charsets[i];
47 var byte1, byte2;
48 for (byte1 = 1; byte1 < 0x100; ++byte1) {
49 for (byte2 = 1; byte2 < 0x100; ++byte2) {
50 test(String.fromCharCode(byte1, byte2) + "foo");
51 }
52 }
53 }
54 }