Commit 5e121c96906d4d81b882f84407459f5e1312af34

Authored by Jay Berkenbilt
1 parent 9106a5e3

Handle null form field from annotation (fixes #1189)

A file that has Widget annotations that can't be mapped back to form
fields would crash qpdf json.
libqpdf/QPDFJob.cc
... ... @@ -1168,6 +1168,9 @@ QPDFJob::doJSONAcroform(Pipeline* p, bool& first, QPDF& pdf)
1168 1168 ++pagepos1;
1169 1169 for (auto& aoh: afdh.getWidgetAnnotationsForPage(page)) {
1170 1170 QPDFFormFieldObjectHelper ffh = afdh.getFieldForAnnotation(aoh);
  1171 + if (!ffh.getObjectHandle().isDictionary()) {
  1172 + continue;
  1173 + }
1171 1174 JSON j_field = j_fields.addArrayElement(JSON::makeDictionary());
1172 1175 j_field.addDictionaryMember("object", ffh.getObjectHandle().getJSON(m->json_version));
1173 1176 j_field.addDictionaryMember(
... ...
qpdf/qtest/copy-annotations.test
... ... @@ -14,7 +14,7 @@ cleanup();
14 14  
15 15 my $td = new TestDriver('copy-annotations');
16 16  
17   -my $n_tests = 45;
  17 +my $n_tests = 46;
18 18  
19 19 $td->runtest("complex copy annotations",
20 20 {$td->COMMAND =>
... ... @@ -50,6 +50,13 @@ $td->runtest("copy annotations no acroform from foreign file",
50 50 {$td->STRING => "", $td->EXIT_STATUS => 0},
51 51 $td->NORMALIZE_NEWLINES);
52 52  
  53 +$td->runtest("get json no acroform",
  54 + {$td->COMMAND =>
  55 + "qpdf --json annotations-no-acroform.pdf"},
  56 + {$td->FILE => "annotations-no-acroform.json",
  57 + $td->EXIT_STATUS => 0},
  58 + $td->NORMALIZE_NEWLINES);
  59 +
53 60 $td->runtest("check output",
54 61 {$td->FILE => "a.pdf"},
55 62 {$td->FILE => "annotations-same-file.out.pdf"});
... ...
qpdf/qtest/qpdf/annotations-no-acroform.json 0 → 100644
  1 +{
  2 + "version": 2,
  3 + "parameters": {
  4 + "decodelevel": "generalized"
  5 + },
  6 + "pages": [
  7 + {
  8 + "contents": [
  9 + "39 0 R"
  10 + ],
  11 + "images": [],
  12 + "label": null,
  13 + "object": "17 0 R",
  14 + "outlines": [],
  15 + "pageposfrom1": 1
  16 + }
  17 + ],
  18 + "pagelabels": [],
  19 + "acroform": {
  20 + "fields": [],
  21 + "hasacroform": false,
  22 + "needappearances": false
  23 + },
  24 + "attachments": {
  25 + "attachment1.txt": {
  26 + "description": null,
  27 + "filespec": "16 0 R",
  28 + "names": {
  29 + "/F": "attachment1.txt",
  30 + "/UF": "attachment1.txt"
  31 + },
  32 + "preferredcontents": "31 0 R",
  33 + "preferredname": "attachment1.txt",
  34 + "streams": {
  35 + "/F": {
  36 + "checksum": "80a33fc110b5a7b8b4d58b8d57e814bc",
  37 + "creationdate": null,
  38 + "mimetype": null,
  39 + "modificationdate": null
  40 + },
  41 + "/UF": {
  42 + "checksum": "80a33fc110b5a7b8b4d58b8d57e814bc",
  43 + "creationdate": null,
  44 + "mimetype": null,
  45 + "modificationdate": null
  46 + }
  47 + }
  48 + }
  49 + },
  50 + "encrypt": {
  51 + "capabilities": {
  52 + "accessibility": true,
  53 + "extract": true,
  54 + "modify": true,
  55 + "modifyannotations": true,
  56 + "modifyassembly": true,
  57 + "modifyforms": true,
  58 + "modifyother": true,
  59 + "printhigh": true,
  60 + "printlow": true
  61 + },
  62 + "encrypted": false,
  63 + "ownerpasswordmatched": false,
  64 + "parameters": {
  65 + "P": 0,
  66 + "R": 0,
  67 + "V": 0,
  68 + "bits": 0,
  69 + "filemethod": "none",
  70 + "key": null,
  71 + "method": "none",
  72 + "streammethod": "none",
  73 + "stringmethod": "none"
  74 + },
  75 + "recovereduserpassword": null,
  76 + "userpasswordmatched": false
  77 + },
  78 + "outlines": [],
  79 + "qpdf": [
  80 + {
  81 + "jsonversion": 2,
  82 + "pdfversion": "1.6",
  83 + "pushedinheritedpageresources": false,
  84 + "calledgetallpages": true,
  85 + "maxobjectid": 52
  86 + },
  87 + {
  88 + "obj:1 0 R": {
  89 + "value": {
  90 + "/Names": {
  91 + "/EmbeddedFiles": "6 0 R"
  92 + },
  93 + "/Pages": "7 0 R",
  94 + "/Type": "/Catalog"
  95 + }
  96 + },
  97 + "obj:2 0 R": {
  98 + "value": {
  99 + "/Font": {
  100 + "/F1": "8 0 R"
  101 + }
  102 + }
  103 + },
  104 + "obj:3 0 R": {
  105 + "value": {
  106 + "/AP": {
  107 + "/N": "9 0 R"
  108 + },
  109 + "/DA": "u:0 0.4 0 rg /F1 18 Tf",
  110 + "/DR": "2 0 R",
  111 + "/DV": "u:",
  112 + "/FT": "/Tx",
  113 + "/Ff": 0,
  114 + "/Rect": [
  115 + 72,
  116 + 470.774,
  117 + 190.8,
  118 + 484.922
  119 + ],
  120 + "/Subtype": "/Widget",
  121 + "/T": "u:Text Box 1",
  122 + "/Type": "/Annot",
  123 + "/V": "u:Formy field"
  124 + }
  125 + },
  126 + "obj:4 0 R": {
  127 + "value": {
  128 + "/AP": {
  129 + "/N": "11 0 R"
  130 + },
  131 + "/DA": "u:0 0.4 0 rg /F1 18 Tf",
  132 + "/DR": "2 0 R",
  133 + "/DV": "u:",
  134 + "/FT": "/Tx",
  135 + "/Ff": 0,
  136 + "/Rect": [
  137 + 372,
  138 + 330.774,
  139 + 386.148,
  140 + 470.374
  141 + ],
  142 + "/Subtype": "/Widget",
  143 + "/T": "u:Text Box 2",
  144 + "/Type": "/Annot",
  145 + "/V": "u:Rot-ccw field"
  146 + }
  147 + },
  148 + "obj:5 0 R": {
  149 + "value": {
  150 + "/DV": "/1",
  151 + "/FT": "/Btn",
  152 + "/Ff": 49152,
  153 + "/Kids": [
  154 + "13 0 R",
  155 + "14 0 R",
  156 + "15 0 R"
  157 + ],
  158 + "/T": "u:r1",
  159 + "/V": "/2"
  160 + }
  161 + },
  162 + "obj:6 0 R": {
  163 + "value": {
  164 + "/Names": [
  165 + "u:attachment1.txt",
  166 + "16 0 R"
  167 + ]
  168 + }
  169 + },
  170 + "obj:7 0 R": {
  171 + "value": {
  172 + "/Count": 1,
  173 + "/Kids": [
  174 + "17 0 R"
  175 + ],
  176 + "/Type": "/Pages"
  177 + }
  178 + },
  179 + "obj:8 0 R": {
  180 + "value": {
  181 + "/BaseFont": "/Courier",
  182 + "/Encoding": "/WinAnsiEncoding",
  183 + "/Subtype": "/Type1",
  184 + "/Type": "/Font"
  185 + }
  186 + },
  187 + "obj:9 0 R": {
  188 + "stream": {
  189 + "dict": {
  190 + "/BBox": [
  191 + 0,
  192 + -2.826,
  193 + 118.8,
  194 + 11.322
  195 + ],
  196 + "/Length": "10 0 R",
  197 + "/Resources": "2 0 R",
  198 + "/Subtype": "/Form",
  199 + "/Type": "/XObject"
  200 + }
  201 + }
  202 + },
  203 + "obj:10 0 R": {
  204 + "value": 53
  205 + },
  206 + "obj:11 0 R": {
  207 + "stream": {
  208 + "dict": {
  209 + "/BBox": [
  210 + 0,
  211 + -2.826,
  212 + 140.4,
  213 + 11.322
  214 + ],
  215 + "/Length": "12 0 R",
  216 + "/Matrix": [
  217 + 0,
  218 + 1,
  219 + -1,
  220 + 0,
  221 + 0,
  222 + 0
  223 + ],
  224 + "/Resources": "2 0 R",
  225 + "/Subtype": "/Form",
  226 + "/Type": "/XObject"
  227 + }
  228 + }
  229 + },
  230 + "obj:12 0 R": {
  231 + "value": 55
  232 + },
  233 + "obj:13 0 R": {
  234 + "value": {
  235 + "/AP": {
  236 + "/N": {
  237 + "/1": "18 0 R",
  238 + "/Off": "20 0 R"
  239 + }
  240 + },
  241 + "/AS": "/1",
  242 + "/DA": "u:0.18039 0.20392 0.21176 rg /ZaDi 0 Tf",
  243 + "/DR": {
  244 + "/Font": {
  245 + "/ZaDi": "22 0 R"
  246 + }
  247 + },
  248 + "/F": 4,
  249 + "/FT": "/Btn",
  250 + "/MK": {
  251 + "/CA": "u:l"
  252 + },
  253 + "/Parent": "5 0 R",
  254 + "/Rect": [
  255 + 152.749,
  256 + 648.501,
  257 + 164.801,
  258 + 660.549
  259 + ],
  260 + "/Subtype": "/Widget",
  261 + "/Type": "/Annot"
  262 + }
  263 + },
  264 + "obj:14 0 R": {
  265 + "value": {
  266 + "/AP": {
  267 + "/N": {
  268 + "/2": "23 0 R",
  269 + "/Off": "25 0 R"
  270 + }
  271 + },
  272 + "/AS": "/2",
  273 + "/DA": "u:0.18039 0.20392 0.21176 rg /ZaDi 0 Tf",
  274 + "/DR": {
  275 + "/Font": {
  276 + "/ZaDi": "22 0 R"
  277 + }
  278 + },
  279 + "/F": 4,
  280 + "/FT": "/Btn",
  281 + "/MK": {
  282 + "/CA": "u:l"
  283 + },
  284 + "/Parent": "5 0 R",
  285 + "/Rect": [
  286 + 152.749,
  287 + 627.301,
  288 + 164.801,
  289 + 639.349
  290 + ],
  291 + "/Subtype": "/Widget",
  292 + "/Type": "/Annot"
  293 + }
  294 + },
  295 + "obj:15 0 R": {
  296 + "value": {
  297 + "/AP": {
  298 + "/N": {
  299 + "/3": "27 0 R",
  300 + "/Off": "29 0 R"
  301 + }
  302 + },
  303 + "/AS": "/3",
  304 + "/DA": "u:0.18039 0.20392 0.21176 rg /ZaDi 0 Tf",
  305 + "/DR": {
  306 + "/Font": {
  307 + "/ZaDi": "22 0 R"
  308 + }
  309 + },
  310 + "/F": 4,
  311 + "/FT": "/Btn",
  312 + "/MK": {
  313 + "/CA": "u:l"
  314 + },
  315 + "/Parent": "5 0 R",
  316 + "/Rect": [
  317 + 151.399,
  318 + 606.501,
  319 + 163.451,
  320 + 618.549
  321 + ],
  322 + "/Subtype": "/Widget",
  323 + "/Type": "/Annot"
  324 + }
  325 + },
  326 + "obj:16 0 R": {
  327 + "value": {
  328 + "/EF": {
  329 + "/F": "31 0 R",
  330 + "/UF": "31 0 R"
  331 + },
  332 + "/F": "u:attachment1.txt",
  333 + "/Type": "/Filespec",
  334 + "/UF": "u:attachment1.txt"
  335 + }
  336 + },
  337 + "obj:17 0 R": {
  338 + "value": {
  339 + "/Annots": [
  340 + "33 0 R",
  341 + "3 0 R",
  342 + "34 0 R",
  343 + "4 0 R",
  344 + "35 0 R",
  345 + "36 0 R",
  346 + "37 0 R",
  347 + "38 0 R",
  348 + "13 0 R",
  349 + "14 0 R",
  350 + "15 0 R"
  351 + ],
  352 + "/Contents": "39 0 R",
  353 + "/MediaBox": [
  354 + 0,
  355 + 0,
  356 + 612,
  357 + 792
  358 + ],
  359 + "/Parent": "7 0 R",
  360 + "/Resources": "2 0 R",
  361 + "/Type": "/Page"
  362 + }
  363 + },
  364 + "obj:18 0 R": {
  365 + "stream": {
  366 + "dict": {
  367 + "/BBox": [
  368 + 0,
  369 + 0,
  370 + 12.05,
  371 + 12.05
  372 + ],
  373 + "/Length": "19 0 R",
  374 + "/Resources": "41 0 R",
  375 + "/Subtype": "/Form",
  376 + "/Type": "/XObject"
  377 + }
  378 + }
  379 + },
  380 + "obj:19 0 R": {
  381 + "value": 202
  382 + },
  383 + "obj:20 0 R": {
  384 + "stream": {
  385 + "dict": {
  386 + "/BBox": [
  387 + 0,
  388 + 0,
  389 + 12.05,
  390 + 12.05
  391 + ],
  392 + "/Length": "21 0 R",
  393 + "/Resources": "41 0 R",
  394 + "/Subtype": "/Form",
  395 + "/Type": "/XObject"
  396 + }
  397 + }
  398 + },
  399 + "obj:21 0 R": {
  400 + "value": 12
  401 + },
  402 + "obj:22 0 R": {
  403 + "value": {
  404 + "/BaseFont": "/ZapfDingbats",
  405 + "/Subtype": "/Type1",
  406 + "/Type": "/Font"
  407 + }
  408 + },
  409 + "obj:23 0 R": {
  410 + "stream": {
  411 + "dict": {
  412 + "/BBox": [
  413 + 0,
  414 + 0,
  415 + 12.05,
  416 + 12.05
  417 + ],
  418 + "/Length": "24 0 R",
  419 + "/Resources": "41 0 R",
  420 + "/Subtype": "/Form",
  421 + "/Type": "/XObject"
  422 + }
  423 + }
  424 + },
  425 + "obj:24 0 R": {
  426 + "value": 202
  427 + },
  428 + "obj:25 0 R": {
  429 + "stream": {
  430 + "dict": {
  431 + "/BBox": [
  432 + 0,
  433 + 0,
  434 + 12.05,
  435 + 12.05
  436 + ],
  437 + "/Length": "26 0 R",
  438 + "/Resources": "41 0 R",
  439 + "/Subtype": "/Form",
  440 + "/Type": "/XObject"
  441 + }
  442 + }
  443 + },
  444 + "obj:26 0 R": {
  445 + "value": 12
  446 + },
  447 + "obj:27 0 R": {
  448 + "stream": {
  449 + "dict": {
  450 + "/BBox": [
  451 + 0,
  452 + 0,
  453 + 12.05,
  454 + 12.05
  455 + ],
  456 + "/Length": "28 0 R",
  457 + "/Resources": "41 0 R",
  458 + "/Subtype": "/Form",
  459 + "/Type": "/XObject"
  460 + }
  461 + }
  462 + },
  463 + "obj:28 0 R": {
  464 + "value": 202
  465 + },
  466 + "obj:29 0 R": {
  467 + "stream": {
  468 + "dict": {
  469 + "/BBox": [
  470 + 0,
  471 + 0,
  472 + 12.05,
  473 + 12.05
  474 + ],
  475 + "/Length": "30 0 R",
  476 + "/Resources": "41 0 R",
  477 + "/Subtype": "/Form",
  478 + "/Type": "/XObject"
  479 + }
  480 + }
  481 + },
  482 + "obj:30 0 R": {
  483 + "value": 12
  484 + },
  485 + "obj:31 0 R": {
  486 + "stream": {
  487 + "dict": {
  488 + "/Length": "32 0 R",
  489 + "/Params": {
  490 + "/CheckSum": "b:80a33fc110b5a7b8b4d58b8d57e814bc",
  491 + "/Size": 22,
  492 + "/Subtype": "/text/plain"
  493 + },
  494 + "/Type": "/EmbeddedFile"
  495 + }
  496 + }
  497 + },
  498 + "obj:32 0 R": {
  499 + "value": 22
  500 + },
  501 + "obj:33 0 R": {
  502 + "value": {
  503 + "/A": {
  504 + "/S": "/URI",
  505 + "/URI": "u:https://www.qbilt.org/"
  506 + },
  507 + "/Border": [
  508 + 0,
  509 + 0,
  510 + 0.4
  511 + ],
  512 + "/C": [
  513 + 0.8,
  514 + 0.6,
  515 + 0.6
  516 + ],
  517 + "/H": "/I",
  518 + "/Rect": [
  519 + 72,
  520 + 501.832,
  521 + 374.4,
  522 + 520.696
  523 + ],
  524 + "/Subtype": "/Link",
  525 + "/Type": "/Annot"
  526 + }
  527 + },
  528 + "obj:34 0 R": {
  529 + "value": {
  530 + "/AP": {
  531 + "/N": "42 0 R"
  532 + },
  533 + "/Contents": "u:attachment1.txt",
  534 + "/FS": "16 0 R",
  535 + "/NM": "u:attachment1.txt",
  536 + "/Rect": [
  537 + 72,
  538 + 400,
  539 + 92,
  540 + 420
  541 + ],
  542 + "/Subtype": "/FileAttachment",
  543 + "/Type": "/Annot"
  544 + }
  545 + },
  546 + "obj:35 0 R": {
  547 + "value": {
  548 + "/AP": {
  549 + "/N": "44 0 R"
  550 + },
  551 + "/DA": "u:",
  552 + "/Rect": [
  553 + 72,
  554 + 350,
  555 + 92,
  556 + 360
  557 + ],
  558 + "/Subtype": "/FreeText",
  559 + "/Type": "/Annot"
  560 + }
  561 + },
  562 + "obj:36 0 R": {
  563 + "value": {
  564 + "/AP": {
  565 + "/N": "46 0 R"
  566 + },
  567 + "/DA": "u:",
  568 + "/Rect": [
  569 + 102,
  570 + 350,
  571 + 112,
  572 + 370
  573 + ],
  574 + "/Subtype": "/FreeText",
  575 + "/Type": "/Annot"
  576 + }
  577 + },
  578 + "obj:37 0 R": {
  579 + "value": {
  580 + "/AP": {
  581 + "/N": "48 0 R"
  582 + },
  583 + "/DA": "u:",
  584 + "/Rect": [
  585 + 122,
  586 + 350,
  587 + 142,
  588 + 360
  589 + ],
  590 + "/Subtype": "/FreeText",
  591 + "/Type": "/Annot"
  592 + }
  593 + },
  594 + "obj:38 0 R": {
  595 + "value": {
  596 + "/AP": {
  597 + "/N": "50 0 R"
  598 + },
  599 + "/DA": "u:",
  600 + "/Rect": [
  601 + 152,
  602 + 350,
  603 + 162,
  604 + 370
  605 + ],
  606 + "/Subtype": "/FreeText",
  607 + "/Type": "/Annot"
  608 + }
  609 + },
  610 + "obj:39 0 R": {
  611 + "stream": {
  612 + "dict": {
  613 + "/Length": "40 0 R"
  614 + }
  615 + }
  616 + },
  617 + "obj:40 0 R": {
  618 + "value": 874
  619 + },
  620 + "obj:41 0 R": {
  621 + "value": {
  622 + "/Font": "52 0 R",
  623 + "/ProcSet": [
  624 + "/PDF",
  625 + "/Text"
  626 + ]
  627 + }
  628 + },
  629 + "obj:42 0 R": {
  630 + "stream": {
  631 + "dict": {
  632 + "/BBox": [
  633 + 0,
  634 + 0,
  635 + 20,
  636 + 20
  637 + ],
  638 + "/Length": "43 0 R",
  639 + "/Resources": {},
  640 + "/Subtype": "/Form",
  641 + "/Type": "/XObject"
  642 + }
  643 + }
  644 + },
  645 + "obj:43 0 R": {
  646 + "value": 52
  647 + },
  648 + "obj:44 0 R": {
  649 + "stream": {
  650 + "dict": {
  651 + "/BBox": [
  652 + 0,
  653 + 0,
  654 + 20,
  655 + 10
  656 + ],
  657 + "/Length": "45 0 R",
  658 + "/Resources": "2 0 R",
  659 + "/Subtype": "/Form",
  660 + "/Type": "/XObject"
  661 + }
  662 + }
  663 + },
  664 + "obj:45 0 R": {
  665 + "value": 36
  666 + },
  667 + "obj:46 0 R": {
  668 + "stream": {
  669 + "dict": {
  670 + "/BBox": [
  671 + 0,
  672 + 0,
  673 + 20,
  674 + 10
  675 + ],
  676 + "/Length": "47 0 R",
  677 + "/Matrix": [
  678 + 0,
  679 + 1,
  680 + -1,
  681 + 0,
  682 + 0,
  683 + 0
  684 + ],
  685 + "/Resources": "2 0 R",
  686 + "/Subtype": "/Form",
  687 + "/Type": "/XObject"
  688 + }
  689 + }
  690 + },
  691 + "obj:47 0 R": {
  692 + "value": 36
  693 + },
  694 + "obj:48 0 R": {
  695 + "stream": {
  696 + "dict": {
  697 + "/BBox": [
  698 + 0,
  699 + 0,
  700 + 20,
  701 + 10
  702 + ],
  703 + "/Length": "49 0 R",
  704 + "/Matrix": [
  705 + -1,
  706 + 0,
  707 + 0,
  708 + -1,
  709 + 0,
  710 + 0
  711 + ],
  712 + "/Resources": "2 0 R",
  713 + "/Subtype": "/Form",
  714 + "/Type": "/XObject"
  715 + }
  716 + }
  717 + },
  718 + "obj:49 0 R": {
  719 + "value": 36
  720 + },
  721 + "obj:50 0 R": {
  722 + "stream": {
  723 + "dict": {
  724 + "/BBox": [
  725 + 0,
  726 + 0,
  727 + 20,
  728 + 10
  729 + ],
  730 + "/Length": "51 0 R",
  731 + "/Matrix": [
  732 + 0,
  733 + -1,
  734 + 1,
  735 + 0,
  736 + 0,
  737 + 0
  738 + ],
  739 + "/Resources": "2 0 R",
  740 + "/Subtype": "/Form",
  741 + "/Type": "/XObject"
  742 + }
  743 + }
  744 + },
  745 + "obj:51 0 R": {
  746 + "value": 38
  747 + },
  748 + "obj:52 0 R": {
  749 + "value": {
  750 + "/ZaDi": "22 0 R"
  751 + }
  752 + },
  753 + "trailer": {
  754 + "value": {
  755 + "/ID": [
  756 + "b:a2f146daeb6d814a742556489dab9882",
  757 + "b:7b639c67bfc16b5e891fa5468aac3a14"
  758 + ],
  759 + "/Root": "1 0 R",
  760 + "/Size": 53
  761 + }
  762 + }
  763 + }
  764 + ]
  765 +}
... ...