2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-12-23 03:18:59 +00:00

Change object variable in QPDFParser::parse to shared_ptr<QPDFObject>

This commit is contained in:
m-holger 2022-12-19 10:50:46 +00:00 committed by Jay Berkenbilt
parent ec35156ab0
commit e91e642cf3

View File

@ -4,9 +4,24 @@
#include <qpdf/QPDFObjGen.hh> #include <qpdf/QPDFObjGen.hh>
#include <qpdf/QPDFObjectHandle.hh> #include <qpdf/QPDFObjectHandle.hh>
#include <qpdf/QPDFObject_private.hh> #include <qpdf/QPDFObject_private.hh>
#include <qpdf/QPDF_Array.hh>
#include <qpdf/QPDF_Bool.hh>
#include <qpdf/QPDF_Dictionary.hh>
#include <qpdf/QPDF_InlineImage.hh>
#include <qpdf/QPDF_Integer.hh>
#include <qpdf/QPDF_Name.hh>
#include <qpdf/QPDF_Null.hh>
#include <qpdf/QPDF_Operator.hh>
#include <qpdf/QPDF_Real.hh>
#include <qpdf/QPDF_Reserved.hh>
#include <qpdf/QPDF_Stream.hh>
#include <qpdf/QPDF_String.hh>
#include <qpdf/QPDF_Unresolved.hh>
#include <qpdf/QTC.hh> #include <qpdf/QTC.hh>
#include <qpdf/QUtil.hh> #include <qpdf/QUtil.hh>
#include <memory>
namespace namespace
{ {
struct StackFrame struct StackFrame
@ -39,7 +54,7 @@ QPDFParser::parse(bool& empty, bool content_stream)
empty = false; empty = false;
QPDFObjectHandle object; std::shared_ptr<QPDFObject> object;
bool set_offset = false; bool set_offset = false;
std::vector<StackFrame> stack; std::vector<StackFrame> stack;
@ -63,7 +78,7 @@ QPDFParser::parse(bool& empty, bool content_stream)
parser_state_e state = state_stack.back(); parser_state_e state = state_stack.back();
offset = frame.offset; offset = frame.offset;
object = QPDFObjectHandle(); object = nullptr;
set_offset = false; set_offset = false;
QPDFTokenizer::Token token = QPDFTokenizer::Token token =
@ -140,7 +155,7 @@ QPDFParser::parse(bool& empty, bool content_stream)
break; break;
case QPDFTokenizer::tt_bool: case QPDFTokenizer::tt_bool:
object = QPDFObjectHandle::newBool((token.getValue() == "true")); object = QPDF_Bool::create((token.getValue() == "true"));
break; break;
case QPDFTokenizer::tt_null: case QPDFTokenizer::tt_null:
@ -148,18 +163,18 @@ QPDFParser::parse(bool& empty, bool content_stream)
break; break;
case QPDFTokenizer::tt_integer: case QPDFTokenizer::tt_integer:
object = QPDFObjectHandle::newInteger( object = QPDF_Integer::create(
QUtil::string_to_ll(token.getValue().c_str())); QUtil::string_to_ll(token.getValue().c_str()));
break; break;
case QPDFTokenizer::tt_real: case QPDFTokenizer::tt_real:
object = QPDFObjectHandle::newReal(token.getValue()); object = QPDF_Real::create(token.getValue());
break; break;
case QPDFTokenizer::tt_name: case QPDFTokenizer::tt_name:
{ {
std::string name = token.getValue(); std::string name = token.getValue();
object = QPDFObjectHandle::newName(name); object = QPDF_Name::create(name);
if (name == "/Contents") { if (name == "/Contents") {
b_contents = true; b_contents = true;
@ -174,7 +189,7 @@ QPDFParser::parse(bool& empty, bool content_stream)
std::string const& value = token.getValue(); std::string const& value = token.getValue();
auto size = olist.size(); auto size = olist.size();
if (content_stream) { if (content_stream) {
object = QPDFObjectHandle::newOperator(value); object = QPDF_Operator::create(value);
} else if ( } else if (
(value == "R") && (state != st_top) && (size >= 2) && (value == "R") && (state != st_top) && (size >= 2) &&
(!olist.back().isIndirect()) && (!olist.back().isIndirect()) &&
@ -196,7 +211,7 @@ QPDFParser::parse(bool& empty, bool content_stream)
// to indirect objects that don't appear in // to indirect objects that don't appear in
// the PDF) in any parsed object to appear in // the PDF) in any parsed object to appear in
// the object cache. // the object cache.
object = context->getObject(ref_og); object = context->getObject(ref_og).obj;
indirect_ref = true; indirect_ref = true;
} else { } else {
QTC::TC("qpdf", "QPDFParser indirect with 0 objid"); QTC::TC("qpdf", "QPDFParser indirect with 0 objid");
@ -216,7 +231,7 @@ QPDFParser::parse(bool& empty, bool content_stream)
warn("unknown token while reading object;" warn("unknown token while reading object;"
" treating as string"); " treating as string");
bad = true; bad = true;
object = QPDFObjectHandle::newString(value); object = QPDF_String::create(value);
} }
} }
break; break;
@ -232,7 +247,7 @@ QPDFParser::parse(bool& empty, bool content_stream)
} }
decrypter->decryptString(val); decrypter->decryptString(val);
} }
object = QPDFObjectHandle::newString(val); object = QPDF_String::create(val);
} }
break; break;
@ -245,7 +260,7 @@ QPDFParser::parse(bool& empty, bool content_stream)
break; break;
} }
if (!object.isInitialized() && !is_null && if (object == nullptr && !is_null &&
(!((state == st_start) || (state == st_stop) || (!((state == st_start) || (state == st_stop) ||
(state == st_eof)))) { (state == st_eof)))) {
throw std::logic_error("QPDFObjectHandle::parseInternal: " throw std::logic_error("QPDFObjectHandle::parseInternal: "
@ -291,7 +306,7 @@ QPDFParser::parse(bool& empty, bool content_stream)
setDescription(object, input->getLastOffset()); setDescription(object, input->getLastOffset());
} }
set_offset = true; set_offset = true;
olist.push_back(is_null ? null_oh : object); olist.push_back(is_null ? null_oh : QPDFObjectHandle(object));
break; break;
case st_top: case st_top:
@ -310,7 +325,7 @@ QPDFParser::parse(bool& empty, bool content_stream)
parser_state_e old_state = state_stack.back(); parser_state_e old_state = state_stack.back();
state_stack.pop_back(); state_stack.pop_back();
if (old_state == st_array) { if (old_state == st_array) {
object = QPDFObjectHandle::newArray(olist); object = QPDF_Array::create(olist);
setDescription(object, offset - 1); setDescription(object, offset - 1);
// The `offset` points to the next of "[". Set the rewind // The `offset` points to the next of "[". Set the rewind
// offset to point to the beginning of "[". This has been // offset to point to the beginning of "[". This has been
@ -384,7 +399,7 @@ QPDFParser::parse(bool& empty, bool content_stream)
QPDFObjectHandle::newString(frame.contents_string); QPDFObjectHandle::newString(frame.contents_string);
dict["/Contents"].setParsedOffset(frame.contents_offset); dict["/Contents"].setParsedOffset(frame.contents_offset);
} }
object = QPDFObjectHandle::newDictionary(dict); object = QPDF_Dictionary::create(dict);
setDescription(object, offset - 2); setDescription(object, offset - 2);
// The `offset` points to the next of "<<". Set the rewind // The `offset` points to the next of "<<". Set the rewind
// offset to point to the beginning of "<<". This has been // offset to point to the beginning of "<<". This has been
@ -397,13 +412,14 @@ QPDFParser::parse(bool& empty, bool content_stream)
if (state_stack.back() == st_top) { if (state_stack.back() == st_top) {
done = true; done = true;
} else { } else {
stack.back().olist.push_back(is_null ? null_oh : object); stack.back().olist.push_back(
is_null ? null_oh : QPDFObjectHandle(object));
} }
} }
} }
if (is_null) { if (is_null) {
object = QPDFObjectHandle::newNull(); object = QPDF_Null::create();
} }
if (!set_offset) { if (!set_offset) {
setDescription(object, offset); setDescription(object, offset);