Commit a7e8b8c789ae43976cab5356a586183ae123a14d

Authored by Jay Berkenbilt
1 parent 34311a89

Have qpdf --check parse content streams

Also move writing to null and parsing of content streams out of the
wrong if block.
Showing 2 changed files with 42 additions and 10 deletions
ChangeLog
  1 +2013-01-24 Jay Berkenbilt <ejb@ql.org>
  2 +
  3 + * qpdf --check now does syntactic checks all pages' content
  4 + streams as well as checking overall document structure. Semantic
  5 + errors are still not checked, and there are no plans to add
  6 + semantic checks.
  7 +
  8 + * Bug fix: in versions 4.0.0 and 4.0.1, qpdf --check wasn't doing
  9 + as full of a check for linearized files as for non-linearized
  10 + files.
  11 +
1 2013-01-22 Jay Berkenbilt <ejb@ql.org> 12 2013-01-22 Jay Berkenbilt <ejb@ql.org>
2 13
3 * Add QPDFObjectHandle::getTypeCode(). This method returns a 14 * Add QPDFObjectHandle::getTypeCode(). This method returns a
qpdf/qpdf.cc
@@ -46,6 +46,14 @@ struct QPDFPageData @@ -46,6 +46,14 @@ struct QPDFPageData
46 std::vector<int> selected_pages; 46 std::vector<int> selected_pages;
47 }; 47 };
48 48
  49 +class DiscardContents: public QPDFObjectHandle::ParserCallbacks
  50 +{
  51 + public:
  52 + virtual ~DiscardContents() {}
  53 + virtual void handleObject(QPDFObjectHandle) {}
  54 + virtual void handleEOF() {}
  55 +};
  56 +
49 // Note: let's not be too noisy about documenting the fact that this 57 // Note: let's not be too noisy about documenting the fact that this
50 // software purposely fails to enforce the distinction between user 58 // software purposely fails to enforce the distinction between user
51 // and owner passwords. A user password is sufficient to gain full 59 // and owner passwords. A user password is sufficient to gain full
@@ -1442,16 +1450,29 @@ int main(int argc, char* argv[]) @@ -1442,16 +1450,29 @@ int main(int argc, char* argv[])
1442 else 1450 else
1443 { 1451 {
1444 std::cout << "File is not linearized\n"; 1452 std::cout << "File is not linearized\n";
1445 - // Write the file no nowhere, uncompressing  
1446 - // streams. This causes full file traversal  
1447 - // and decoding of all streams we can decode.  
1448 - QPDFWriter w(pdf);  
1449 - Pl_Discard discard;  
1450 - w.setOutputPipeline(&discard);  
1451 - w.setStreamDataMode(qpdf_s_uncompress);  
1452 - w.write();  
1453 - okay = true;  
1454 - } 1453 + }
  1454 +
  1455 + // Write the file no nowhere, uncompressing
  1456 + // streams. This causes full file traversal
  1457 + // and decoding of all streams we can decode.
  1458 + QPDFWriter w(pdf);
  1459 + Pl_Discard discard;
  1460 + w.setOutputPipeline(&discard);
  1461 + w.setStreamDataMode(qpdf_s_uncompress);
  1462 + w.write();
  1463 +
  1464 + // Parse all content streams
  1465 + std::vector<QPDFObjectHandle> pages = pdf.getAllPages();
  1466 + DiscardContents discard_contents;
  1467 + for (std::vector<QPDFObjectHandle>::iterator iter =
  1468 + pages.begin();
  1469 + iter != pages.end(); ++iter)
  1470 + {
  1471 + QPDFObjectHandle::parseContentStream(
  1472 + (*iter).getKey("/Contents"), &discard_contents);
  1473 + }
  1474 +
  1475 + okay = true;
1455 } 1476 }
1456 catch (std::exception& e) 1477 catch (std::exception& e)
1457 { 1478 {