intl/uconv/tests/unit/test_bug381412.js

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

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.

michael@0 1 const charset = "Shift_JIS";
michael@0 2
michael@0 3 function error(inString, outString, msg){
michael@0 4 var dispIn = "";
michael@0 5 var dispOut = "";
michael@0 6 var i;
michael@0 7 for (i = 0; i < inString.length; ++i) {
michael@0 8 dispIn += " x" + inString.charCodeAt(i).toString(16);
michael@0 9 }
michael@0 10 if (outString.length == 0) {
michael@0 11 dispOut = "<empty>";
michael@0 12 } else {
michael@0 13 for (i = 0; i < outString.length; ++i) {
michael@0 14 dispOut += " x" + outString.charCodeAt(i).toString(16);
michael@0 15 }
michael@0 16 }
michael@0 17 dump("\"" + dispIn + "\" ==> \"" + dispOut + "\"\n");
michael@0 18 do_throw("security risk: " + msg);
michael@0 19 }
michael@0 20
michael@0 21 function run_test() {
michael@0 22 var ScriptableUnicodeConverter =
michael@0 23 Components.Constructor("@mozilla.org/intl/scriptableunicodeconverter",
michael@0 24 "nsIScriptableUnicodeConverter");
michael@0 25
michael@0 26 var converter = new ScriptableUnicodeConverter();
michael@0 27 converter.charset = charset;
michael@0 28
michael@0 29 var leadByte, trailByte;
michael@0 30 var inString;
michael@0 31 for (leadByte = 1; leadByte < 0x100; ++leadByte) {
michael@0 32 for (trailByte = 1; trailByte < 0x100; ++trailByte) {
michael@0 33 inString = String.fromCharCode(leadByte, trailByte, 65);
michael@0 34 var outString = converter.ConvertToUnicode(inString) + converter.Finish();
michael@0 35 switch (outString.length) {
michael@0 36 case 1:
michael@0 37 error(inString, outString, "2 byte sequence eaten");
michael@0 38 break;
michael@0 39 case 2:
michael@0 40 if (outString.charCodeAt(0) < 0x80 &&
michael@0 41 outString.charCodeAt(1) < 0x80) {
michael@0 42 error(inString, outString, "2 byte sequence converted to 1 ASCII");
michael@0 43 }
michael@0 44 break;
michael@0 45 case 3:
michael@0 46 if (outString != inString &&
michael@0 47 outString.charCodeAt(0) < 0x80 &&
michael@0 48 outString.charCodeAt(1) < 0x80) {
michael@0 49 error(inString, outString,
michael@0 50 "2 byte sequence converted to 2 ASCII");
michael@0 51 }
michael@0 52 break;
michael@0 53 }
michael@0 54 }
michael@0 55 }
michael@0 56 }

mercurial