2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-12-22 19:08:59 +00:00

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.
This commit is contained in:
Jay Berkenbilt 2022-09-07 14:11:24 -04:00
parent 0132261ee0
commit 4422588d7d
5 changed files with 20 additions and 12 deletions

View File

@ -18,7 +18,7 @@ QPDF_Unresolved::shallowCopy()
{
throw std::logic_error(
"attempted to shallow copy unresolved QPDFObjectHandle");
return create(qpdf, og);
return nullptr;
}
std::string

View File

@ -24,22 +24,22 @@ class QPDFValue
virtual std::string unparse() = 0;
virtual JSON getJSON(int json_version) = 0;
virtual void
setDescription(QPDF* qpdf, std::string const& description)
setDescription(QPDF* qpdf_p, std::string const& description)
{
owning_qpdf = qpdf;
qpdf = qpdf_p;
object_description = description;
}
bool
getDescription(QPDF*& qpdf, std::string& description)
getDescription(QPDF*& qpdf_p, std::string& description)
{
qpdf = owning_qpdf;
qpdf_p = qpdf;
description = object_description;
return owning_qpdf != nullptr;
return qpdf != nullptr;
}
bool
hasDescription()
{
return owning_qpdf != nullptr;
return qpdf != nullptr && !object_description.empty();
}
void
setParsedOffset(qpdf_offset_t offset)
@ -92,7 +92,6 @@ class QPDFValue
private:
QPDFValue(QPDFValue const&) = delete;
QPDFValue& operator=(QPDFValue const&) = delete;
QPDF* owning_qpdf{nullptr};
std::string object_description;
qpdf_offset_t parsed_offset{-1};
const qpdf_object_type_e type_code;

View File

@ -49,7 +49,7 @@ class QPDFValueProxy
{
return value->type_name;
}
// Returns nullptr for direct objects
QPDF*
getQPDF() const
{

View File

@ -1,4 +1,5 @@
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
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
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
WARNING: empty PDF: content normalization encountered bad tokens
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
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.

View File

@ -1137,8 +1137,16 @@ test_29(QPDF& pdf, char const* arg2)
assert(arg2 != 0);
QPDF other;
other.processFile(arg2);
// Should use copyForeignObject instead
other.getTrailer().replaceKey("/QTest", pdf.getTrailer().getKey("/QTest"));
// We need to create a QPDF with mixed ownership to exercise
// QPDFWriter's ownership check. To do this, we have to sneak the
// foreign object inside an ownerless direct object to avoid
// detection prior to calling QPDFWriter. Maybe a future version
// of qpdf will be able prevent creating mixed ownership. Another
// way to fake it out would be to call setDescription to
// explicitly change the ownership to the wrong value.
auto dict = QPDFObjectHandle::newDictionary();
dict.replaceKey("/QTest", pdf.getTrailer().getKey("/QTest"));
other.getTrailer().replaceKey("/QTest", dict);
try {
QPDFWriter w(other, "a.pdf");