1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 01:58:06 +02:00

Ensure that the PDF header contains an actual number (PR 11463 follow-up)

While it would be nice to change the `PDFFormatVersion` property, as returned through `PDFDocumentProxy.getMetadata`, to a number (rather than a string) that would unfortunately be a breaking API change.
However, it does seem like a good idea to at least *validate* the PDF header version on the worker-thread, rather than potentially returning an arbitrary string.
This commit is contained in:
Jonas Jenwald 2020-02-05 13:59:47 +01:00
parent a5fec297c0
commit 88c35d872f
4 changed files with 101 additions and 1 deletions

View file

@ -429,6 +429,8 @@ const FINGERPRINT_FIRST_BYTES = 1024;
const EMPTY_FINGERPRINT =
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
const PDF_HEADER_VERSION_REGEXP = /^[1-9]\.[0-9]$/;
function find(stream, signature, limit = 1024, backwards = false) {
if (
typeof PDFJSDev === "undefined" ||
@ -668,8 +670,17 @@ class PDFDocument {
Trapped: isName,
};
let version = this.pdfFormatVersion;
if (
typeof version !== "string" ||
!PDF_HEADER_VERSION_REGEXP.test(version)
) {
warn(`Invalid PDF header version number: ${version}`);
version = null;
}
const docInfo = {
PDFFormatVersion: this.pdfFormatVersion,
PDFFormatVersion: version,
IsLinearized: !!this.linearization,
IsAcroFormPresent: !!this.acroForm,
IsXFAPresent: !!this.xfa,