diff --git a/libqpdf/QPDFParser.cc b/libqpdf/QPDFParser.cc index 6b3cdb4..3088891 100644 --- a/libqpdf/QPDFParser.cc +++ b/libqpdf/QPDFParser.cc @@ -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 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 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); } } } diff --git a/libqpdf/QPDF_Array.cc b/libqpdf/QPDF_Array.cc index 12e4b3e..de34103 100644 --- a/libqpdf/QPDF_Array.cc +++ b/libqpdf/QPDF_Array.cc @@ -123,8 +123,12 @@ void QPDF_Array::setFromVector(std::vector>&& 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; + } } } diff --git a/libqpdf/qpdf/SparseOHArray.hh b/libqpdf/qpdf/SparseOHArray.hh index b2b9831..26ae3dc 100644 --- a/libqpdf/qpdf/SparseOHArray.hh +++ b/libqpdf/qpdf/SparseOHArray.hh @@ -4,6 +4,8 @@ #include #include +class QPDF_Array; + class SparseOHArray { public: @@ -25,6 +27,7 @@ class SparseOHArray const_iterator end() const; private: + friend class QPDF_Array; std::unordered_map elements; size_t n_elements; };