File tree 2 files changed +33
-1
lines changed
2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -69,6 +69,11 @@ class PDFParser extends PDFObjectParser {
69
69
70
70
this . maybeRecoverRoot ( ) ;
71
71
72
+ if ( this . context . lookup ( PDFRef . of ( 0 ) ) ) {
73
+ console . warn ( 'Removing parsed object: 0 0 R' ) ;
74
+ this . context . delete ( PDFRef . of ( 0 ) ) ;
75
+ }
76
+
72
77
return this . context ;
73
78
}
74
79
Original file line number Diff line number Diff line change @@ -21,7 +21,8 @@ describe(`PDFParser`, () => {
21
21
console . warn = jest . fn ( ( ...args ) => {
22
22
if (
23
23
! args [ 0 ] . includes ( 'Trying to parse invalid object:' ) &&
24
- ! args [ 0 ] . includes ( 'Invalid object ref:' )
24
+ ! args [ 0 ] . includes ( 'Invalid object ref:' ) &&
25
+ ! args [ 0 ] . includes ( 'Removing parsed object: 0 0 R' )
25
26
) {
26
27
origConsoleWarn ( ...args ) ;
27
28
}
@@ -368,4 +369,30 @@ describe(`PDFParser`, () => {
368
369
const object28 = context . lookup ( PDFRef . of ( 28 ) ) ;
369
370
expect ( object28 ) . toBeInstanceOf ( PDFDict ) ;
370
371
} ) ;
372
+
373
+ it ( `removes indirect objects with objectNumber=0` , async ( ) => {
374
+ const input = `
375
+ %PDF-1.7
376
+ 1 0 obj
377
+ (foo)
378
+ endobj
379
+ 0 0 obj
380
+ (bar)
381
+ endobj
382
+ 2 0 obj
383
+ (baz)
384
+ endobj
385
+ %%EOF
386
+ ` ;
387
+ const parser = PDFParser . forBytesWithOptions ( typedArrayFor ( input ) ) ;
388
+ const context = await parser . parseDocument ( ) ;
389
+
390
+ expect ( context . enumerateIndirectObjects ( ) . length ) . toBe ( 2 ) ;
391
+ const object1 = context . lookup ( PDFRef . of ( 1 ) ) ;
392
+ expect ( object1 ) . toBeInstanceOf ( PDFString ) ;
393
+ const object0 = context . lookup ( PDFRef . of ( 0 ) ) ;
394
+ expect ( object0 ) . toBe ( undefined ) ;
395
+ const object2 = context . lookup ( PDFRef . of ( 2 ) ) ;
396
+ expect ( object2 ) . toBeInstanceOf ( PDFString ) ;
397
+ } ) ;
371
398
} ) ;
You can’t perform that action at this time.
0 commit comments