mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15:18:08 +02:00
Merge pull request #14597 from Snuffleupagus/Dict-set-validate-key
Ensure that `Dict.set` only accepts string `key`s
This commit is contained in:
commit
409cbfc817
4 changed files with 20 additions and 7 deletions
|
@ -1187,7 +1187,7 @@ class PDFDocument {
|
|||
} else {
|
||||
info(`Bad value in document info for "${key}".`);
|
||||
}
|
||||
} else if (typeof key === "string") {
|
||||
} else {
|
||||
// For custom values, only accept white-listed types to prevent
|
||||
// errors that would occur when trying to send non-serializable
|
||||
// objects to the main-thread (for example `Dict` or `Stream`).
|
||||
|
|
|
@ -198,11 +198,14 @@ class Dict {
|
|||
|
||||
set(key, value) {
|
||||
if (
|
||||
(typeof PDFJSDev === "undefined" ||
|
||||
PDFJSDev.test("!PRODUCTION || TESTING")) &&
|
||||
value === undefined
|
||||
typeof PDFJSDev === "undefined" ||
|
||||
PDFJSDev.test("!PRODUCTION || TESTING")
|
||||
) {
|
||||
unreachable('Dict.set: The "value" cannot be undefined.');
|
||||
if (typeof key !== "string") {
|
||||
unreachable('Dict.set: The "key" must be a string.');
|
||||
} else if (value === undefined) {
|
||||
unreachable('Dict.set: The "value" cannot be undefined.');
|
||||
}
|
||||
}
|
||||
this._map[key] = value;
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ import {
|
|||
getVerbosityLevel,
|
||||
info,
|
||||
InvalidPDFException,
|
||||
isString,
|
||||
MissingPDFException,
|
||||
PasswordException,
|
||||
setVerbosityLevel,
|
||||
|
@ -639,7 +638,7 @@ class WorkerMessageHandler {
|
|||
const xrefInfo = xref.trailer.get("Info") || null;
|
||||
if (xrefInfo instanceof Dict) {
|
||||
xrefInfo.forEach((key, value) => {
|
||||
if (isString(key) && isString(value)) {
|
||||
if (typeof value === "string") {
|
||||
infoObj[key] = stringToPDFString(value);
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue