Merge pull request #5124 from jordan-thoms/improve-fingerprinting
Improve fingerprinting of documents
This commit is contained in:
commit
ee1b1252ff
@ -280,6 +280,10 @@ var Page = (function PageClosure() {
|
|||||||
* `PDFDocument` objects on the main thread created.
|
* `PDFDocument` objects on the main thread created.
|
||||||
*/
|
*/
|
||||||
var PDFDocument = (function PDFDocumentClosure() {
|
var PDFDocument = (function PDFDocumentClosure() {
|
||||||
|
var FINGERPRINT_FIRST_BYTES = 1024;
|
||||||
|
|
||||||
|
var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' +
|
||||||
|
'\x00\x00\x00\x00\x00\x00\x00\x00\x00';
|
||||||
function PDFDocument(pdfManager, arg, password) {
|
function PDFDocument(pdfManager, arg, password) {
|
||||||
if (isStream(arg)) {
|
if (isStream(arg)) {
|
||||||
init.call(this, pdfManager, arg, password);
|
init.call(this, pdfManager, arg, password);
|
||||||
@ -493,14 +497,21 @@ var PDFDocument = (function PDFDocumentClosure() {
|
|||||||
get fingerprint() {
|
get fingerprint() {
|
||||||
var xref = this.xref, hash, fileID = '';
|
var xref = this.xref, hash, fileID = '';
|
||||||
|
|
||||||
if (xref.trailer.has('ID')) {
|
if (xref.trailer.has('ID') &&
|
||||||
|
xref.trailer.get('ID')[0] !== EMPTY_FINGERPRINT) {
|
||||||
hash = stringToBytes(xref.trailer.get('ID')[0]);
|
hash = stringToBytes(xref.trailer.get('ID')[0]);
|
||||||
} else {
|
} else {
|
||||||
hash = calculateMD5(this.stream.bytes.subarray(0, 100), 0, 100);
|
if (this.stream.ensureRange) {
|
||||||
|
this.stream.ensureRange(0,
|
||||||
|
Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
|
||||||
|
}
|
||||||
|
hash = calculateMD5(this.stream.bytes.subarray(0,
|
||||||
|
FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 0, n = hash.length; i < n; i++) {
|
for (var i = 0, n = hash.length; i < n; i++) {
|
||||||
fileID += hash[i].toString(16);
|
var hex = hash[i].toString(16);
|
||||||
|
fileID += hex.length === 1 ? '0' + hex : hex;
|
||||||
}
|
}
|
||||||
|
|
||||||
return shadow(this, 'fingerprint', fileID);
|
return shadow(this, 'fingerprint', fileID);
|
||||||
|
Loading…
Reference in New Issue
Block a user