Commit e4e0f40fc0b9fe74865898b640ff82f84996bb5d

Authored by Jay Berkenbilt
1 parent 126b0269

Fix annotations properly for page with no /Resources (fixes #827)

ChangeLog
  1 +2023-01-09 Jay Berkenbilt <ejb@ql.org>
  2 +
  3 + * Bug fix: flatten annotations should handle a page with no
  4 + /Resources key. Fixes #827.
  5 +
1 6 2022-11-20 Jay Berkenbilt <ejb@ql.org>
2 7  
3 8 * 11.2.0: release
... ...
libqpdf/QPDFPageDocumentHelper.cc
... ... @@ -67,9 +67,11 @@ QPDFPageDocumentHelper::flattenAnnotations(
67 67 for (auto& ph: getAllPages()) {
68 68 QPDFObjectHandle resources = ph.getAttribute("/Resources", true);
69 69 if (!resources.isDictionary()) {
70   - // This should never happen and is not exercised in the
71   - // test suite
72   - resources = QPDFObjectHandle::newDictionary();
  70 + QTC::TC(
  71 + "qpdf",
  72 + "QPDFPageDocumentHelper flatten resources missing or invalid");
  73 + resources = ph.getObjectHandle().replaceKeyAndGetNew(
  74 + "/Resources", QPDFObjectHandle::newDictionary());
73 75 }
74 76 flattenAnnotationsForPage(
75 77 ph, resources, afdh, required_flags, forbidden_flags);
... ...
qpdf/qpdf.testcov
... ... @@ -679,3 +679,4 @@ QPDFPageObjectHelper copied fallback 0
679 679 QPDFPageObjectHelper used fallback without copying 0
680 680 QPDF skipping cache for known unchecked object 0
681 681 QPDF fix dangling triggered xref reconstruction 0
  682 +QPDFPageDocumentHelper flatten resources missing or invalid 0
... ...
qpdf/qtest/flatten-annotations.test
... ... @@ -55,6 +55,7 @@ my @annotation_files = (
55 55 'sample-form',
56 56 'need-appearances',
57 57 'need-appearances-more',
  58 + 'annotation-no-resources',
58 59 );
59 60 $n_tests += 2 * scalar(@annotation_files);
60 61  
... ...
qpdf/qtest/qpdf/annotation-no-resources-out.pdf 0 → 100644
  1 +%PDF-1.5
  2 +%¿÷¢þ
  3 +%QDF-1.0
  4 +
  5 +1 0 obj
  6 +<<
  7 + /Lang (en-US)
  8 + /MarkInfo <<
  9 + /Marked true
  10 + >>
  11 + /OpenAction [
  12 + 3 0 R
  13 + /XYZ
  14 + null
  15 + null
  16 + 0
  17 + ]
  18 + /Pages 4 0 R
  19 + /StructTreeRoot 5 0 R
  20 + /Type /Catalog
  21 +>>
  22 +endobj
  23 +
  24 +2 0 obj
  25 +<<
  26 + /CreationDate (D:20181224113354-05'00')
  27 + /Creator <feff005700720069007400650072>
  28 + /Producer <feff004c0069006200720065004f0066006600690063006500200036002e0031>
  29 +>>
  30 +endobj
  31 +
  32 +%% Page 1
  33 +3 0 obj
  34 +<<
  35 + /Contents [
  36 + 6 0 R
  37 + 8 0 R
  38 + 10 0 R
  39 + ]
  40 + /Group <<
  41 + /CS /DeviceRGB
  42 + /I true
  43 + /S /Transparency
  44 + >>
  45 + /MediaBox [
  46 + 0
  47 + 0
  48 + 612
  49 + 792
  50 + ]
  51 + /Parent 4 0 R
  52 + /Resources <<
  53 + /XObject <<
  54 + /Fxo1 12 0 R
  55 + /Fxo2 14 0 R
  56 + /Fxo3 16 0 R
  57 + >>
  58 + >>
  59 + /StructParents 0
  60 + /Type /Page
  61 +>>
  62 +endobj
  63 +
  64 +4 0 obj
  65 +<<
  66 + /Count 1
  67 + /Kids [
  68 + 3 0 R
  69 + ]
  70 + /Type /Pages
  71 +>>
  72 +endobj
  73 +
  74 +5 0 obj
  75 +<<
  76 + /K [
  77 + 18 0 R
  78 + ]
  79 + /ParentTree 19 0 R
  80 + /RoleMap <<
  81 + /Document /Document
  82 + /Standard /P
  83 + >>
  84 + /Type /StructTreeRoot
  85 +>>
  86 +endobj
  87 +
  88 +%% Contents for page 1
  89 +6 0 obj
  90 +<<
  91 + /Length 7 0 R
  92 +>>
  93 +stream
  94 +q
  95 +endstream
  96 +endobj
  97 +
  98 +7 0 obj
  99 +2
  100 +endobj
  101 +
  102 +%% Contents for page 1
  103 +8 0 obj
  104 +<<
  105 + /Length 9 0 R
  106 +>>
  107 +stream
  108 +0.1 w
  109 +/Artifact BMC
  110 +q 0 0.028 611.971 791.971 re
  111 +W* n
  112 +EMC
  113 +/Form<</MCID 0>>BDC
  114 +0 0 0 RG
  115 +1 1 1 rg
  116 +127.35 648.65 72.3 55.95 re B*
  117 +EMC
  118 +/Form<</MCID 1>>BDC
  119 +127.35 540.25 108.45 58 re B*
  120 +EMC
  121 +/Form<</MCID 2>>BDC
  122 +291.65 427.75 77.8 103 re B*
  123 +EMC
  124 +Q
  125 +endstream
  126 +endobj
  127 +
  128 +%QDF: ignore_newline
  129 +9 0 obj
  130 +240
  131 +endobj
  132 +
  133 +%% Contents for page 1
  134 +10 0 obj
  135 +<<
  136 + /Length 11 0 R
  137 +>>
  138 +stream
  139 +
  140 +Q
  141 +q
  142 +1.00003 0 0 0.99996 129.849 651.151 cm
  143 +/Fxo1 Do
  144 +Q
  145 +q
  146 +1.00002 0 0 0.99996 129.849 542.751 cm
  147 +/Fxo2 Do
  148 +Q
  149 +q
  150 +1.00003 0 0 0.99998 294.149 430.251 cm
  151 +/Fxo3 Do
  152 +Q
  153 +endstream
  154 +endobj
  155 +
  156 +11 0 obj
  157 +159
  158 +endobj
  159 +
  160 +12 0 obj
  161 +<<
  162 + /BBox [
  163 + 0
  164 + 0
  165 + 67.3
  166 + 50.95
  167 + ]
  168 + /Resources <<
  169 + /Font <<
  170 + >>
  171 + /ProcSet [
  172 + /PDF
  173 + /Text
  174 + ]
  175 + >>
  176 + /Subtype /Form
  177 + /Type /XObject
  178 + /Length 13 0 R
  179 +>>
  180 +stream
  181 +q
  182 +1 0 0 RG
  183 +5 w
  184 +0 0 67.3 50.95 re s
  185 +0 1 0 RG
  186 +5 5 15 15 re s
  187 +Q
  188 +endstream
  189 +endobj
  190 +
  191 +13 0 obj
  192 +61
  193 +endobj
  194 +
  195 +14 0 obj
  196 +<<
  197 + /BBox [
  198 + 0
  199 + 0
  200 + 103.45
  201 + 53
  202 + ]
  203 + /Resources <<
  204 + /Font <<
  205 + >>
  206 + /ProcSet [
  207 + /PDF
  208 + /Text
  209 + ]
  210 + >>
  211 + /Subtype /Form
  212 + /Type /XObject
  213 + /Length 15 0 R
  214 +>>
  215 +stream
  216 +q
  217 +0 1 0 RG
  218 +5 w
  219 +0 0 103.45 53 re s
  220 +0 0 1 RG
  221 +5 5 15 15 re s
  222 +1 w
  223 +1 0 0 RG
  224 +-10 25 m
  225 +113.45 25 l
  226 +52 -10 m
  227 +52 63 l
  228 +s
  229 +Q
  230 +endstream
  231 +endobj
  232 +
  233 +15 0 obj
  234 +113
  235 +endobj
  236 +
  237 +16 0 obj
  238 +<<
  239 + /BBox [
  240 + 0
  241 + 0
  242 + 72.8
  243 + 98
  244 + ]
  245 + /Resources <<
  246 + /Font <<
  247 + >>
  248 + /ProcSet [
  249 + /PDF
  250 + /Text
  251 + ]
  252 + >>
  253 + /Subtype /Form
  254 + /Type /XObject
  255 + /Length 17 0 R
  256 +>>
  257 +stream
  258 +q
  259 +0 0 1 RG
  260 +5 w
  261 +0 0 72.8 98 re s
  262 +1 0 0 RG
  263 +5 5 15 15 re s
  264 +Q
  265 +endstream
  266 +endobj
  267 +
  268 +17 0 obj
  269 +58
  270 +endobj
  271 +
  272 +18 0 obj
  273 +<<
  274 + /K [
  275 + 20 0 R
  276 + 21 0 R
  277 + 22 0 R
  278 + 23 0 R
  279 + ]
  280 + /P 5 0 R
  281 + /Pg 3 0 R
  282 + /S /Document
  283 + /Type /StructElem
  284 +>>
  285 +endobj
  286 +
  287 +19 0 obj
  288 +<<
  289 + /Nums [
  290 + 0
  291 + [
  292 + 21 0 R
  293 + 22 0 R
  294 + 23 0 R
  295 + ]
  296 + ]
  297 +>>
  298 +endobj
  299 +
  300 +20 0 obj
  301 +<<
  302 + /A 24 0 R
  303 + /P 18 0 R
  304 + /Pg 3 0 R
  305 + /S /Standard
  306 + /Type /StructElem
  307 +>>
  308 +endobj
  309 +
  310 +21 0 obj
  311 +<<
  312 + /K [
  313 + 0
  314 + ]
  315 + /P 18 0 R
  316 + /Pg 3 0 R
  317 + /S /Form
  318 + /Type /StructElem
  319 +>>
  320 +endobj
  321 +
  322 +22 0 obj
  323 +<<
  324 + /K [
  325 + 1
  326 + ]
  327 + /P 18 0 R
  328 + /Pg 3 0 R
  329 + /S /Form
  330 + /Type /StructElem
  331 +>>
  332 +endobj
  333 +
  334 +23 0 obj
  335 +<<
  336 + /K [
  337 + 2
  338 + ]
  339 + /P 18 0 R
  340 + /Pg 3 0 R
  341 + /S /Form
  342 + /Type /StructElem
  343 +>>
  344 +endobj
  345 +
  346 +24 0 obj
  347 +<<
  348 + /O /Layout
  349 + /Placement /Block
  350 +>>
  351 +endobj
  352 +
  353 +xref
  354 +0 25
  355 +0000000000 65535 f
  356 +0000000025 00000 n
  357 +0000000219 00000 n
  358 +0000000414 00000 n
  359 +0000000750 00000 n
  360 +0000000822 00000 n
  361 +0000000994 00000 n
  362 +0000001051 00000 n
  363 +0000001092 00000 n
  364 +0000001409 00000 n
  365 +0000001452 00000 n
  366 +0000001668 00000 n
  367 +0000001689 00000 n
  368 +0000001971 00000 n
  369 +0000001991 00000 n
  370 +0000002324 00000 n
  371 +0000002345 00000 n
  372 +0000002621 00000 n
  373 +0000002641 00000 n
  374 +0000002777 00000 n
  375 +0000002871 00000 n
  376 +0000002965 00000 n
  377 +0000003060 00000 n
  378 +0000003155 00000 n
  379 +0000003250 00000 n
  380 +trailer <<
  381 + /DocChecksum /DA785F789D02970D387C264D0A6C8CB0
  382 + /Info 2 0 R
  383 + /Root 1 0 R
  384 + /Size 25
  385 + /ID [<976442cb303b8d5e88a36a127de2a19f><31415926535897932384626433832795>]
  386 +>>
  387 +startxref
  388 +3306
  389 +%%EOF
... ...
qpdf/qtest/qpdf/annotation-no-resources.pdf 0 → 100644
  1 +%PDF-1.5
  2 +%¿÷¢þ
  3 +%QDF-1.0
  4 +
  5 +1 0 obj
  6 +<<
  7 + /AcroForm <<
  8 + /DR 3 0 R
  9 + /Fields [
  10 + 4 0 R
  11 + 5 0 R
  12 + 6 0 R
  13 + ]
  14 + /NeedAppearances false
  15 + >>
  16 + /Lang (en-US)
  17 + /MarkInfo <<
  18 + /Marked true
  19 + >>
  20 + /OpenAction [
  21 + 7 0 R
  22 + /XYZ
  23 + null
  24 + null
  25 + 0
  26 + ]
  27 + /Pages 8 0 R
  28 + /StructTreeRoot 9 0 R
  29 + /Type /Catalog
  30 +>>
  31 +endobj
  32 +
  33 +2 0 obj
  34 +<<
  35 + /CreationDate (D:20181224113354-05'00')
  36 + /Creator <feff005700720069007400650072>
  37 + /Producer <feff004c0069006200720065004f0066006600690063006500200036002e0031>
  38 +>>
  39 +endobj
  40 +
  41 +3 0 obj
  42 +<<
  43 + /Font 10 0 R
  44 + /ProcSet [
  45 + /PDF
  46 + /Text
  47 + ]
  48 +>>
  49 +endobj
  50 +
  51 +4 0 obj
  52 +<<
  53 + /AP <<
  54 + /N 11 0 R
  55 + >>
  56 + /DA (0.18039 0.20392 0.21176 rg /F1 10 Tf)
  57 + /DR <<
  58 + /Font 10 0 R
  59 + >>
  60 + /DV <feff>
  61 + /F 4
  62 + /FT /Tx
  63 + /Ff 4096
  64 + /P 7 0 R
  65 + /Rect [
  66 + 129.849
  67 + 651.151
  68 + 197.151
  69 + 702.099
  70 + ]
  71 + /Subtype /Widget
  72 + /T (Text Box 1)
  73 + /Type /Annot
  74 + /V <feff>
  75 +>>
  76 +endobj
  77 +
  78 +5 0 obj
  79 +<<
  80 + /AP <<
  81 + /N 13 0 R
  82 + >>
  83 + /DA (0.18039 0.20392 0.21176 rg /F1 10 Tf)
  84 + /DR <<
  85 + /Font 10 0 R
  86 + >>
  87 + /DV <feff>
  88 + /F 4
  89 + /FT /Tx
  90 + /Ff 4096
  91 + /P 7 0 R
  92 + /Rect [
  93 + 129.849
  94 + 542.751
  95 + 233.301
  96 + 595.749
  97 + ]
  98 + /Subtype /Widget
  99 + /T (Text Box 2)
  100 + /Type /Annot
  101 + /V <feff>
  102 +>>
  103 +endobj
  104 +
  105 +6 0 obj
  106 +<<
  107 + /AP <<
  108 + /N 15 0 R
  109 + >>
  110 + /DA (0.18039 0.20392 0.21176 rg /F1 10 Tf)
  111 + /DR <<
  112 + /Font 10 0 R
  113 + >>
  114 + /DV <feff>
  115 + /F 4
  116 + /FT /Tx
  117 + /Ff 4096
  118 + /P 7 0 R
  119 + /Rect [
  120 + 294.149
  121 + 430.251
  122 + 366.951
  123 + 528.249
  124 + ]
  125 + /Subtype /Widget
  126 + /T (Text Box 3)
  127 + /Type /Annot
  128 + /V <feff>
  129 +>>
  130 +endobj
  131 +
  132 +%% Page 1
  133 +7 0 obj
  134 +<<
  135 + /Annots [
  136 + 4 0 R
  137 + 5 0 R
  138 + 6 0 R
  139 + ]
  140 + /Contents 17 0 R
  141 + /Group <<
  142 + /CS /DeviceRGB
  143 + /I true
  144 + /S /Transparency
  145 + >>
  146 + /MediaBox [
  147 + 0
  148 + 0
  149 + 612
  150 + 792
  151 + ]
  152 + /Parent 8 0 R
  153 + /StructParents 0
  154 + /Type /Page
  155 +>>
  156 +endobj
  157 +
  158 +8 0 obj
  159 +<<
  160 + /Count 1
  161 + /Kids [
  162 + 7 0 R
  163 + ]
  164 + /Type /Pages
  165 +>>
  166 +endobj
  167 +
  168 +9 0 obj
  169 +<<
  170 + /K [
  171 + 19 0 R
  172 + ]
  173 + /ParentTree 20 0 R
  174 + /RoleMap <<
  175 + /Document /Document
  176 + /Standard /P
  177 + >>
  178 + /Type /StructTreeRoot
  179 +>>
  180 +endobj
  181 +
  182 +10 0 obj
  183 +<<
  184 +>>
  185 +endobj
  186 +
  187 +11 0 obj
  188 +<<
  189 + /BBox [
  190 + 0
  191 + 0
  192 + 67.3
  193 + 50.95
  194 + ]
  195 + /Resources 3 0 R
  196 + /Subtype /Form
  197 + /Type /XObject
  198 + /Length 12 0 R
  199 +>>
  200 +stream
  201 +q
  202 +1 0 0 RG
  203 +5 w
  204 +0 0 67.3 50.95 re s
  205 +0 1 0 RG
  206 +5 5 15 15 re s
  207 +Q
  208 +endstream
  209 +endobj
  210 +
  211 +12 0 obj
  212 +61
  213 +endobj
  214 +
  215 +13 0 obj
  216 +<<
  217 + /BBox [
  218 + 0
  219 + 0
  220 + 103.45
  221 + 53
  222 + ]
  223 + /Resources 3 0 R
  224 + /Subtype /Form
  225 + /Type /XObject
  226 + /Length 14 0 R
  227 +>>
  228 +stream
  229 +q
  230 +0 1 0 RG
  231 +5 w
  232 +0 0 103.45 53 re s
  233 +0 0 1 RG
  234 +5 5 15 15 re s
  235 +1 w
  236 +1 0 0 RG
  237 +-10 25 m
  238 +113.45 25 l
  239 +52 -10 m
  240 +52 63 l
  241 +s
  242 +Q
  243 +endstream
  244 +endobj
  245 +
  246 +14 0 obj
  247 +113
  248 +endobj
  249 +
  250 +15 0 obj
  251 +<<
  252 + /BBox [
  253 + 0
  254 + 0
  255 + 72.8
  256 + 98
  257 + ]
  258 + /Resources 3 0 R
  259 + /Subtype /Form
  260 + /Type /XObject
  261 + /Length 16 0 R
  262 +>>
  263 +stream
  264 +q
  265 +0 0 1 RG
  266 +5 w
  267 +0 0 72.8 98 re s
  268 +1 0 0 RG
  269 +5 5 15 15 re s
  270 +Q
  271 +endstream
  272 +endobj
  273 +
  274 +16 0 obj
  275 +58
  276 +endobj
  277 +
  278 +%% Contents for page 1
  279 +17 0 obj
  280 +<<
  281 + /Length 18 0 R
  282 +>>
  283 +stream
  284 +0.1 w
  285 +/Artifact BMC
  286 +q 0 0.028 611.971 791.971 re
  287 +W* n
  288 +EMC
  289 +/Form<</MCID 0>>BDC
  290 +0 0 0 RG
  291 +1 1 1 rg
  292 +127.35 648.65 72.3 55.95 re B*
  293 +EMC
  294 +/Form<</MCID 1>>BDC
  295 +127.35 540.25 108.45 58 re B*
  296 +EMC
  297 +/Form<</MCID 2>>BDC
  298 +291.65 427.75 77.8 103 re B*
  299 +EMC
  300 +Q
  301 +endstream
  302 +endobj
  303 +
  304 +%QDF: ignore_newline
  305 +18 0 obj
  306 +240
  307 +endobj
  308 +
  309 +19 0 obj
  310 +<<
  311 + /K [
  312 + 21 0 R
  313 + 22 0 R
  314 + 23 0 R
  315 + 24 0 R
  316 + ]
  317 + /P 9 0 R
  318 + /Pg 7 0 R
  319 + /S /Document
  320 + /Type /StructElem
  321 +>>
  322 +endobj
  323 +
  324 +20 0 obj
  325 +<<
  326 + /Nums [
  327 + 0
  328 + [
  329 + 22 0 R
  330 + 23 0 R
  331 + 24 0 R
  332 + ]
  333 + ]
  334 +>>
  335 +endobj
  336 +
  337 +21 0 obj
  338 +<<
  339 + /A 25 0 R
  340 + /P 19 0 R
  341 + /Pg 7 0 R
  342 + /S /Standard
  343 + /Type /StructElem
  344 +>>
  345 +endobj
  346 +
  347 +22 0 obj
  348 +<<
  349 + /K [
  350 + 0
  351 + ]
  352 + /P 19 0 R
  353 + /Pg 7 0 R
  354 + /S /Form
  355 + /Type /StructElem
  356 +>>
  357 +endobj
  358 +
  359 +23 0 obj
  360 +<<
  361 + /K [
  362 + 1
  363 + ]
  364 + /P 19 0 R
  365 + /Pg 7 0 R
  366 + /S /Form
  367 + /Type /StructElem
  368 +>>
  369 +endobj
  370 +
  371 +24 0 obj
  372 +<<
  373 + /K [
  374 + 2
  375 + ]
  376 + /P 19 0 R
  377 + /Pg 7 0 R
  378 + /S /Form
  379 + /Type /StructElem
  380 +>>
  381 +endobj
  382 +
  383 +25 0 obj
  384 +<<
  385 + /O /Layout
  386 + /Placement /Block
  387 +>>
  388 +endobj
  389 +
  390 +xref
  391 +0 26
  392 +0000000000 65535 f
  393 +0000000025 00000 n
  394 +0000000336 00000 n
  395 +0000000521 00000 n
  396 +0000000594 00000 n
  397 +0000000898 00000 n
  398 +0000001202 00000 n
  399 +0000001516 00000 n
  400 +0000001767 00000 n
  401 +0000001839 00000 n
  402 +0000001988 00000 n
  403 +0000002011 00000 n
  404 +0000002227 00000 n
  405 +0000002247 00000 n
  406 +0000002514 00000 n
  407 +0000002535 00000 n
  408 +0000002745 00000 n
  409 +0000002788 00000 n
  410 +0000003107 00000 n
  411 +0000003128 00000 n
  412 +0000003264 00000 n
  413 +0000003358 00000 n
  414 +0000003452 00000 n
  415 +0000003547 00000 n
  416 +0000003642 00000 n
  417 +0000003737 00000 n
  418 +trailer <<
  419 + /DocChecksum /DA785F789D02970D387C264D0A6C8CB0
  420 + /Info 2 0 R
  421 + /Root 1 0 R
  422 + /Size 26
  423 + /ID [<976442cb303b8d5e88a36a127de2a19f><ad9b3712a3de3e1f77381c0ef1d15737>]
  424 +>>
  425 +startxref
  426 +3793
  427 +%%EOF
... ...