@patrickdk77/pdf-defuse 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/document.d.ts +2 -2
- package/dist/document.js +12 -12
- package/package.json +1 -1
package/dist/document.d.ts
CHANGED
|
@@ -190,7 +190,7 @@ export declare class PdfDocument {
|
|
|
190
190
|
/** A node typed /Page, or any node without /Kids, is a page to pdf.js. */
|
|
191
191
|
private isPageNode;
|
|
192
192
|
/** Reads a value one level deep, as pdf.js reads one on its way to a page. Throws BrokenEntry where pdf.js would. */
|
|
193
|
-
private
|
|
193
|
+
private readEntry;
|
|
194
194
|
/**
|
|
195
195
|
* Whether an entry points at another object or at nothing that reads as an object header. pdf.js refuses such an
|
|
196
196
|
* entry, and an entry whose generation differs from the reference, before it reads the object. A missing entry
|
|
@@ -241,7 +241,7 @@ export declare class PdfDocument {
|
|
|
241
241
|
*/
|
|
242
242
|
private pickTrailer;
|
|
243
243
|
/** Reads a value one level deep, throwing BrokenEntry where pdf.js's lookup throws. */
|
|
244
|
-
private
|
|
244
|
+
private readEntryStrict;
|
|
245
245
|
/** With no trailer at all, pdf.js takes the lowest-numbered object, or stream dictionary, that holds /Root. */
|
|
246
246
|
private rootHolder;
|
|
247
247
|
/**
|
package/dist/document.js
CHANGED
|
@@ -493,7 +493,7 @@ class PdfDocument {
|
|
|
493
493
|
this.checkedEntries = new Map();
|
|
494
494
|
try {
|
|
495
495
|
await this.findPage(top, pages, 0, counts);
|
|
496
|
-
const count = await this.
|
|
496
|
+
const count = await this.readEntry(pages.get('Count'));
|
|
497
497
|
if (typeof count === 'number' && Number.isInteger(count) && (count <= 1 || (await this.findPage(top, pages, count - 1, counts))))
|
|
498
498
|
return false;
|
|
499
499
|
await this.readAllPages(top, pages);
|
|
@@ -535,7 +535,7 @@ class PdfDocument {
|
|
|
535
535
|
if (seen.has(k))
|
|
536
536
|
return false;
|
|
537
537
|
seen.add(k);
|
|
538
|
-
const obj = await this.
|
|
538
|
+
const obj = await this.readEntry(node);
|
|
539
539
|
if (obj instanceof objects_1.PdfDict && (await this.isPageNode(obj))) {
|
|
540
540
|
if (!counts.has(k))
|
|
541
541
|
counts.set(k, 1);
|
|
@@ -548,7 +548,7 @@ class PdfDocument {
|
|
|
548
548
|
}
|
|
549
549
|
if (!(node instanceof objects_1.PdfDict))
|
|
550
550
|
return false;
|
|
551
|
-
const count = await this.
|
|
551
|
+
const count = await this.readEntry(node.get('Count'));
|
|
552
552
|
if (typeof count === 'number' && Number.isInteger(count) && count >= 0) {
|
|
553
553
|
if (id !== undefined && !counts.has(id))
|
|
554
554
|
counts.set(id, count);
|
|
@@ -557,7 +557,7 @@ class PdfDocument {
|
|
|
557
557
|
continue;
|
|
558
558
|
}
|
|
559
559
|
}
|
|
560
|
-
const kids = await this.
|
|
560
|
+
const kids = await this.readEntry(node.get('Kids'));
|
|
561
561
|
if (Array.isArray(kids)) {
|
|
562
562
|
steps += kids.length;
|
|
563
563
|
for (let i = kids.length - 1; i >= 0; i--)
|
|
@@ -581,7 +581,7 @@ class PdfDocument {
|
|
|
581
581
|
const item = queue.at(-1);
|
|
582
582
|
if (item === undefined)
|
|
583
583
|
return;
|
|
584
|
-
const kids = await this.
|
|
584
|
+
const kids = await this.readEntry(item.node.get('Kids'));
|
|
585
585
|
if (!Array.isArray(kids)) {
|
|
586
586
|
await this.isPageNode(item.node);
|
|
587
587
|
return;
|
|
@@ -595,7 +595,7 @@ class PdfDocument {
|
|
|
595
595
|
if (seen.has(refKey(kid)))
|
|
596
596
|
return;
|
|
597
597
|
seen.add(refKey(kid));
|
|
598
|
-
kid = await this.
|
|
598
|
+
kid = await this.readEntry(kid);
|
|
599
599
|
}
|
|
600
600
|
if (!(kid instanceof objects_1.PdfDict))
|
|
601
601
|
return;
|
|
@@ -605,11 +605,11 @@ class PdfDocument {
|
|
|
605
605
|
}
|
|
606
606
|
/** A node typed /Page, or any node without /Kids, is a page to pdf.js. */
|
|
607
607
|
async isPageNode(d) {
|
|
608
|
-
const type = await this.
|
|
608
|
+
const type = await this.readEntry(d.get('Type'));
|
|
609
609
|
return (type instanceof objects_1.PdfName && type.name === 'Page') || !d.has('Kids');
|
|
610
610
|
}
|
|
611
611
|
/** Reads a value one level deep, as pdf.js reads one on its way to a page. Throws BrokenEntry where pdf.js would. */
|
|
612
|
-
async
|
|
612
|
+
async readEntry(v) {
|
|
613
613
|
if (!(v instanceof objects_1.PdfRef))
|
|
614
614
|
return v;
|
|
615
615
|
let broken = this.checkedEntries?.get(refKey(v));
|
|
@@ -1322,13 +1322,13 @@ class PdfDocument {
|
|
|
1322
1322
|
for (const d of dicts) {
|
|
1323
1323
|
let valid;
|
|
1324
1324
|
try {
|
|
1325
|
-
const root = await this.
|
|
1325
|
+
const root = await this.readEntryStrict(d.get('Root'), fallback);
|
|
1326
1326
|
if (!(root instanceof objects_1.PdfDict))
|
|
1327
1327
|
continue;
|
|
1328
|
-
const pages = await this.
|
|
1328
|
+
const pages = await this.readEntryStrict(root.get('Pages'), fallback);
|
|
1329
1329
|
if (!(pages instanceof objects_1.PdfDict))
|
|
1330
1330
|
continue;
|
|
1331
|
-
valid = Number.isInteger(await this.
|
|
1331
|
+
valid = Number.isInteger(await this.readEntryStrict(pages.get('Count'), fallback));
|
|
1332
1332
|
}
|
|
1333
1333
|
catch (e) {
|
|
1334
1334
|
if (!(e instanceof BrokenEntry))
|
|
@@ -1345,7 +1345,7 @@ class PdfDocument {
|
|
|
1345
1345
|
});
|
|
1346
1346
|
}
|
|
1347
1347
|
/** Reads a value one level deep, throwing BrokenEntry where pdf.js's lookup throws. */
|
|
1348
|
-
async
|
|
1348
|
+
async readEntryStrict(v, fallback) {
|
|
1349
1349
|
if (!(v instanceof objects_1.PdfRef))
|
|
1350
1350
|
return v;
|
|
1351
1351
|
const entry = unpack(this.xref.get(v.num));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@patrickdk77/pdf-defuse",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Sanitize and clean PDF files. Detects and removes JavaScript, attached files, launch actions, unsafe links and empty-password encryption, scores the risk, and writes a disarmed copy with bounded memory and no runtime dependencies.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "patrickdk77",
|