[JS] Use heap allocation when initializing quickjs sandbox (#13286)
- In case of large string the sandbox initialization failed because of an OOM * so allocate a new string in the heap * and free it after use. - it requires a quickjs update since we need to export some symbols (stringToNewUTF8 and free).
This commit is contained in:
parent
57a1ea840f
commit
762cfd2d1b
43
external/quickjs/quickjs-eval.js
vendored
43
external/quickjs/quickjs-eval.js
vendored
File diff suppressed because one or more lines are too long
@ -71,20 +71,26 @@ class Sandbox {
|
||||
}
|
||||
|
||||
let success = false;
|
||||
let buf = 0;
|
||||
try {
|
||||
const sandboxData = JSON.stringify(data);
|
||||
// "pdfjsScripting.initSandbox..." MUST be the last line to be evaluated
|
||||
// since the returned value is used for the communication.
|
||||
code.push(`pdfjsScripting.initSandbox({ data: ${sandboxData} })`);
|
||||
buf = this._module.stringToNewUTF8(code.join("\n"));
|
||||
|
||||
success = !!this._module.ccall(
|
||||
"init",
|
||||
"number",
|
||||
["string", "number"],
|
||||
[code.join("\n"), this._alertOnError]
|
||||
["number", "number"],
|
||||
[buf, this._alertOnError]
|
||||
);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
} finally {
|
||||
if (buf) {
|
||||
this._module.ccall("free", "number", ["number"], [buf]);
|
||||
}
|
||||
}
|
||||
|
||||
if (success) {
|
||||
|
Loading…
Reference in New Issue
Block a user