diff options
author | Jay Berkenbilt <ejb@ql.org> | 2015-02-22 00:22:32 +0100 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2015-02-22 01:47:11 +0100 |
commit | a11549a566ceed28bc9f6ba100b0d3f6ae59a1f4 (patch) | |
tree | 4868bd8264af045ea8796f3a7cd74ccc5f462bb9 /qpdf | |
parent | 28a9df5119af12d6d97edf4fa97f88ce23865096 (diff) | |
download | qpdf-a11549a566ceed28bc9f6ba100b0d3f6ae59a1f4.tar.zst |
Detect loops in /Pages structure
Pushing inherited objects to pages and getting all pages were both
prone to stack overflow infinite loops if there were loops in the
Pages dictionary. There is a general weakness in the code in that any
part of the code that traverses the Pages structure would be prone to
this and would have to implement its own loop detection. A more robust
fix may provide some general method for handling the Pages structure,
but it's probably not worth doing.
Note: addition of *Internal2 private functions was done rather than
changing signatures of existing methods to avoid breaking
compatibility.
Diffstat (limited to 'qpdf')
-rw-r--r-- | qpdf/qtest/qpdf.test | 6 | ||||
-rw-r--r-- | qpdf/qtest/qpdf/pages-loop.out | 5 | ||||
-rw-r--r-- | qpdf/qtest/qpdf/pages-loop.pdf | 102 |
3 files changed, 112 insertions, 1 deletions
diff --git a/qpdf/qtest/qpdf.test b/qpdf/qtest/qpdf.test index 75726ca4..bd509264 100644 --- a/qpdf/qtest/qpdf.test +++ b/qpdf/qtest/qpdf.test @@ -199,7 +199,7 @@ $td->runtest("remove page we don't have", show_ntests(); # ---------- $td->notify("--- Miscellaneous Tests ---"); -$n_tests += 75; +$n_tests += 76; $td->runtest("qpdf version", {$td->COMMAND => "qpdf --version"}, @@ -566,6 +566,10 @@ $td->runtest("ensure arguments to R are direct", {$td->COMMAND => "qpdf --check indirect-r-arg.pdf"}, {$td->FILE => "indirect-r-arg.out", $td->EXIT_STATUS => 2}, $td->NORMALIZE_NEWLINES); +$td->runtest("detect loops in pages structure", + {$td->COMMAND => "qpdf --check pages-loop.pdf"}, + {$td->FILE => "pages-loop.out", $td->EXIT_STATUS => 2}, + $td->NORMALIZE_NEWLINES); show_ntests(); # ---------- diff --git a/qpdf/qtest/qpdf/pages-loop.out b/qpdf/qtest/qpdf/pages-loop.out new file mode 100644 index 00000000..08643aa4 --- /dev/null +++ b/qpdf/qtest/qpdf/pages-loop.out @@ -0,0 +1,5 @@ +checking pages-loop.pdf +PDF Version: 1.3 +File is not encrypted +File is not linearized +pages-loop.pdf (object 3 0): Loop detected in /Pages structure (getAllPages) diff --git a/qpdf/qtest/qpdf/pages-loop.pdf b/qpdf/qtest/qpdf/pages-loop.pdf new file mode 100644 index 00000000..a41b7502 --- /dev/null +++ b/qpdf/qtest/qpdf/pages-loop.pdf @@ -0,0 +1,102 @@ +%PDF-1.3 +%¿÷¢þ +%QDF-1.0 + +%% Original object ID: 1 0 +1 0 obj +<< + /Pages 2 0 R + /Type /Catalog +>> +endobj + +%% Original object ID: 2 0 +2 0 obj +<< + /Count 1 + /Kids [ + 3 0 R + 2 0 R + ] + /Type /Pages +>> +endobj + +%% Page 1 +%% Original object ID: 3 0 +3 0 obj +<< + /Contents 4 0 R + /MediaBox [ + 0 + 0 + 612 + 792 + ] + /Parent 2 0 R + /Resources << + /Font << + /F1 6 0 R + >> + /ProcSet 7 0 R + >> + /Type /Page +>> +endobj + +%% Contents for page 1 +%% Original object ID: 4 0 +4 0 obj +<< + /Length 5 0 R +>> +stream +BT + /F1 24 Tf + 72 720 Td + (Potato) Tj +ET +endstream +endobj + +5 0 obj +44 +endobj + +%% Original object ID: 6 0 +6 0 obj +<< + /BaseFont /Helvetica + /Encoding /WinAnsiEncoding + /Name /F1 + /Subtype /Type1 + /Type /Font +>> +endobj + +%% Original object ID: 5 0 +7 0 obj +[ + /PDF + /Text +] +endobj + +xref +0 8 +0000000000 65535 f +0000000052 00000 n +0000000133 00000 n +0000000252 00000 n +0000000494 00000 n +0000000593 00000 n +0000000639 00000 n +0000000784 00000 n +trailer << + /Root 1 0 R + /Size 8 + /ID [<395875d4235973eebbade9c7e9e7f857><395875d4235973eebbade9c7e9e7f857>] +>> +startxref +819 +%%EOF |