mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Support corrupt documents with *empty* Name
-entries (issue 13610)
Apparently some really bad PDF software can create documents with *empty* `Name`-entries, which we thus need to somehow deal with. While I don't know if this patch is necessarily the best solution, it should at least ensure that the *empty* `Name`-instance cannot accidentally match a proper `Name`-instance (and it doesn't require changes to a lot of existing code).[1] --- [1] I briefly considered using a `Symbol` rather than an Object, but quickly decided against that since the former one [is not clonable](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm#supported_types) and `Name`-instances may be sent to the API.
This commit is contained in:
parent
6163cd015b
commit
6467907318
5 changed files with 18 additions and 1 deletions
|
@ -1113,6 +1113,9 @@ class Lexer {
|
|||
}
|
||||
if (strBuf.length > 127) {
|
||||
warn(`Name token is longer than allowed by the spec: ${strBuf.length}`);
|
||||
} else if (strBuf.length === 0) {
|
||||
warn("Name token is empty.");
|
||||
return Name.empty;
|
||||
}
|
||||
return Name.get(strBuf.join(""));
|
||||
}
|
||||
|
|
|
@ -33,6 +33,12 @@ const Name = (function NameClosure() {
|
|||
return nameValue ? nameValue : (nameCache[name] = new Name(name));
|
||||
}
|
||||
|
||||
static get empty() {
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
const emptyName = new Name({ empty: true });
|
||||
return shadow(this, "empty", emptyName);
|
||||
}
|
||||
|
||||
static _clearCache() {
|
||||
nameCache = Object.create(null);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue