Commit 9abd73ff795483d4367ad8c4d079f00386c8dea1

Authored by m-holger
1 parent fe4853fe

Improve `QPDFParser` handling of invalid indirect references by enhancing associated warnings

libqpdf/QPDFParser.cc
... ... @@ -320,7 +320,9 @@ QPDFParser::parseRemainder(bool content_stream)
320 320 if (!(id < 1 || gen < 0 || gen >= 65535)) {
321 321 add(ParseGuard::getObject(context, id, gen, parse_pdf));
322 322 } else {
323   - addNull();
  323 + add_bad_null(
  324 + "treating bad indirect reference (" + std::to_string(id) + " " +
  325 + std::to_string(gen) + " R) as null");
324 326 }
325 327 int_count = 0;
326 328 continue;
... ...
qpdf/qtest/qpdf/issue-101.out
... ... @@ -30,6 +30,8 @@ WARNING: issue-101.pdf (trailer, offset 1508): stream keyword found in trailer
30 30 WARNING: issue-101.pdf (trailer, offset 1438): recovered trailer has no /Root entry
31 31 WARNING: issue-101.pdf (object 2 0, offset 244): unknown token while reading object; treating as null
32 32 WARNING: issue-101.pdf (object 2 0, offset 29): dictionary has duplicated key /Parent; last occurrence overrides earlier ones
  33 +WARNING: issue-101.pdf (object 2 0, offset 333): treating bad indirect reference (0 0 R) as null
  34 +WARNING: issue-101.pdf (object 5 0, offset 1247): treating bad indirect reference (0 0 R) as null
33 35 WARNING: issue-101.pdf (object 5 0, offset 1242): dictionary ended prematurely; using null as value for last key
34 36 WARNING: issue-101.pdf (object 5 0, offset 1242): expected dictionary keys but found non-name objects; ignoring
35 37 WARNING: issue-101.pdf (object 7 0, offset 3855): unknown token while reading object; treating as null
... ...
qpdf/qtest/qpdf/issue-118.out
1 1 WARNING: issue-118.pdf: can't find PDF header
  2 +WARNING: issue-118.pdf (xref stream: object 8 0, offset 720): treating bad indirect reference (0 0 R) as null
2 3 WARNING: issue-118.pdf (xref stream, offset 732): self-referential object stream 2
3 4 WARNING: issue-118.pdf (xref stream, offset 732): object stream id 12336 for object 3 is impossibly large
4 5 WARNING: issue-118.pdf (xref stream, offset 732): object stream id 12336 for object 4 is impossibly large
... ...
qpdf/qtest/qpdf/issue-335a.out
... ... @@ -39,12 +39,14 @@ WARNING: issue-335a.pdf (trailer, offset 22844): expected dictionary keys but fo
39 39 WARNING: issue-335a.pdf (trailer, offset 22880): stream keyword found in trailer
40 40 WARNING: issue-335a.pdf (trailer, offset 22840): recovered trailer has no /Root entry
41 41 WARNING: issue-335a.pdf (trailer, offset 22702): unknown token while reading object; treating as null
  42 +WARNING: issue-335a.pdf (trailer, offset 22713): treating bad indirect reference (0 0 R) as null
42 43 WARNING: issue-335a.pdf (trailer, offset 22701): expected dictionary keys but found non-name objects; ignoring
43 44 WARNING: issue-335a.pdf (trailer, offset 22746): stream keyword found in trailer
44 45 WARNING: issue-335a.pdf (trailer, offset 22697): recovered trailer has no /Root entry
45 46 WARNING: issue-335a.pdf (trailer, offset 22687): unknown token while reading object; treating as null
46 47 WARNING: issue-335a.pdf (trailer, offset 22690): unknown token while reading object; treating as null
47 48 WARNING: issue-335a.pdf (trailer, offset 22702): unknown token while reading object; treating as null
  49 +WARNING: issue-335a.pdf (trailer, offset 22713): treating bad indirect reference (0 0 R) as null
48 50 WARNING: issue-335a.pdf (trailer, offset 22701): expected dictionary keys but found non-name objects; ignoring
49 51 WARNING: issue-335a.pdf (trailer, offset 22740): unknown token while reading object; treating as null
50 52 WARNING: issue-335a.pdf (trailer, offset 22748): unknown token while reading object; treating as null
... ... @@ -58,6 +60,7 @@ WARNING: issue-335a.pdf (trailer, offset 22675): unknown token while reading obj
58 60 WARNING: issue-335a.pdf (trailer, offset 22687): unknown token while reading object; treating as null
59 61 WARNING: issue-335a.pdf (trailer, offset 22690): unknown token while reading object; treating as null
60 62 WARNING: issue-335a.pdf (trailer, offset 22702): unknown token while reading object; treating as null
  63 +WARNING: issue-335a.pdf (trailer, offset 22713): treating bad indirect reference (0 0 R) as null
61 64 WARNING: issue-335a.pdf (trailer, offset 22701): expected dictionary keys but found non-name objects; ignoring
62 65 WARNING: issue-335a.pdf (trailer, offset 22740): unknown token while reading object; treating as null
63 66 WARNING: issue-335a.pdf (trailer, offset 22748): unknown token while reading object; treating as null
... ... @@ -66,6 +69,8 @@ WARNING: issue-335a.pdf (trailer, offset 22791): unknown token while reading obj
66 69 WARNING: issue-335a.pdf (trailer, offset 22794): unexpected >
67 70 WARNING: issue-335a.pdf (trailer, offset 22794): too many errors; giving up on reading object
68 71 WARNING: issue-335a.pdf (trailer, offset 22437): unknown token while reading object; treating as null
  72 +WARNING: issue-335a.pdf (trailer, offset 22448): treating bad indirect reference (0 0 R) as null
  73 +WARNING: issue-335a.pdf (trailer, offset 22471): treating bad indirect reference (20 -1 R) as null
69 74 WARNING: issue-335a.pdf (trailer, offset 22436): expected dictionary keys but found non-name objects; ignoring
70 75 WARNING: issue-335a.pdf (trailer, offset 22482): stream keyword found in trailer
71 76 WARNING: issue-335a.pdf (trailer, offset 22432): recovered trailer has no /Root entry
... ... @@ -98,27 +103,30 @@ WARNING: issue-335a.pdf (trailer, offset 22134): stream keyword found in trailer
98 103 WARNING: issue-335a.pdf (trailer, offset 22083): recovered trailer has no /Root entry
99 104 WARNING: issue-335a.pdf (trailer, offset 22000): invalid character (t) in hexstring
100 105 WARNING: issue-335a.pdf (trailer, offset 21937): unknown token while reading object; treating as null
  106 +WARNING: issue-335a.pdf (trailer, offset 21948): treating bad indirect reference (0 0 R) as null
101 107 WARNING: issue-335a.pdf (trailer, offset 21962): unknown token while reading object; treating as null
102 108 WARNING: issue-335a.pdf (trailer, offset 21991): unknown token while reading object; treating as null
103 109 WARNING: issue-335a.pdf (trailer, offset 22000): invalid character (t) in hexstring
104 110 WARNING: issue-335a.pdf (trailer, offset 22003): unknown token while reading object; treating as null
  111 +WARNING: issue-335a.pdf (trailer, offset 22026): treating bad indirect reference (-4 0 R) as null
105 112 WARNING: issue-335a.pdf (trailer, offset 21936): dictionary has duplicated key /Length; last occurrence overrides earlier ones
106 113 WARNING: issue-335a.pdf (trailer, offset 22028): unexpected >
107 114 WARNING: issue-335a.pdf (trailer, offset 22030): unknown token while reading object; treating as null
108   -WARNING: issue-335a.pdf (trailer, offset 22038): unknown token while reading object; treating as null
109   -WARNING: issue-335a.pdf (trailer, offset 22038): too many errors; giving up on reading object
  115 +WARNING: issue-335a.pdf (trailer, offset 22030): too many errors; giving up on reading object
110 116 WARNING: issue-335a.pdf (trailer, offset 21918): unknown token while reading object; treating as null
111 117 WARNING: issue-335a.pdf (trailer, offset 21925): unknown token while reading object; treating as null
112 118 WARNING: issue-335a.pdf (trailer, offset 21937): unknown token while reading object; treating as null
  119 +WARNING: issue-335a.pdf (trailer, offset 21948): treating bad indirect reference (0 0 R) as null
113 120 WARNING: issue-335a.pdf (trailer, offset 21962): unknown token while reading object; treating as null
114 121 WARNING: issue-335a.pdf (trailer, offset 21991): unknown token while reading object; treating as null
115 122 WARNING: issue-335a.pdf (trailer, offset 22000): invalid character (t) in hexstring
116 123 WARNING: issue-335a.pdf (trailer, offset 22003): unknown token while reading object; treating as null
  124 +WARNING: issue-335a.pdf (trailer, offset 22026): treating bad indirect reference (-4 0 R) as null
