Commit f08f3989200a532634ab5fa7d2b0e8ec6edba20b
1 parent
c76536dd
Test json v2 with invalid stream data
Showing
6 changed files
with
284 additions
and
5 deletions
TODO
| ... | ... | @@ -60,8 +60,6 @@ General things to remember: |
| 60 | 60 | when present in the schema. It's reasonable for people to check for |
| 61 | 61 | presence of a key. Most languages make this easy to do. |
| 62 | 62 | |
| 63 | -* Test stream with invalid data | |
| 64 | - | |
| 65 | 63 | * When we get to full serialization, add json serialization |
| 66 | 64 | performance test. |
| 67 | 65 | ... | ... |
qpdf/qtest/qpdf.test
| ... | ... | @@ -1110,7 +1110,7 @@ my @json_files = ( |
| 1110 | 1110 | ['V4-aes', ['--json-key=encrypt']], |
| 1111 | 1111 | ['V4-aes', ['--json-key=encrypt', '--show-encryption-key']], |
| 1112 | 1112 | ); |
| 1113 | -$n_tests += 2 * scalar(@json_files); | |
| 1113 | +$n_tests += 5 + (2 * scalar(@json_files)); | |
| 1114 | 1114 | foreach my $d (@json_files) |
| 1115 | 1115 | { |
| 1116 | 1116 | my ($file, $xargs) = @$d; |
| ... | ... | @@ -1134,7 +1134,8 @@ foreach my $d (@json_files) |
| 1134 | 1134 | my $in = "$file.pdf"; |
| 1135 | 1135 | $td->runtest("json v1 $out", |
| 1136 | 1136 | {$td->COMMAND => |
| 1137 | - ['qpdf', '--json=1', '--test-json-schema', @v1_xargs, $in]}, | |
| 1137 | + ['qpdf', '--json=1', '--test-json-schema', | |
| 1138 | + @v1_xargs, $in]}, | |
| 1138 | 1139 | {$td->FILE => "$out-v1.out", $td->EXIT_STATUS => 0}, |
| 1139 | 1140 | $td->NORMALIZE_NEWLINES); |
| 1140 | 1141 | $td->runtest("json v2 $out", |
| ... | ... | @@ -1144,6 +1145,31 @@ foreach my $d (@json_files) |
| 1144 | 1145 | $td->NORMALIZE_NEWLINES); |
| 1145 | 1146 | } |
| 1146 | 1147 | |
| 1148 | +$td->runtest("bad json stream data (inline)", | |
| 1149 | + {$td->COMMAND => | |
| 1150 | + "qpdf --json=2 --test-json-schema" . | |
| 1151 | + " --json-stream-data=inline bad-data.pdf > a.json"}, | |
| 1152 | + {$td->FILE => "bad-data-json.out", $td->EXIT_STATUS => 3}, | |
| 1153 | + $td->NORMALIZE_NEWLINES); | |
| 1154 | +$td->runtest("check (inline)", | |
| 1155 | + {$td->FILE => "a.json"}, | |
| 1156 | + {$td->FILE => "json-bad-data-json-inline-v2.out"}, | |
| 1157 | + $td->NORMALIZE_NEWLINES); | |
| 1158 | +$td->runtest("bad json stream data (file)", | |
| 1159 | + {$td->COMMAND => | |
| 1160 | + "qpdf --json=2 --test-json-schema" . | |
| 1161 | + " --json-stream-data=file --json-stream-prefix=auto" . | |
| 1162 | + " bad-data.pdf > a.json"}, | |
| 1163 | + {$td->FILE => "bad-data-json.out", $td->EXIT_STATUS => 3}, | |
| 1164 | + $td->NORMALIZE_NEWLINES); | |
| 1165 | +$td->runtest("check (file)", | |
| 1166 | + {$td->FILE => "a.json"}, | |
| 1167 | + {$td->FILE => "json-bad-data-json-file-v2.out"}, | |
| 1168 | + $td->NORMALIZE_NEWLINES); | |
| 1169 | +$td->runtest("check stream (file)", | |
| 1170 | + {$td->FILE => "auto-4"}, | |
| 1171 | + {$td->FILE => "bad-data-4.out"}); | |
| 1172 | + | |
| 1147 | 1173 | show_ntests(); |
| 1148 | 1174 | # ---------- |
| 1149 | 1175 | $td->notify("--- Page API Tests ---"); |
| ... | ... | @@ -5778,6 +5804,6 @@ sub get_md5_checksum |
| 5778 | 5804 | |
| 5779 | 5805 | sub cleanup |
| 5780 | 5806 | { |
| 5781 | - system("rm -rf *.ps *.pnm ?.pdf ?.qdf *.enc* tif1 tif2 tiff-cache"); | |
| 5807 | + system("rm -rf a.json *.ps *.pnm ?.pdf ?.qdf *.enc* tif1 tif2 tiff-cache"); | |
| 5782 | 5808 | system("rm -rf *split-out* ???-kfo.pdf *.tmpout \@file.pdf auto-*"); |
| 5783 | 5809 | } | ... | ... |
qpdf/qtest/qpdf/bad-data-4.out
0 โ 100644
No preview for this file type
qpdf/qtest/qpdf/bad-data-json.out
0 โ 100644
qpdf/qtest/qpdf/json-bad-data-json-file-v2.out
0 โ 100644
| 1 | +{ | |
| 2 | + "version": 2, | |
| 3 | + "parameters": { | |
| 4 | + "decodelevel": "generalized" | |
| 5 | + }, | |
| 6 | + "pages": [ | |
| 7 | + { | |
| 8 | + "contents": [ | |
| 9 | + "4 0 R" | |
| 10 | + ], | |
| 11 | + "images": [], | |
| 12 | + "label": null, | |
| 13 | + "object": "3 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 | + "encrypt": { | |
| 26 | + "capabilities": { | |
| 27 | + "accessibility": true, | |
| 28 | + "extract": true, | |
| 29 | + "modify": true, | |
| 30 | + "modifyannotations": true, | |
| 31 | + "modifyassembly": true, | |
| 32 | + "modifyforms": true, | |
| 33 | + "modifyother": true, | |
| 34 | + "printhigh": true, | |
| 35 | + "printlow": true | |
| 36 | + }, | |
| 37 | + "encrypted": false, | |
| 38 | + "ownerpasswordmatched": false, | |
| 39 | + "parameters": { | |
| 40 | + "P": 0, | |
| 41 | + "R": 0, | |
| 42 | + "V": 0, | |
| 43 | + "bits": 0, | |
| 44 | + "filemethod": "none", | |
| 45 | + "key": null, | |
| 46 | + "method": "none", | |
| 47 | + "streammethod": "none", | |
| 48 | + "stringmethod": "none" | |
| 49 | + }, | |
| 50 | + "userpasswordmatched": false | |
| 51 | + }, | |
| 52 | + "outlines": [], | |
| 53 | + "qpdf": { | |
| 54 | + "jsonversion": 2, | |
| 55 | + "pdfversion": "1.3", | |
| 56 | + "objects": { | |
| 57 | + "obj:1 0 R": { | |
| 58 | + "value": { | |
| 59 | + "/Pages": "2 0 R", | |
| 60 | + "/Type": "/Catalog" | |
| 61 | + } | |
| 62 | + }, | |
| 63 | + "obj:2 0 R": { | |
| 64 | + "value": { | |
| 65 | + "/Count": 1, | |
| 66 | + "/Kids": [ | |
| 67 | + "3 0 R" | |
| 68 | + ], | |
| 69 | + "/Type": "/Pages" | |
| 70 | + } | |
| 71 | + }, | |
| 72 | + "obj:3 0 R": { | |
| 73 | + "value": { | |
| 74 | + "/Contents": "4 0 R", | |
| 75 | + "/MediaBox": [ | |
| 76 | + 0, | |
| 77 | + 0, | |
| 78 | + 612, | |
| 79 | + 792 | |
| 80 | + ], | |
| 81 | + "/Parent": "2 0 R", | |
| 82 | + "/Resources": { | |
| 83 | + "/Font": { | |
| 84 | + "/F1": "5 0 R" | |
| 85 | + }, | |
| 86 | + "/ProcSet": "6 0 R" | |
| 87 | + }, | |
| 88 | + "/Type": "/Page" | |
| 89 | + } | |
| 90 | + }, | |
| 91 | + "obj:4 0 R": { | |
| 92 | + "stream": { | |
| 93 | + "datafile": "auto-4", | |
| 94 | + "dict": { | |
| 95 | + "/Filter": "/LZWDecode" | |
| 96 | + } | |
| 97 | + } | |
| 98 | + }, | |
| 99 | + "obj:5 0 R": { | |
| 100 | + "value": { | |
| 101 | + "/BaseFont": "/Helvetica", | |
| 102 | + "/Encoding": "/WinAnsiEncoding", | |
| 103 | + "/Name": "/F1", | |
| 104 | + "/Subtype": "/Type1", | |
| 105 | + "/Type": "/Font" | |
| 106 | + } | |
| 107 | + }, | |
| 108 | + "obj:6 0 R": { | |
| 109 | + "value": [ | |
| 110 | + "/PDF", | |
| 111 | + "/Text" | |
| 112 | + ] | |
| 113 | + }, | |
| 114 | + "trailer": { | |
| 115 | + "value": { | |
| 116 | + "/ID": [ | |
| 117 | + "b:4a5e383aee3970ed44eb87234d7f93f1", | |
| 118 | + "b:4a5e383aee3970ed44eb87234d7f93f1" | |
| 119 | + ], | |
| 120 | + "/Root": "1 0 R", | |
| 121 | + "/Size": 7 | |
| 122 | + } | |
| 123 | + } | |
| 124 | + } | |
| 125 | + } | |
| 126 | +} | ... | ... |
qpdf/qtest/qpdf/json-bad-data-json-inline-v2.out
0 โ 100644
| 1 | +{ | |
| 2 | + "version": 2, | |
| 3 | + "parameters": { | |
| 4 | + "decodelevel": "generalized" | |
| 5 | + }, | |
| 6 | + "pages": [ | |
| 7 | + { | |
| 8 | + "contents": [ | |
| 9 | + "4 0 R" | |
| 10 | + ], | |
| 11 | + "images": [], | |
| 12 | + "label": null, | |
| 13 | + "object": "3 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 | + "encrypt": { | |
| 26 | + "capabilities": { | |
| 27 | + "accessibility": true, | |
| 28 | + "extract": true, | |
| 29 | + "modify": true, | |
| 30 | + "modifyannotations": true, | |
| 31 | + "modifyassembly": true, | |
| 32 | + "modifyforms": true, | |
| 33 | + "modifyother": true, | |
| 34 | + "printhigh": true, | |
| 35 | + "printlow": true | |
| 36 | + }, | |
| 37 | + "encrypted": false, | |
| 38 | + "ownerpasswordmatched": false, | |
| 39 | + "parameters": { | |
| 40 | + "P": 0, | |
| 41 | + "R": 0, | |
| 42 | + "V": 0, | |
| 43 | + "bits": 0, | |
| 44 | + "filemethod": "none", | |
| 45 | + "key": null, | |
| 46 | + "method": "none", | |
| 47 | + "streammethod": "none", | |
| 48 | + "stringmethod": "none" | |
| 49 | + }, | |
| 50 | + "userpasswordmatched": false | |
| 51 | + }, | |
| 52 | + "outlines": [], | |
| 53 | + "qpdf": { | |
| 54 | + "jsonversion": 2, | |
| 55 | + "pdfversion": "1.3", | |
| 56 | + "objects": { | |
| 57 | + "obj:1 0 R": { | |
| 58 | + "value": { | |
| 59 | + "/Pages": "2 0 R", | |
| 60 | + "/Type": "/Catalog" | |
| 61 | + } | |
| 62 | + }, | |
| 63 | + "obj:2 0 R": { | |
| 64 | + "value": { | |
| 65 | + "/Count": 1, | |
| 66 | + "/Kids": [ | |
| 67 | + "3 0 R" | |
| 68 | + ], | |
| 69 | + "/Type": "/Pages" | |
| 70 | + } | |
| 71 | + }, | |
| 72 | + "obj:3 0 R": { | |
| 73 | + "value": { | |
| 74 | + "/Contents": "4 0 R", | |
| 75 | + "/MediaBox": [ | |
| 76 | + 0, | |
| 77 | + 0, | |
| 78 | + 612, | |
| 79 | + 792 | |
| 80 | + ], | |
| 81 | + "/Parent": "2 0 R", | |
| 82 | + "/Resources": { | |
| 83 | + "/Font": { | |
| 84 | + "/F1": "5 0 R" | |
| 85 | + }, | |
| 86 | + "/ProcSet": "6 0 R" | |
| 87 | + }, | |
| 88 | + "/Type": "/Page" | |
| 89 | + } | |
| 90 | + }, | |
| 91 | + "obj:4 0 R": { | |
| 92 | + "stream": { | |
| 93 | + "data": "eJxzCuFSUNB3M1QwMlEISQOyzY2AyEAhJAXI1gjIL0ksyddUCMnicg3hAgDLAQnI", | |
| 94 | + "dict": { | |
| 95 | + "/Filter": "/LZWDecode" | |
| 96 | + } | |
| 97 | + } | |
| 98 | + }, | |
| 99 | + "obj:5 0 R": { | |
| 100 | + "value": { | |
| 101 | + "/BaseFont": "/Helvetica", | |
| 102 | + "/Encoding": "/WinAnsiEncoding", | |
| 103 | + "/Name": "/F1", | |
| 104 | + "/Subtype": "/Type1", | |
| 105 | + "/Type": "/Font" | |
| 106 | + } | |
| 107 | + }, | |
| 108 | + "obj:6 0 R": { | |
| 109 | + "value": [ | |
| 110 | + "/PDF", | |
| 111 | + "/Text" | |
| 112 | + ] | |
| 113 | + }, | |
| 114 | + "trailer": { | |
| 115 | + "value": { | |
| 116 | + "/ID": [ | |
| 117 | + "b:4a5e383aee3970ed44eb87234d7f93f1", | |
| 118 | + "b:4a5e383aee3970ed44eb87234d7f93f1" | |
| 119 | + ], | |
| 120 | + "/Root": "1 0 R", | |
| 121 | + "/Size": 7 | |
| 122 | + } | |
| 123 | + } | |
| 124 | + } | |
| 125 | + } | |
| 126 | +} | ... | ... |