1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 22:58:07 +02:00

Merge pull request #19828 from Snuffleupagus/worker-check-Object-prototype

Check that the `Object.prototype` hasn't been incorrectly extended (PR 11582 follow-up)
This commit is contained in:
Jonas Jenwald 2025-04-18 13:59:07 +02:00 committed by GitHub
commit 87a143dbbc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -123,20 +123,19 @@ class WorkerMessageHandler {
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
// Fail early, and predictably, rather than having (some) fonts fail to
// load/render with slightly cryptic error messages in environments where
// the `Array.prototype` has been *incorrectly* extended.
// the `{Object, Array}.prototype` has been *incorrectly* extended.
//
// PLEASE NOTE: We do *not* want to slow down font parsing by adding
// `hasOwnProperty` checks all over the code-base.
const enumerableProperties = [];
for (const property in []) {
enumerableProperties.push(property);
const buildMsg = (type, prop) =>
`The \`${type}.prototype\` contains unexpected enumerable property ` +
`"${prop}", thus breaking e.g. \`for...in\` iteration of ${type}s.`;
for (const prop in {}) {
throw new Error(buildMsg("Object", prop));
}
if (enumerableProperties.length) {
throw new Error(
"The `Array.prototype` contains unexpected enumerable properties: " +
enumerableProperties.join(", ") +
"; thus breaking e.g. `for...in` iteration of `Array`s."
);
for (const prop in []) {
throw new Error(buildMsg("Array", prop));
}
}
const workerHandlerName = docId + "_worker";