Commit ce8e63cb9ad3ec4ef3709be67c32c866e6b8e769
1 parent
234e3237
Add test case for broken indirect object reference
...where the first "number" is an indirect object that happens to be a number.
Showing
3 changed files
with
10 additions
and
3 deletions
qpdf/qtest/parsing.test
| ... | ... | @@ -17,7 +17,7 @@ my $td = new TestDriver('parsing'); |
| 17 | 17 | my $n_tests = 17; |
| 18 | 18 | |
| 19 | 19 | $td->runtest("parse objects from string", |
| 20 | - {$td->COMMAND => "test_driver 31 minimal.pdf"}, # file not used | |
| 20 | + {$td->COMMAND => "test_driver 31 good1.qdf"}, | |
| 21 | 21 | {$td->FILE => "parse-object.out", $td->EXIT_STATUS => 0}, |
| 22 | 22 | $td->NORMALIZE_NEWLINES); |
| 23 | 23 | $td->runtest("EOF terminating literal tokens", | ... | ... |
qpdf/qtest/qpdf/parse-object.out
| 1 | 1 | [ /name 16059 3.14159 false << /key true /other [ (string1) (string2) ] >> null ] |
| 2 | 2 | logic error parsing indirect: QPDFObjectHandle::parse called without context on an object with indirect references |
| 3 | 3 | trailing data: parsed object (trailing test): trailing data found parsing object from string |
| 4 | +broken indirect object reference: parsed object: trailing data found parsing object from string | |
| 4 | 5 | test 31 done | ... | ... |
qpdf/test_driver.cc
| ... | ... | @@ -1228,8 +1228,6 @@ test_30(QPDF& pdf, char const* arg2) |
| 1228 | 1228 | static void |
| 1229 | 1229 | test_31(QPDF& pdf, char const* arg2) |
| 1230 | 1230 | { |
| 1231 | - // Test object parsing from a string. The input file is not used. | |
| 1232 | - | |
| 1233 | 1231 | auto o1 = "[/name 16059 3.14159 false\n" |
| 1234 | 1232 | " << /key true /other [ (string1) (string2) ] >> null]"_qpdf; |
| 1235 | 1233 | std::cout << o1.unparse() << std::endl; |
| ... | ... | @@ -1247,6 +1245,14 @@ test_31(QPDF& pdf, char const* arg2) |
| 1247 | 1245 | } catch (std::runtime_error const& e) { |
| 1248 | 1246 | std::cout << "trailing data: " << e.what() << std::endl; |
| 1249 | 1247 | } |
| 1248 | + try { | |
| 1249 | + assert(QPDFObjectHandle::parse(&pdf, "5 0 R").isInteger()); | |
| 1250 | + QPDFObjectHandle::parse(&pdf, "5 0 R 0 R"); | |
| 1251 | + std::cout << "oops -- didn't throw" << std::endl; | |
| 1252 | + } catch (std::runtime_error const& e) { | |
| 1253 | + std::cout << "broken indirect object reference: " << e.what() | |
| 1254 | + << std::endl; | |
| 1255 | + } | |
| 1250 | 1256 | assert( |
| 1251 | 1257 | QPDFObjectHandle::parse(&pdf, "[1 0 R]", "indirect test").unparse() == |
| 1252 | 1258 | "[ 1 0 R ]"); | ... | ... |