diff options
author | Jay Berkenbilt <ejb@ql.org> | 2023-01-09 13:31:39 +0100 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2023-01-09 13:31:39 +0100 |
commit | e4e0f40fc0b9fe74865898b640ff82f84996bb5d (patch) | |
tree | 2cf9ff020152d238d523ca9288e329305a9d4acf | |
parent | 126b0269379bbb6cc6c8b808d34b216539682a75 (diff) | |
download | qpdf-e4e0f40fc0b9fe74865898b640ff82f84996bb5d.tar.zst |
Fix annotations properly for page with no /Resources (fixes #827)
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | libqpdf/QPDFPageDocumentHelper.cc | 8 | ||||
-rw-r--r-- | qpdf/qpdf.testcov | 1 | ||||
-rw-r--r-- | qpdf/qtest/flatten-annotations.test | 1 | ||||
-rw-r--r-- | qpdf/qtest/qpdf/annotation-no-resources-out.pdf | 389 | ||||
-rw-r--r-- | qpdf/qtest/qpdf/annotation-no-resources.pdf | 427 |
6 files changed, 828 insertions, 3 deletions
@@ -1,3 +1,8 @@ +2023-01-09 Jay Berkenbilt <ejb@ql.org> + + * Bug fix: flatten annotations should handle a page with no + /Resources key. Fixes #827. + 2022-11-20 Jay Berkenbilt <ejb@ql.org> * 11.2.0: release diff --git a/libqpdf/QPDFPageDocumentHelper.cc b/libqpdf/QPDFPageDocumentHelper.cc index 39b2800a..31d84e4b 100644 --- a/libqpdf/QPDFPageDocumentHelper.cc +++ b/libqpdf/QPDFPageDocumentHelper.cc @@ -67,9 +67,11 @@ QPDFPageDocumentHelper::flattenAnnotations( for (auto& ph: getAllPages()) { QPDFObjectHandle resources = ph.getAttribute("/Resources", true); if (!resources.isDictionary()) { - // This should never happen and is not exercised in the - // test suite - resources = QPDFObjectHandle::newDictionary(); + QTC::TC( + "qpdf", + "QPDFPageDocumentHelper flatten resources missing or invalid"); + resources = ph.getObjectHandle().replaceKeyAndGetNew( + "/Resources", QPDFObjectHandle::newDictionary()); } flattenAnnotationsForPage( ph, resources, afdh, required_flags, forbidden_flags); diff --git a/qpdf/qpdf.testcov b/qpdf/qpdf.testcov index 3cef71d2..7d8890e9 100644 --- a/qpdf/qpdf.testcov +++ b/qpdf/qpdf.testcov @@ -679,3 +679,4 @@ QPDFPageObjectHelper copied fallback 0 QPDFPageObjectHelper used fallback without copying 0 QPDF skipping cache for known unchecked object 0 QPDF fix dangling triggered xref reconstruction 0 +QPDFPageDocumentHelper flatten resources missing or invalid 0 diff --git a/qpdf/qtest/flatten-annotations.test b/qpdf/qtest/flatten-annotations.test index 5d071dba..91124c6c 100644 --- a/qpdf/qtest/flatten-annotations.test +++ b/qpdf/qtest/flatten-annotations.test @@ -55,6 +55,7 @@ my @annotation_files = ( 'sample-form', 'need-appearances', 'need-appearances-more', + 'annotation-no-resources', ); $n_tests += 2 * scalar(@annotation_files); diff --git a/qpdf/qtest/qpdf/annotation-no-resources-out.pdf b/qpdf/qtest/qpdf/annotation-no-resources-out.pdf new file mode 100644 index 00000000..0ce0cdce --- /dev/null +++ b/qpdf/qtest/qpdf/annotation-no-resources-out.pdf @@ -0,0 +1,389 @@ +%PDF-1.5 +%¿÷¢þ +%QDF-1.0 + +1 0 obj +<< + /Lang (en-US) + /MarkInfo << + /Marked true + >> + /OpenAction [ + 3 0 R + /XYZ + null + null + 0 + ] + /Pages 4 0 R + /StructTreeRoot 5 0 R + /Type /Catalog +>> +endobj + +2 0 obj +<< + /CreationDate (D:20181224113354-05'00') + /Creator <feff005700720069007400650072> + /Producer <feff004c0069006200720065004f0066006600690063006500200036002e0031> +>> +endobj + +%% Page 1 +3 0 obj +<< + /Contents [ + 6 0 R + 8 0 R + 10 0 R + ] + /Group << + /CS /DeviceRGB + /I true + /S /Transparency + >> + /MediaBox [ + 0 + 0 + 612 + 792 + ] + /Parent 4 0 R + /Resources << + /XObject << + /Fxo1 12 0 R + /Fxo2 14 0 R + /Fxo3 16 0 R + >> + >> + /StructParents 0 + /Type /Page +>> +endobj + +4 0 obj +<< + /Count 1 + /Kids [ + 3 0 R + ] + /Type /Pages +>> +endobj + +5 0 obj +<< + /K [ + 18 0 R + ] + /ParentTree 19 0 R + /RoleMap << + /Document /Document + /Standard /P + >> + /Type /StructTreeRoot +>> +endobj + +%% Contents for page 1 +6 0 obj +<< + /Length 7 0 R +>> +stream +q +endstream +endobj + +7 0 obj +2 +endobj + +%% Contents for page 1 +8 0 obj +<< + /Length 9 0 R +>> +stream +0.1 w +/Artifact BMC +q 0 0.028 611.971 791.971 re +W* n +EMC +/Form<</MCID 0>>BDC +0 0 0 RG +1 1 1 rg +127.35 648.65 72.3 55.95 re B* +EMC +/Form<</MCID 1>>BDC +127.35 540.25 108.45 58 re B* +EMC +/Form<</MCID 2>>BDC +291.65 427.75 77.8 103 re B* +EMC +Q +endstream +endobj + +%QDF: ignore_newline +9 0 obj +240 +endobj + +%% Contents for page 1 +10 0 obj +<< + /Length 11 0 R +>> +stream + +Q +q +1.00003 0 0 0.99996 129.849 651.151 cm +/Fxo1 Do +Q +q +1.00002 0 0 0.99996 129.849 542.751 cm +/Fxo2 Do +Q +q +1.00003 0 0 0.99998 294.149 430.251 cm +/Fxo3 Do +Q +endstream +endobj + +11 0 obj +159 +endobj + +12 0 obj +<< + /BBox [ + 0 + 0 + 67.3 + 50.95 + ] + /Resources << + /Font << + >> + /ProcSet [ + /PDF + /Text + ] + >> + /Subtype /Form + /Type /XObject + /Length 13 0 R +>> +stream +q +1 0 0 RG +5 w +0 0 67.3 50.95 re s +0 1 0 RG +5 5 15 15 re s +Q +endstream +endobj + +13 0 obj +61 +endobj + +14 0 obj +<< + /BBox [ + 0 + 0 + 103.45 + 53 + ] + /Resources << + /Font << + >> + /ProcSet [ + /PDF + /Text + ] + >> + /Subtype /Form + /Type /XObject + /Length 15 0 R +>> +stream +q +0 1 0 RG +5 w +0 0 103.45 53 re s +0 0 1 RG +5 5 15 15 re s +1 w +1 0 0 RG +-10 25 m +113.45 25 l +52 -10 m +52 63 l +s +Q +endstream +endobj + +15 0 obj +113 +endobj + +16 0 obj +<< + /BBox [ + 0 + 0 + 72.8 + 98 + ] + /Resources << + /Font << + >> + /ProcSet [ + /PDF + /Text + ] + >> + /Subtype /Form + /Type /XObject + /Length 17 0 R +>> +stream +q +0 0 1 RG +5 w +0 0 72.8 98 re s +1 0 0 RG +5 5 15 15 re s +Q +endstream +endobj + +17 0 obj +58 +endobj + +18 0 obj +<< + /K [ + 20 0 R + 21 0 R + 22 0 R + 23 0 R + ] + /P 5 0 R + /Pg 3 0 R + /S /Document + /Type /StructElem +>> +endobj + +19 0 obj +<< + /Nums [ + 0 + [ + 21 0 R + 22 0 R + 23 0 R + ] + ] +>> +endobj + +20 0 obj +<< + /A 24 0 R + /P 18 0 R + /Pg 3 0 R + /S /Standard + /Type /StructElem +>> +endobj + +21 0 obj +<< + /K [ + 0 + ] + /P 18 0 R + /Pg 3 0 R + /S /Form + /Type /StructElem +>> +endobj + +22 0 obj +<< + /K [ + 1 + ] + /P 18 0 R + /Pg 3 0 R + /S /Form + /Type /StructElem +>> +endobj + +23 0 obj +<< + /K [ + 2 + ] + /P 18 0 R + /Pg 3 0 R + /S /Form + /Type /StructElem +>> +endobj + +24 0 obj +<< + /O /Layout + /Placement /Block +>> +endobj + +xref +0 25 +0000000000 65535 f +0000000025 00000 n +0000000219 00000 n +0000000414 00000 n +0000000750 00000 n +0000000822 00000 n +0000000994 00000 n +0000001051 00000 n +0000001092 00000 n +0000001409 00000 n +0000001452 00000 n +0000001668 00000 n +0000001689 00000 n +0000001971 00000 n +0000001991 00000 n +0000002324 00000 n +0000002345 00000 n +0000002621 00000 n +0000002641 00000 n +0000002777 00000 n +0000002871 00000 n +0000002965 00000 n +0000003060 00000 n +0000003155 00000 n +0000003250 00000 n +trailer << + /DocChecksum /DA785F789D02970D387C264D0A6C8CB0 + /Info 2 0 R + /Root 1 0 R + /Size 25 + /ID [<976442cb303b8d5e88a36a127de2a19f><31415926535897932384626433832795>] +>> +startxref +3306 +%%EOF diff --git a/qpdf/qtest/qpdf/annotation-no-resources.pdf b/qpdf/qtest/qpdf/annotation-no-resources.pdf new file mode 100644 index 00000000..1281758f --- /dev/null +++ b/qpdf/qtest/qpdf/annotation-no-resources.pdf @@ -0,0 +1,427 @@ +%PDF-1.5 +%¿÷¢þ +%QDF-1.0 + +1 0 obj +<< + /AcroForm << + /DR 3 0 R + /Fields [ + 4 0 R + 5 0 R + 6 0 R + ] + /NeedAppearances false + >> + /Lang (en-US) + /MarkInfo << + /Marked true + >> + /OpenAction [ + 7 0 R + /XYZ + null + null + 0 + ] + /Pages 8 0 R + /StructTreeRoot 9 0 R + /Type /Catalog +>> +endobj + +2 0 obj +<< + /CreationDate (D:20181224113354-05'00') + /Creator <feff005700720069007400650072> + /Producer <feff004c0069006200720065004f0066006600690063006500200036002e0031> +>> +endobj + +3 0 obj +<< + /Font 10 0 R + /ProcSet [ + /PDF + /Text + ] +>> +endobj + +4 0 obj +<< + /AP << + /N 11 0 R + >> + /DA (0.18039 0.20392 0.21176 rg /F1 10 Tf) + /DR << + /Font 10 0 R + >> + /DV <feff> + /F 4 + /FT /Tx + /Ff 4096 + /P 7 0 R + /Rect [ + 129.849 + 651.151 + 197.151 + 702.099 + ] + /Subtype /Widget + /T (Text Box 1) + /Type /Annot + /V <feff> +>> +endobj + +5 0 obj +<< + /AP << + /N 13 0 R + >> + /DA (0.18039 0.20392 0.21176 rg /F1 10 Tf) + /DR << + /Font 10 0 R + >> + /DV <feff> + /F 4 + /FT /Tx + /Ff 4096 + /P 7 0 R + /Rect [ + 129.849 + 542.751 + 233.301 + 595.749 + ] + /Subtype /Widget + /T (Text Box 2) + /Type /Annot + /V <feff> +>> +endobj + +6 0 obj +<< + /AP << + /N 15 0 R + >> + /DA (0.18039 0.20392 0.21176 rg /F1 10 Tf) + /DR << + /Font 10 0 R + >> + /DV <feff> + /F 4 + /FT /Tx + /Ff 4096 + /P 7 0 R + /Rect [ + 294.149 + 430.251 + 366.951 + 528.249 + ] + /Subtype /Widget + /T (Text Box 3) + /Type /Annot + /V <feff> +>> +endobj + +%% Page 1 +7 0 obj +<< + /Annots [ + 4 0 R + 5 0 R + 6 0 R + ] + /Contents 17 0 R + /Group << + /CS /DeviceRGB + /I true + /S /Transparency + >> + /MediaBox [ + 0 + 0 + 612 + 792 + ] + /Parent 8 0 R + /StructParents 0 + /Type /Page +>> +endobj + +8 0 obj +<< + /Count 1 + /Kids [ + 7 0 R + ] + /Type /Pages +>> +endobj + +9 0 obj +<< + /K [ + 19 0 R + ] + /ParentTree 20 0 R + /RoleMap << + /Document /Document + /Standard /P + >> + /Type /StructTreeRoot +>> +endobj + +10 0 obj +<< +>> +endobj + +11 0 obj +<< + /BBox [ + 0 + 0 + 67.3 + 50.95 + ] + /Resources 3 0 R + /Subtype /Form + /Type /XObject + /Length 12 0 R +>> +stream +q +1 0 0 RG +5 w +0 0 67.3 50.95 re s +0 1 0 RG +5 5 15 15 re s +Q +endstream +endobj + +12 0 obj +61 +endobj + +13 0 obj +<< + /BBox [ + 0 + 0 + 103.45 + 53 + ] + /Resources 3 0 R + /Subtype /Form + /Type /XObject + /Length 14 0 R +>> +stream +q +0 1 0 RG +5 w +0 0 103.45 53 re s +0 0 1 RG +5 5 15 15 re s +1 w +1 0 0 RG +-10 25 m +113.45 25 l +52 -10 m +52 63 l +s +Q +endstream +endobj + +14 0 obj +113 +endobj + +15 0 obj +<< + /BBox [ + 0 + 0 + 72.8 + 98 + ] + /Resources 3 0 R + /Subtype /Form + /Type /XObject + /Length 16 0 R +>> +stream +q +0 0 1 RG +5 w +0 0 72.8 98 re s +1 0 0 RG +5 5 15 15 re s +Q +endstream +endobj + +16 0 obj +58 +endobj + +%% Contents for page 1 +17 0 obj +<< + /Length 18 0 R +>> +stream +0.1 w +/Artifact BMC +q 0 0.028 611.971 791.971 re +W* n +EMC +/Form<</MCID 0>>BDC +0 0 0 RG +1 1 1 rg +127.35 648.65 72.3 55.95 re B* +EMC +/Form<</MCID 1>>BDC +127.35 540.25 108.45 58 re B* +EMC +/Form<</MCID 2>>BDC +291.65 427.75 77.8 103 re B* +EMC +Q +endstream +endobj + +%QDF: ignore_newline +18 0 obj +240 +endobj + +19 0 obj +<< + /K [ + 21 0 R + 22 0 R + 23 0 R + 24 0 R + ] + /P 9 0 R + /Pg 7 0 R + /S /Document + /Type /StructElem +>> +endobj + +20 0 obj +<< + /Nums [ + 0 + [ + 22 0 R + 23 0 R + 24 0 R + ] + ] +>> +endobj + +21 0 obj +<< + /A 25 0 R + /P 19 0 R + /Pg 7 0 R + /S /Standard + /Type /StructElem +>> +endobj + +22 0 obj +<< + /K [ + 0 + ] + /P 19 0 R + /Pg 7 0 R + /S /Form + /Type /StructElem +>> +endobj + +23 0 obj +<< + /K [ + 1 + ] + /P 19 0 R + /Pg 7 0 R + /S /Form + /Type /StructElem +>> +endobj + +24 0 obj +<< + /K [ + 2 + ] + /P 19 0 R + /Pg 7 0 R + /S /Form + /Type /StructElem +>> +endobj + +25 0 obj +<< + /O /Layout + /Placement /Block +>> +endobj + +xref +0 26 +0000000000 65535 f +0000000025 00000 n +0000000336 00000 n +0000000521 00000 n +0000000594 00000 n +0000000898 00000 n +0000001202 00000 n +0000001516 00000 n +0000001767 00000 n +0000001839 00000 n +0000001988 00000 n +0000002011 00000 n +0000002227 00000 n +0000002247 00000 n +0000002514 00000 n +0000002535 00000 n +0000002745 00000 n +0000002788 00000 n +0000003107 00000 n +0000003128 00000 n +0000003264 00000 n +0000003358 00000 n +0000003452 00000 n +0000003547 00000 n +0000003642 00000 n +0000003737 00000 n +trailer << + /DocChecksum /DA785F789D02970D387C264D0A6C8CB0 + /Info 2 0 R + /Root 1 0 R + /Size 26 + /ID [<976442cb303b8d5e88a36a127de2a19f><ad9b3712a3de3e1f77381c0ef1d15737>] +>> +startxref +3793 +%%EOF |