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

This commit is contained in:
Jay Berkenbilt 2023-01-09 07:31:39 -05:00
parent 126b026937
commit e4e0f40fc0
6 changed files with 828 additions and 3 deletions

View File

@ -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

View File

@ -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);

View File

@ -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

View File

@ -55,6 +55,7 @@ my @annotation_files = (
'sample-form',
'need-appearances',
'need-appearances-more',
'annotation-no-resources',
);
$n_tests += 2 * scalar(@annotation_files);

View File

@ -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

View File

@ -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