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

Sanitize the document info.

This commit is contained in:
Brendan Dahl 2012-08-03 16:11:43 -07:00
parent 22688b4471
commit 29263836c2
3 changed files with 45 additions and 8 deletions

View file

@ -403,6 +403,24 @@ var PDFDocument = (function PDFDocumentClosure() {
return true; /* found */
}
var DOCUMENT_INFO = {
get entries() {
// Lazily build this since all the validation functions below are not
// defined until after this file loads.
return shadow(this, 'entries', {
Title: isString,
Author: isString,
Subject: isString,
Keywords: isString,
Creator: isString,
Producer: isString,
CreationDate: isString,
ModDate: isString,
Trapped: isName
});
}
};
PDFDocument.prototype = {
get linearization() {
var length = this.stream.length;
@ -495,18 +513,27 @@ var PDFDocument = (function PDFDocumentClosure() {
return shadow(this, 'numPages', num);
},
getDocumentInfo: function PDFDocument_getDocumentInfo() {
var info;
var docInfo;
if (this.xref.trailer.has('Info')) {
var infoDict = this.xref.trailer.get('Info');
info = {};
infoDict.forEach(function(key, value) {
info[key] = typeof value !== 'string' ? value :
stringToPDFString(value);
});
docInfo = {};
var validEntries = DOCUMENT_INFO.entries;
// Only fill the document info with valid entries from the spec.
for (var key in validEntries) {
if (infoDict.has(key)) {
var value = infoDict.get(key);
// Make sure the value conforms to the spec.
if (validEntries[key](value)) {
docInfo[key] = typeof value !== 'string' ? value :
stringToPDFString(value);
} else {
info('Bad value in document info for "' + key + '"');
}
}
}
}
return shadow(this, 'getDocumentInfo', info);
return shadow(this, 'getDocumentInfo', docInfo);
},
getFingerprint: function PDFDocument_getFingerprint() {
var xref = this.xref, fileID;