Commit 4422588d7d51e226e6aeecfa9e53382aeb54d7c4

Authored by Jay Berkenbilt
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.
libqpdf/QPDF_Unresolved.cc
@@ -18,7 +18,7 @@ QPDF_Unresolved::shallowCopy() @@ -18,7 +18,7 @@ QPDF_Unresolved::shallowCopy()
18 { 18 {
19 throw std::logic_error( 19 throw std::logic_error(
20 "attempted to shallow copy unresolved QPDFObjectHandle"); 20 "attempted to shallow copy unresolved QPDFObjectHandle");
21 - return create(qpdf, og); 21 + return nullptr;
22 } 22 }
23 23
24 std::string 24 std::string
libqpdf/qpdf/QPDFValue.hh
@@ -24,22 +24,22 @@ class QPDFValue @@ -24,22 +24,22 @@ class QPDFValue
24 virtual std::string unparse() = 0; 24 virtual std::string unparse() = 0;
25 virtual JSON getJSON(int json_version) = 0; 25 virtual JSON getJSON(int json_version) = 0;
26 virtual void 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 object_description = description; 30 object_description = description;
31 } 31 }
32 bool 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 description = object_description; 36 description = object_description;
37 - return owning_qpdf != nullptr; 37 + return qpdf != nullptr;
38 } 38 }
39 bool 39 bool
40 hasDescription() 40 hasDescription()
41 { 41 {
42 - return owning_qpdf != nullptr; 42 + return qpdf != nullptr && !object_description.empty();
43 } 43 }
44 void 44 void
45 setParsedOffset(qpdf_offset_t offset) 45 setParsedOffset(qpdf_offset_t offset)
@@ -92,7 +92,6 @@ class QPDFValue @@ -92,7 +92,6 @@ class QPDFValue
92 private: 92 private:
93 QPDFValue(QPDFValue const&) = delete; 93 QPDFValue(QPDFValue const&) = delete;
94 QPDFValue& operator=(QPDFValue const&) = delete; 94 QPDFValue& operator=(QPDFValue const&) = delete;
95 - QPDF* owning_qpdf{nullptr};  
96 std::string object_description; 95 std::string object_description;
97 qpdf_offset_t parsed_offset{-1}; 96 qpdf_offset_t parsed_offset{-1};
98 const qpdf_object_type_e type_code; 97 const qpdf_object_type_e type_code;
libqpdf/qpdf/QPDFValueProxy.hh
@@ -49,7 +49,7 @@ class QPDFValueProxy @@ -49,7 +49,7 @@ class QPDFValueProxy
49 { 49 {
50 return value->type_name; 50 return value->type_name;
51 } 51 }
52 - // Returns nullptr for direct objects 52 +
53 QPDF* 53 QPDF*
54 getQPDF() const 54 getQPDF() const
55 { 55 {
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 WARNING: empty PDF: content normalization encountered bad tokens 3 WARNING: empty PDF: content normalization encountered bad tokens
3 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 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 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. 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,8 +1137,16 @@ test_29(QPDF& pdf, char const* arg2)
1137 assert(arg2 != 0); 1137 assert(arg2 != 0);
1138 QPDF other; 1138 QPDF other;
1139 other.processFile(arg2); 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 try { 1151 try {
1144 QPDFWriter w(other, "a.pdf"); 1152 QPDFWriter w(other, "a.pdf");