Commit 4422588d7d51e226e6aeecfa9e53382aeb54d7c4
1 parent
0132261e
Remove unneeded owning_qpdf from QPDFValue
The qpdf member was already sufficient. Removing this actually fixed a few pre-existing issues around detecting foreign ownership and allowing certain conditions to be warnings rather than exceptions.
Showing
5 changed files
with
20 additions
and
12 deletions
libqpdf/QPDF_Unresolved.cc
libqpdf/qpdf/QPDFValue.hh
| ... | ... | @@ -24,22 +24,22 @@ class QPDFValue |
| 24 | 24 | virtual std::string unparse() = 0; |
| 25 | 25 | virtual JSON getJSON(int json_version) = 0; |
| 26 | 26 | virtual void |
| 27 | - setDescription(QPDF* qpdf, std::string const& description) | |
| 27 | + setDescription(QPDF* qpdf_p, std::string const& description) | |
| 28 | 28 | { |
| 29 | - owning_qpdf = qpdf; | |
| 29 | + qpdf = qpdf_p; | |
| 30 | 30 | object_description = description; |
| 31 | 31 | } |
| 32 | 32 | bool |
| 33 | - getDescription(QPDF*& qpdf, std::string& description) | |
| 33 | + getDescription(QPDF*& qpdf_p, std::string& description) | |
| 34 | 34 | { |
| 35 | - qpdf = owning_qpdf; | |
| 35 | + qpdf_p = qpdf; | |
| 36 | 36 | description = object_description; |
| 37 | - return owning_qpdf != nullptr; | |
| 37 | + return qpdf != nullptr; | |
| 38 | 38 | } |
| 39 | 39 | bool |
| 40 | 40 | hasDescription() |
| 41 | 41 | { |
| 42 | - return owning_qpdf != nullptr; | |
| 42 | + return qpdf != nullptr && !object_description.empty(); | |
| 43 | 43 | } |
| 44 | 44 | void |
| 45 | 45 | setParsedOffset(qpdf_offset_t offset) |
| ... | ... | @@ -92,7 +92,6 @@ class QPDFValue |
| 92 | 92 | private: |
| 93 | 93 | QPDFValue(QPDFValue const&) = delete; |
| 94 | 94 | QPDFValue& operator=(QPDFValue const&) = delete; |
| 95 | - QPDF* owning_qpdf{nullptr}; | |
| 96 | 95 | std::string object_description; |
| 97 | 96 | qpdf_offset_t parsed_offset{-1}; |
| 98 | 97 | const qpdf_object_type_e type_code; | ... | ... |
libqpdf/qpdf/QPDFValueProxy.hh
qpdf/qtest/qpdf/split-tokens-split.out
| 1 | -WARNING: split-tokens.pdf, object 3 0 at offset 181: Unable to parse content stream: page object 3 0 stream 5 0, stream 7 0, stream 9 0, stream 11 0 (content, offset 375): null character not allowed in name token; not attempting to remove unreferenced objects from this object | |
| 1 | +WARNING: page object 3 0 stream 5 0, stream 7 0, stream 9 0, stream 11 0 (content, offset 375): null character not allowed in name token | |
| 2 | +WARNING: split-tokens.pdf, object 3 0 at offset 181: Bad token found while scanning content stream; not attempting to remove unreferenced objects from this object | |
| 2 | 3 | WARNING: empty PDF: content normalization encountered bad tokens |
| 3 | 4 | WARNING: empty PDF: normalized content ended with a bad token; you may be able to resolve this by coalescing content streams in combination with normalizing content. From the command line, specify --coalesce-contents |
| 4 | 5 | WARNING: empty PDF: Resulting stream data may be corrupted but is may still useful for manual inspection. For more information on this warning, search for content normalization in the manual. | ... | ... |
qpdf/test_driver.cc
| ... | ... | @@ -1137,8 +1137,16 @@ test_29(QPDF& pdf, char const* arg2) |
| 1137 | 1137 | assert(arg2 != 0); |
| 1138 | 1138 | QPDF other; |
| 1139 | 1139 | other.processFile(arg2); |
| 1140 | - // Should use copyForeignObject instead | |
| 1141 | - other.getTrailer().replaceKey("/QTest", pdf.getTrailer().getKey("/QTest")); | |
| 1140 | + // We need to create a QPDF with mixed ownership to exercise | |
| 1141 | + // QPDFWriter's ownership check. To do this, we have to sneak the | |
| 1142 | + // foreign object inside an ownerless direct object to avoid | |
| 1143 | + // detection prior to calling QPDFWriter. Maybe a future version | |
| 1144 | + // of qpdf will be able prevent creating mixed ownership. Another | |
| 1145 | + // way to fake it out would be to call setDescription to | |
| 1146 | + // explicitly change the ownership to the wrong value. | |
| 1147 | + auto dict = QPDFObjectHandle::newDictionary(); | |
| 1148 | + dict.replaceKey("/QTest", pdf.getTrailer().getKey("/QTest")); | |
| 1149 | + other.getTrailer().replaceKey("/QTest", dict); | |
| 1142 | 1150 | |
| 1143 | 1151 | try { |
| 1144 | 1152 | QPDFWriter w(other, "a.pdf"); | ... | ... |