2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-11-15 17:17:08 +00:00
qpdf/libqpdf/QPDFOutlineObjectHelper.cc
Jay Berkenbilt d71f05ca07 Fix sign and conversion warnings (major)
This makes all integer type conversions that have potential data loss
explicit with calls that do range checks and raise an exception. After
this commit, qpdf builds with no warnings when -Wsign-conversion
-Wconversion is used with gcc or clang or when -W3 -Wd4800 is used
with MSVC. This significantly reduces the likelihood of potential
crashes from bogus integer values.

There are some parts of the code that take int when they should take
size_t or an offset. Such places would make qpdf not support files
with more than 2^31 of something that usually wouldn't be so large. In
the event that such a file shows up and is valid, at least qpdf would
raise an error in the right spot so the issue could be legitimately
addressed rather than failing in some weird way because of a silent
overflow condition.
2019-06-21 13:17:21 -04:00

118 lines
2.7 KiB
C++

#include <qpdf/QPDFOutlineObjectHelper.hh>
#include <qpdf/QPDFOutlineDocumentHelper.hh>
#include <qpdf/QTC.hh>
QPDFOutlineObjectHelper::Members::~Members()
{
}
QPDFOutlineObjectHelper::Members::Members(QPDFOutlineDocumentHelper& dh) :
dh(dh)
{
}
QPDFOutlineObjectHelper::QPDFOutlineObjectHelper(
QPDFObjectHandle oh, QPDFOutlineDocumentHelper& dh, int depth) :
QPDFObjectHelper(oh),
m(new Members(dh))
{
if (depth > 50)
{
// Not exercised in test suite, but was tested manually by
// temporarily changing max depth to 1.
return;
}
if (QPDFOutlineDocumentHelper::Accessor::checkSeen(
this->m->dh, this->oh.getObjGen()))
{
QTC::TC("qpdf", "QPDFOutlineObjectHelper loop");
return;
}
QPDFObjectHandle cur = oh.getKey("/First");
while (! cur.isNull())
{
QPDFOutlineObjectHelper new_ooh(cur, dh, 1 + depth);
new_ooh.m->parent = new QPDFOutlineObjectHelper(*this);
this->m->kids.push_back(new_ooh);
cur = cur.getKey("/Next");
}
}
PointerHolder<QPDFOutlineObjectHelper>
QPDFOutlineObjectHelper::getParent()
{
return this->m->parent;
}
std::list<QPDFOutlineObjectHelper>
QPDFOutlineObjectHelper::getKids()
{
return this->m->kids;
}
QPDFObjectHandle
QPDFOutlineObjectHelper::getDest()
{
QPDFObjectHandle dest;
QPDFObjectHandle A;
if (this->oh.hasKey("/Dest"))
{
QTC::TC("qpdf", "QPDFOutlineObjectHelper direct dest");
dest = this->oh.getKey("/Dest");
}
else if ((A = this->oh.getKey("/A")).isDictionary() &&
A.getKey("/S").isName() &&
(A.getKey("/S").getName() == "/GoTo") &&
A.hasKey("/D"))
{
QTC::TC("qpdf", "QPDFOutlineObjectHelper action dest");
dest = A.getKey("/D");
}
if (! dest.isInitialized())
{
dest = QPDFObjectHandle::newNull();
}
if (dest.isName() || dest.isString())
{
QTC::TC("qpdf", "QPDFOutlineObjectHelper named dest");
dest = this->m->dh.resolveNamedDest(dest);
}
return dest;
}
QPDFObjectHandle
QPDFOutlineObjectHelper::getDestPage()
{
QPDFObjectHandle dest = getDest();
if ((dest.isArray()) && (dest.getArrayNItems() > 0))
{
return dest.getArrayItem(0);
}
return QPDFObjectHandle::newNull();
}
int
QPDFOutlineObjectHelper::getCount()
{
int count = 0;
if (this->oh.hasKey("/Count"))
{
count = this->oh.getKey("/Count").getIntValueAsInt();
}
return count;
}
std::string
QPDFOutlineObjectHelper::getTitle()
{
std::string result;
if (this->oh.hasKey("/Title"))
{
result = this->oh.getKey("/Title").getUTF8Value();
}
return result;
}