Commit d3c444a7fb7ef62d44633cba4ab433348bc27943
Committed by
GitHub
Merge pull request #980 from m-holger/readobject
Avoid unnecessary copying of stream dictionary in QPDF::readObject
Showing
5 changed files
with
21 additions
and
26 deletions
libqpdf/QPDF.cc
| ... | ... | @@ -1343,21 +1343,16 @@ QPDF::readObject( |
| 1343 | 1343 | size_t length = 0; |
| 1344 | 1344 | |
| 1345 | 1345 | try { |
| 1346 | - std::map<std::string, QPDFObjectHandle> dict = object.getDictAsMap(); | |
| 1346 | + auto length_obj = object.getKey("/Length"); | |
| 1347 | 1347 | |
| 1348 | - if (dict.count("/Length") == 0) { | |
| 1349 | - QTC::TC("qpdf", "QPDF stream without length"); | |
| 1350 | - throw damagedPDF(input, offset, "stream dictionary lacks /Length key"); | |
| 1351 | - } | |
| 1352 | - | |
| 1353 | - QPDFObjectHandle length_obj = dict["/Length"]; | |
| 1354 | 1348 | if (!length_obj.isInteger()) { |
| 1349 | + if (length_obj.isNull()) { | |
| 1350 | + QTC::TC("qpdf", "QPDF stream without length"); | |
| 1351 | + throw damagedPDF(input, offset, "stream dictionary lacks /Length key"); | |
| 1352 | + } | |
| 1355 | 1353 | QTC::TC("qpdf", "QPDF stream length not integer"); |
| 1356 | 1354 | throw damagedPDF( |
| 1357 | - input, | |
| 1358 | - offset, | |
| 1359 | - "/Length key in stream dictionary is not " | |
| 1360 | - "an integer"); | |
| 1355 | + input, offset, "/Length key in stream dictionary is not an integer"); | |
| 1361 | 1356 | } |
| 1362 | 1357 | |
| 1363 | 1358 | length = toS(length_obj.getUIntValue()); | ... | ... |
qpdf/qtest/qpdf/issue-100.out
| ... | ... | @@ -9,7 +9,7 @@ WARNING: issue-100.pdf (object 5 0, offset 297): unknown token while reading obj |
| 9 | 9 | WARNING: issue-100.pdf (object 5 0, offset 304): unknown token while reading object; treating as string |
| 10 | 10 | WARNING: issue-100.pdf (object 5 0, offset 304): too many errors; giving up on reading object |
| 11 | 11 | WARNING: issue-100.pdf (object 5 0, offset 308): expected endobj |
| 12 | -WARNING: issue-100.pdf (object 5 0, offset 418): /Length key in stream dictionary is not an integer | |
| 12 | +WARNING: issue-100.pdf (object 5 0, offset 418): stream dictionary lacks /Length key | |
| 13 | 13 | WARNING: issue-100.pdf (object 5 0, offset 489): attempting to recover stream length |
| 14 | 14 | WARNING: issue-100.pdf (object 5 0, offset 489): recovered stream length: 12 |
| 15 | 15 | WARNING: issue-100.pdf (trailer, offset 953): expected dictionary key but found non-name object; inserting key /QPDFFake1 | ... | ... |
qpdf/qtest/qpdf/issue-117.out
| ... | ... | @@ -2,7 +2,7 @@ WARNING: issue-117.pdf: file is damaged |
| 2 | 2 | WARNING: issue-117.pdf (offset 3526): xref not found |
| 3 | 3 | WARNING: issue-117.pdf: Attempting to reconstruct cross-reference table |
| 4 | 4 | WARNING: issue-117.pdf (offset 66): loop detected resolving object 2 0 |
| 5 | -WARNING: issue-117.pdf (object 2 0, offset 22): /Length key in stream dictionary is not an integer | |
| 5 | +WARNING: issue-117.pdf (object 2 0, offset 22): stream dictionary lacks /Length key | |
| 6 | 6 | WARNING: issue-117.pdf (object 2 0, offset 67): attempting to recover stream length |
| 7 | 7 | WARNING: issue-117.pdf (object 2 0, offset 67): recovered stream length: 91 |
| 8 | 8 | WARNING: issue-117.pdf (object 5 0, offset 1559): expected endstream | ... | ... |
qpdf/qtest/qpdf/issue-335a.out
| ... | ... | @@ -1019,22 +1019,22 @@ WARNING: issue-335a.pdf (trailer, offset 20748): stream keyword followed by extr |
| 1019 | 1019 | WARNING: issue-335a.pdf (trailer, offset 20679): stream dictionary lacks /Length key |
| 1020 | 1020 | WARNING: issue-335a.pdf (trailer, offset 20749): attempting to recover stream length |
| 1021 | 1021 | WARNING: issue-335a.pdf (trailer, offset 20749): unable to recover stream data; treating stream as empty |
| 1022 | -WARNING: issue-335a.pdf (trailer, offset 20756): /Length key in stream dictionary is not an integer | |
| 1022 | +WARNING: issue-335a.pdf (trailer, offset 20756): stream dictionary lacks /Length key | |
| 1023 | 1023 | WARNING: issue-335a.pdf (trailer, offset 20787): attempting to recover stream length |
| 1024 | 1024 | WARNING: issue-335a.pdf (trailer, offset 20787): unable to recover stream data; treating stream as empty |
| 1025 | 1025 | WARNING: issue-335a.pdf (trailer, offset 20812): unknown token while reading object; treating as string |
| 1026 | 1026 | WARNING: issue-335a.pdf (trailer, offset 20803): expected dictionary key but found non-name object; inserting key /QPDFFake1 |
| 1027 | 1027 | WARNING: issue-335a.pdf (trailer, offset 20803): dictionary has duplicated key /Length; last occurrence overrides earlier ones |
| 1028 | 1028 | WARNING: issue-335a.pdf (trailer, offset 20843): stream keyword followed by extraneous whitespace |
| 1029 | -WARNING: issue-335a.pdf (trailer, offset 20800): /Length key in stream dictionary is not an integer | |
| 1029 | +WARNING: issue-335a.pdf (trailer, offset 20800): stream dictionary lacks /Length key | |
| 1030 | 1030 | WARNING: issue-335a.pdf (trailer, offset 20844): attempting to recover stream length |
| 1031 | 1031 | WARNING: issue-335a.pdf (trailer, offset 20844): unable to recover stream data; treating stream as empty |
| 1032 | -WARNING: issue-335a.pdf (trailer, offset 20851): /Length key in stream dictionary is not an integer | |
| 1032 | +WARNING: issue-335a.pdf (trailer, offset 20851): stream dictionary lacks /Length key | |
| 1033 | 1033 | WARNING: issue-335a.pdf (trailer, offset 20882): attempting to recover stream length |
| 1034 | 1034 | WARNING: issue-335a.pdf (trailer, offset 20882): unable to recover stream data; treating stream as empty |
| 1035 | 1035 | WARNING: issue-335a.pdf (trailer, offset 20914): unknown token while reading object; treating as string |
| 1036 | 1036 | WARNING: issue-335a.pdf (trailer, offset 20898): expected dictionary key but found non-name object; inserting key /QPDFFake1 |
| 1037 | -WARNING: issue-335a.pdf (trailer, offset 20895): /Length key in stream dictionary is not an integer | |
| 1037 | +WARNING: issue-335a.pdf (trailer, offset 20895): stream dictionary lacks /Length key | |
| 1038 | 1038 | WARNING: issue-335a.pdf (trailer, offset 20929): attempting to recover stream length |
| 1039 | 1039 | WARNING: issue-335a.pdf (trailer, offset 20929): unable to recover stream data; treating stream as empty |
| 1040 | 1040 | WARNING: issue-335a.pdf (trailer, offset 20949): unexpected > |
| ... | ... | @@ -1047,7 +1047,7 @@ WARNING: issue-335a.pdf (trailer, offset 20973): unexpected ) |
| 1047 | 1047 | WARNING: issue-335a.pdf (trailer, offset 20973): too many errors; giving up on reading object |
| 1048 | 1048 | WARNING: issue-335a.pdf (trailer, offset 21042): unknown token while reading object; treating as string |
| 1049 | 1049 | WARNING: issue-335a.pdf (trailer, offset 21026): expected dictionary key but found non-name object; inserting key /QPDFFake1 |
| 1050 | -WARNING: issue-335a.pdf (trailer, offset 21023): /Length key in stream dictionary is not an integer | |
| 1050 | +WARNING: issue-335a.pdf (trailer, offset 21023): stream dictionary lacks /Length key | |
| 1051 | 1051 | WARNING: issue-335a.pdf (trailer, offset 21057): attempting to recover stream length |
| 1052 | 1052 | WARNING: issue-335a.pdf (trailer, offset 21057): unable to recover stream data; treating stream as empty |
| 1053 | 1053 | WARNING: issue-335a.pdf (trailer, offset 21077): unexpected > |
| ... | ... | @@ -1116,7 +1116,7 @@ WARNING: issue-335a.pdf (trailer, offset 21444): unknown token while reading obj |
| 1116 | 1116 | WARNING: issue-335a.pdf (trailer, offset 21452): invalid character (-) in hexstring |
| 1117 | 1117 | WARNING: issue-335a.pdf (trailer, offset 21819): unknown token while reading object; treating as string |
| 1118 | 1118 | WARNING: issue-335a.pdf (trailer, offset 21819): too many errors; giving up on reading object |
| 1119 | -WARNING: issue-335a.pdf (trailer, offset 21407): /Length key in stream dictionary is not an integer | |
| 1119 | +WARNING: issue-335a.pdf (trailer, offset 21407): stream dictionary lacks /Length key | |
| 1120 | 1120 | WARNING: issue-335a.pdf (trailer, offset 21438): attempting to recover stream length |
| 1121 | 1121 | WARNING: issue-335a.pdf (trailer, offset 21438): unable to recover stream data; treating stream as empty |
| 1122 | 1122 | WARNING: issue-335a.pdf (trailer, offset 21452): invalid character (-) in hexstring |
| ... | ... | @@ -1171,13 +1171,13 @@ WARNING: issue-335a.pdf (trailer, offset 21936): dictionary has duplicated key / |
| 1171 | 1171 | WARNING: issue-335a.pdf (trailer, offset 21936): expected dictionary key but found non-name object; inserting key /QPDFFake7 |
| 1172 | 1172 | WARNING: issue-335a.pdf (trailer, offset 21936): expected dictionary key but found non-name object; inserting key /QPDFFake8 |
| 1173 | 1173 | WARNING: issue-335a.pdf (trailer, offset 21936): expected dictionary key but found non-name object; inserting key /QPDFFake9 |
| 1174 | -WARNING: issue-335a.pdf (trailer, offset 21932): /Length key in stream dictionary is not an integer | |
| 1174 | +WARNING: issue-335a.pdf (trailer, offset 21932): stream dictionary lacks /Length key | |
| 1175 | 1175 | WARNING: issue-335a.pdf (trailer, offset 22052): attempting to recover stream length |
| 1176 | 1176 | WARNING: issue-335a.pdf (trailer, offset 22052): unable to recover stream data; treating stream as empty |
| 1177 | 1177 | WARNING: issue-335a.pdf (trailer, offset 22000): invalid character (t) in hexstring |
| 1178 | 1178 | WARNING: issue-335a.pdf (trailer, offset 22088): unknown token while reading object; treating as string |
| 1179 | 1179 | WARNING: issue-335a.pdf (trailer, offset 22087): expected dictionary key but found non-name object; inserting key /QPDFFake1 |
| 1180 | -WARNING: issue-335a.pdf (trailer, offset 22083): /Length key in stream dictionary is not an integer | |
| 1180 | +WARNING: issue-335a.pdf (trailer, offset 22083): stream dictionary lacks /Length key | |
| 1181 | 1181 | WARNING: issue-335a.pdf (trailer, offset 22136): attempting to recover stream length |
| 1182 | 1182 | WARNING: issue-335a.pdf (trailer, offset 22136): unable to recover stream data; treating stream as empty |
| 1183 | 1183 | WARNING: issue-335a.pdf (trailer, offset 22178): unknown token while reading object; treating as string |
| ... | ... | @@ -1194,7 +1194,7 @@ WARNING: issue-335a.pdf (trailer, offset 22177): expected dictionary key but fou |
| 1194 | 1194 | WARNING: issue-335a.pdf (trailer, offset 22177): expected dictionary key but found non-name object; inserting key /QPDFFake4 |
| 1195 | 1195 | WARNING: issue-335a.pdf (trailer, offset 22177): expected dictionary key but found non-name object; inserting key /QPDFFake5 |
| 1196 | 1196 | WARNING: issue-335a.pdf (trailer, offset 22276): stream keyword followed by carriage return only |
| 1197 | -WARNING: issue-335a.pdf (trailer, offset 22173): /Length key in stream dictionary is not an integer | |
| 1197 | +WARNING: issue-335a.pdf (trailer, offset 22173): stream dictionary lacks /Length key | |
| 1198 | 1198 | WARNING: issue-335a.pdf (trailer, offset 22276): attempting to recover stream length |
| 1199 | 1199 | WARNING: issue-335a.pdf (trailer, offset 22276): unable to recover stream data; treating stream as empty |
| 1200 | 1200 | WARNING: issue-335a.pdf (trailer, offset 22202): unknown token while reading object; treating as string |
| ... | ... | @@ -1219,7 +1219,7 @@ WARNING: issue-335a.pdf (trailer, offset 22373): attempting to recover stream le |
| 1219 | 1219 | WARNING: issue-335a.pdf (trailer, offset 22373): unable to recover stream data; treating stream as empty |
| 1220 | 1220 | WARNING: issue-335a.pdf (trailer, offset 22437): unknown token while reading object; treating as string |
| 1221 | 1221 | WARNING: issue-335a.pdf (trailer, offset 22436): expected dictionary key but found non-name object; inserting key /QPDFFake1 |
| 1222 | -WARNING: issue-335a.pdf (trailer, offset 22432): /Length key in stream dictionary is not an integer | |
| 1222 | +WARNING: issue-335a.pdf (trailer, offset 22432): stream dictionary lacks /Length key | |
| 1223 | 1223 | WARNING: issue-335a.pdf (trailer, offset 22484): attempting to recover stream length |
| 1224 | 1224 | WARNING: issue-335a.pdf (trailer, offset 22484): unable to recover stream data; treating stream as empty |
| 1225 | 1225 | WARNING: issue-335a.pdf (trailer, offset 22650): unknown token while reading object; treating as string |
| ... | ... | @@ -1278,7 +1278,7 @@ WARNING: issue-335a.pdf (trailer, offset 22817): attempting to recover stream le |
| 1278 | 1278 | WARNING: issue-335a.pdf (trailer, offset 22817): unable to recover stream data; treating stream as empty |
| 1279 | 1279 | WARNING: issue-335a.pdf (trailer, offset 22702): unknown token while reading object; treating as string |
| 1280 | 1280 | WARNING: issue-335a.pdf (trailer, offset 22701): expected dictionary key but found non-name object; inserting key /QPDFFake1 |
| 1281 | -WARNING: issue-335a.pdf (trailer, offset 22697): /Length key in stream dictionary is not an integer | |
| 1281 | +WARNING: issue-335a.pdf (trailer, offset 22697): stream dictionary lacks /Length key | |
| 1282 | 1282 | WARNING: issue-335a.pdf (trailer, offset 22748): attempting to recover stream length |
| 1283 | 1283 | WARNING: issue-335a.pdf (trailer, offset 22748): unable to recover stream data; treating stream as empty |
| 1284 | 1284 | WARNING: issue-335a.pdf (trailer, offset 22845): unknown token while reading object; treating as string |
| ... | ... | @@ -1308,7 +1308,7 @@ WARNING: issue-335a.pdf (object 5 0, offset 23451): invalid character (ÿ) in hex |
| 1308 | 1308 | WARNING: issue-335a.pdf (object 5 0, offset 23458): unknown token while reading object; treating as string |
| 1309 | 1309 | WARNING: issue-335a.pdf (object 5 0, offset 23444): expected dictionary key but found non-name object; inserting key /QPDFFake1 |
| 1310 | 1310 | WARNING: issue-335a.pdf (object 5 0, offset 23444): expected dictionary key but found non-name object; inserting key /QPDFFake2 |
| 1311 | -WARNING: issue-335a.pdf (object 5 0, offset 23440): /Length key in stream dictionary is not an integer | |
| 1311 | +WARNING: issue-335a.pdf (object 5 0, offset 23440): stream dictionary lacks /Length key | |
| 1312 | 1312 | WARNING: issue-335a.pdf (object 5 0, offset 23485): attempting to recover stream length |
| 1313 | 1313 | WARNING: issue-335a.pdf (object 5 0, offset 23485): unable to recover stream data; treating stream as empty |
| 1314 | 1314 | WARNING: issue-335a.pdf (object 5 0, offset 24974): expected endobj | ... | ... |
qpdf/qtest/qpdf/issue-51.out
| ... | ... | @@ -5,7 +5,7 @@ WARNING: issue-51.pdf (object 7 0, offset 553): expected endobj |
| 5 | 5 | WARNING: issue-51.pdf (object 1 0, offset 236): dictionary has duplicated key /00000000; last occurrence overrides earlier ones |
| 6 | 6 | WARNING: issue-51.pdf (object 1 0, offset 359): expected endobj |
| 7 | 7 | WARNING: issue-51.pdf (offset 70): loop detected resolving object 2 0 |
| 8 | -WARNING: issue-51.pdf (object 2 0, offset 26): /Length key in stream dictionary is not an integer | |
| 8 | +WARNING: issue-51.pdf (object 2 0, offset 26): stream dictionary lacks /Length key | |
| 9 | 9 | WARNING: issue-51.pdf (object 2 0, offset 71): attempting to recover stream length |
| 10 | 10 | WARNING: issue-51.pdf (object 2 0, offset 71): unable to recover stream data; treating stream as empty |
| 11 | 11 | WARNING: issue-51.pdf (object 2 0, offset 977): expected endobj | ... | ... |