mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 450633 - "script stack space quota is exhausted" exception in JSON.jsm when calling SessionStore API for sessions with a large amount of data. r=sayrer, sr=brendan
This commit is contained in:
parent
b7acee2c1f
commit
0b40c8a49f
@ -173,6 +173,22 @@ var JSON = {
|
||||
const maybeHarmful = /[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/;
|
||||
const jsonStrings = /"(\\.|[^"\\\n\r])*"/g;
|
||||
|
||||
const openEndedString = /"(\\.|[^"\\\n\r])*$/;
|
||||
const maxStringLength = 1 << 16;
|
||||
|
||||
// process the string in several slices when it's too big in order
|
||||
// to prevent script stack space quote exhaustion (cf. bug 450633)
|
||||
while (aString.length > maxStringLength) {
|
||||
let slice = aString.substr(0, maxStringLength).replace(jsonStrings, "");
|
||||
aString = aString.substr(maxStringLength);
|
||||
if (openEndedString.test(slice)) {
|
||||
slice = slice.replace(openEndedString, "");
|
||||
aString = '"' + aString;
|
||||
}
|
||||
if (maybeHarmful.test(slice))
|
||||
return false;
|
||||
}
|
||||
|
||||
return !maybeHarmful.test(aString.replace(jsonStrings, ""));
|
||||
}
|
||||
};
|
||||
|
@ -128,4 +128,11 @@ function run_test() {
|
||||
|
||||
do_check_false(JSON.isMostlyHarmless('(function() { alert("P0wn3d!"); })()'));
|
||||
do_check_false(JSON.isMostlyHarmless('{ get a() { return "P0wn3d!"; } }'));
|
||||
|
||||
// this string shouldn't cause a "script stack space quota is exhausted" error
|
||||
let bigString = " ";
|
||||
while (bigString.length < (1 << 22))
|
||||
bigString += bigString;
|
||||
|
||||
do_check_eq(JSON.fromString(toJSONString(bigString)), bigString);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user