117 125 WARNING: issue-335a.pdf (trailer, offset 21936): dictionary has duplicated key /Length; last occurrence overrides earlier ones
118 126 WARNING: issue-335a.pdf (trailer, offset 22028): unexpected >
119   -WARNING: issue-335a.pdf (trailer, offset 22030): unknown token while reading object; treating as null
120   -WARNING: issue-335a.pdf (trailer, offset 22030): too many errors; giving up on reading object
  127 +WARNING: issue-335a.pdf (trailer, offset 22028): too many errors; giving up on reading object
121 128 WARNING: issue-335a.pdf (trailer, offset 21837): unknown token while reading object; treating as null
  129 +WARNING: issue-335a.pdf (trailer, offset 21861): treating bad indirect reference (0 0 R) as null
122 130 WARNING: issue-335a.pdf (trailer, offset 21850): expected dictionary keys but found non-name objects; ignoring
123 131 WARNING: issue-335a.pdf (trailer, offset 21892): unknown token while reading object; treating as null
124 132 WARNING: issue-335a.pdf (trailer, offset 21900): unknown token while reading object; treating as null
... ...
qpdf/qtest/qpdf/issue-51.out
1 1 WARNING: issue-51.pdf: can't find PDF header
2 2 WARNING: issue-51.pdf: reported number of objects (0) is not one plus the highest object number (8)
  3 +WARNING: issue-51.pdf (object 7 0, offset 500): treating bad indirect reference (0 0 R) as null
3 4 WARNING: issue-51.pdf (object 7 0, offset 476): dictionary has duplicated key /0000; last occurrence overrides earlier ones
4 5 WARNING: issue-51.pdf (object 7 0, offset 553): expected endobj
5 6 issue-51.pdf: unable to find page tree
... ...
qpdf/qtest/qpdf/issue-99.out
1 1 WARNING: issue-99.pdf: file is damaged
2 2 WARNING: issue-99.pdf (offset 3526): xref not found
3 3 WARNING: issue-99.pdf: Attempting to reconstruct cross-reference table
  4 +WARNING: issue-99.pdf (trailer, offset 4635): treating bad indirect reference (0 0 R) as null
4 5 WARNING: issue-99.pdf (trailer, offset 4613): recovered trailer has no /Root entry
5 6 WARNING: issue-99.pdf (object 1 0, offset 775): unknown token while reading object; treating as null
6 7 WARNING: issue-99.pdf (object 1 0, offset 795): unknown token while reading object; treating as null
... ... @@ -11,6 +12,7 @@ WARNING: issue-99.pdf (object 1 0, offset 855): too many errors; giving up on re
11 12 WARNING: issue-99.pdf (object 2 0, offset 64): expected endobj
12 13 WARNING: issue-99.pdf (object 5 0, offset 2452): unknown token while reading object; treating as string
13 14 WARNING: issue-99.pdf (object 6 0, offset 2506): unexpected array close token; giving up on reading object
  15 +WARNING: issue-99.pdf (object 8 0, offset 4281): treating bad indirect reference (0 0 R) as null
14 16 WARNING: issue-99.pdf (object 10 0, offset 3708): expected dictionary keys but found non-name objects; ignoring
15 17 WARNING: issue-99.pdf (object 11 0, offset 4485): unknown token while reading object; treating as null
16 18 WARNING: issue-99.pdf (object 11 0, offset 4497): unexpected array close token; giving up on reading object
... ...
qpdf/qtest/qpdf/parse-object.out
... ... @@ -6,4 +6,9 @@ WARNING: parsed object: treating unexpected brace token as null
6 6 WARNING: parsed object: treating unexpected brace token as null
7 7 WARNING: parsed object: unexpected dictionary close token
8 8 WARNING: bad-parse.qdf (object 7 0, offset 1121): unexpected EOF
  9 +WARNING: parsed object (offset 5): treating bad indirect reference (0 0 R) as null
  10 +WARNING: parsed object (offset 12): treating bad indirect reference (-1 0 R) as null
  11 +WARNING: parsed object (offset 22): treating bad indirect reference (1 65535 R) as null
  12 +WARNING: parsed object (offset 33): treating bad indirect reference (1 100000 R) as null
  13 +WARNING: parsed object (offset 40): treating bad indirect reference (1 -1 R) as null
9 14 test 31 done
... ...