Skip to content

Commit 87a143d

Browse files
Merge pull request #19828 from Snuffleupagus/worker-check-Object-prototype
Check that the `Object.prototype` hasn't been incorrectly extended (PR 11582 follow-up)
2 parents 4b1875c + 91ba147 commit 87a143d

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/core/worker.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,20 +123,19 @@ class WorkerMessageHandler {
123123
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
124124
// Fail early, and predictably, rather than having (some) fonts fail to
125125
// load/render with slightly cryptic error messages in environments where
126-
// the `Array.prototype` has been *incorrectly* extended.
126+
// the `{Object, Array}.prototype` has been *incorrectly* extended.
127127
//
128128
// PLEASE NOTE: We do *not* want to slow down font parsing by adding
129129
// `hasOwnProperty` checks all over the code-base.
130-
const enumerableProperties = [];
131-
for (const property in []) {
132-
enumerableProperties.push(property);
130+
const buildMsg = (type, prop) =>
131+
`The \`${type}.prototype\` contains unexpected enumerable property ` +
132+
`"${prop}", thus breaking e.g. \`for...in\` iteration of ${type}s.`;
133+
134+
for (const prop in {}) {
135+
throw new Error(buildMsg("Object", prop));
133136
}
134-
if (enumerableProperties.length) {
135-
throw new Error(
136-
"The `Array.prototype` contains unexpected enumerable properties: " +
137-
enumerableProperties.join(", ") +
138-
"; thus breaking e.g. `for...in` iteration of `Array`s."
139-
);
137+
for (const prop in []) {
138+
throw new Error(buildMsg("Array", prop));
140139
}
141140
}
142141
const workerHandlerName = docId + "_worker";

0 commit comments

Comments
 (0)