2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-11-10 23:20:58 +00:00

Avoid inserting direct null objects into olist

This commit is contained in:
m-holger 2022-12-19 14:52:32 +00:00 committed by Jay Berkenbilt
parent 9da50ca360
commit 8391022416
3 changed files with 19 additions and 9 deletions

View File

@ -308,7 +308,7 @@ QPDFParser::parse(bool& empty, bool content_stream)
setDescription(object, input->getLastOffset());
}
set_offset = true;
olist.push_back(is_null ? null_oh : object);
olist.push_back(object);
break;
case st_top:
@ -339,16 +339,19 @@ QPDFParser::parse(bool& empty, bool content_stream)
// Convert list to map. Alternating elements are keys. Attempt
// to recover more or less gracefully from invalid dictionaries.
std::set<std::string> names;
size_t n_elements = olist.size();
for (size_t i = 0; i < n_elements; ++i) {
QPDFObjectHandle oh = olist.at(i);
if ((!oh.isIndirect()) && oh.isName()) {
names.insert(oh.getName());
for (auto& obj: olist) {
if (obj) {
if (obj->getTypeCode() == ::ot_name) {
names.insert(obj->getStringValue());
}
} else {
obj = null_oh;
}
}
std::map<std::string, QPDFObjectHandle> dict;
int next_fake_key = 1;
size_t n_elements = olist.size();
for (unsigned int i = 0; i < n_elements; ++i) {
QPDFObjectHandle key_obj = olist.at(i);
QPDFObjectHandle val;
@ -414,7 +417,7 @@ QPDFParser::parse(bool& empty, bool content_stream)
if (state_stack.back() == st_top) {
done = true;
} else {
stack.back().olist.push_back(is_null ? null_oh : object);
stack.back().olist.push_back(object);
}
}
}

View File

@ -123,8 +123,12 @@ void
QPDF_Array::setFromVector(std::vector<std::shared_ptr<QPDFObject>>&& v)
{
this->elements = SparseOHArray();
for (auto&& iter: v) {
this->elements.append(iter);
for (auto&& item: v) {
if (item) {
this->elements.append(item);
} else {
++this->elements.n_elements;
}
}
}

View File

@ -4,6 +4,8 @@
#include <qpdf/QPDFObjectHandle.hh>
#include <unordered_map>
class QPDF_Array;
class SparseOHArray
{
public:
@ -25,6 +27,7 @@ class SparseOHArray
const_iterator end() const;
private:
friend class QPDF_Array;
std::unordered_map<size_t, QPDFObjectHandle> elements;
size_t n_elements;
};