Diffstat (limited to 'noncore/unsupported/qpdf/xpdf/XRef.cc') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/unsupported/qpdf/xpdf/XRef.cc | 80 |
1 files changed, 52 insertions, 28 deletions
diff --git a/noncore/unsupported/qpdf/xpdf/XRef.cc b/noncore/unsupported/qpdf/xpdf/XRef.cc index 5d526e9..0e1bbc9 100644 --- a/noncore/unsupported/qpdf/xpdf/XRef.cc +++ b/noncore/unsupported/qpdf/xpdf/XRef.cc @@ -3,5 +3,5 @@ // XRef.cc // -// Copyright 1996 Derek B. Noonburg +// Copyright 1996-2002 Glyph & Cog, LLC // //======================================================================== @@ -26,4 +26,5 @@ #endif #include "Error.h" +#include "ErrorCodes.h" #include "XRef.h" @@ -50,8 +51,9 @@ XRef::XRef(BaseStream *strA, GString *ownerPassword, GString *userPassword) { - int pos; + Guint pos; int i; ok = gTrue; + errCode = errNone; size = 0; entries = NULL; @@ -68,4 +70,5 @@ XRef::XRef(BaseStream *strA, GString *ownerPassword, GString *userPassword) { if (pos == 0) { if (!(ok = constructXRef())) { + errCode = errDamaged; return; } @@ -75,5 +78,5 @@ XRef::XRef(BaseStream *strA, GString *ownerPassword, GString *userPassword) { entries = (XRefEntry *)gmalloc(size * sizeof(XRefEntry)); for (i = 0; i < size; ++i) { - entries[i].offset = -1; + entries[i].offset = 0xffffffff; entries[i].used = gFalse; } @@ -87,4 +90,5 @@ XRef::XRef(BaseStream *strA, GString *ownerPassword, GString *userPassword) { entries = NULL; if (!(ok = constructXRef())) { + errCode = errDamaged; return; } @@ -102,4 +106,5 @@ XRef::XRef(BaseStream *strA, GString *ownerPassword, GString *userPassword) { if (checkEncrypted(ownerPassword, userPassword)) { ok = gFalse; + errCode = errEncrypted; return; } @@ -116,9 +121,10 @@ XRef::~XRef() { // Read startxref position, xref table size, and root. Returns // first xref position. -int XRef::readTrailer() { +Guint XRef::readTrailer() { Parser *parser; Object obj; char buf[xrefSearchSize+1]; - int n, pos, pos1; + int n; + Guint pos, pos1; char *p; int c; @@ -126,5 +132,5 @@ int XRef::readTrailer() { // read last xrefSearchSize bytes - str->setPos(-xrefSearchSize); + str->setPos(xrefSearchSize, -1); for (n = 0; n < xrefSearchSize; ++n) { if ((c = str->getChar()) == EOF) @@ -142,5 +148,5 @@ int XRef::readTrailer() { return 0; for (p = &buf[i+9]; isspace(*p); ++p) ; - pos = lastXRefPos = atoi(p); + pos = lastXRefPos = strToUnsigned(p); // find trailer dict by looking after first xref table @@ -177,6 +183,7 @@ int XRef::readTrailer() { // read trailer dict obj.initNull(); - parser = new Parser(NULL, new Lexer(NULL, str->makeSubStream(start + pos1, - -1, &obj))); + parser = new Parser(NULL, + new Lexer(NULL, + str->makeSubStream(start + pos1, gFalse, 0, &obj))); parser->getObj(&trailerDict); if (trailerDict.isDict()) { @@ -205,5 +212,5 @@ int XRef::readTrailer() { // Read an xref table and the prev pointer from the trailer. -GBool XRef::readXRef(int *pos) { +GBool XRef::readXRef(Guint *pos) { Parser *parser; Object obj, obj2; @@ -262,5 +269,5 @@ GBool XRef::readXRef(int *pos) { entries = (XRefEntry *)grealloc(entries, newSize * sizeof(XRefEntry)); for (i = size; i < newSize; ++i) { - entries[i].offset = -1; + entries[i].offset = 0xffffffff; entries[i].used = gFalse; } @@ -274,7 +281,7 @@ GBool XRef::readXRef(int *pos) { s[j] = (char)c; } - if (entries[i].offset < 0) { + if (entries[i].offset == 0xffffffff) { s[10] = '\0'; - entries[i].offset = atoi(s); + entries[i].offset = strToUnsigned(s); s[16] = '\0'; entries[i].gen = atoi(&s[11]); @@ -294,5 +301,5 @@ GBool XRef::readXRef(int *pos) { i = first = 0; entries[0] = entries[1]; - entries[1].offset = -1; + entries[1].offset = 0xffffffff; } } @@ -302,6 +309,7 @@ GBool XRef::readXRef(int *pos) { // read prev pointer from trailer dictionary obj.initNull(); - parser = new Parser(NULL, new Lexer(NULL, str->makeSubStream(str->getPos(), - -1, &obj))); + parser = new Parser(NULL, + new Lexer(NULL, + str->makeSubStream(str->getPos(), gFalse, 0, &obj))); parser->getObj(&obj); if (!obj.isCmd("trailer")) { @@ -315,5 +323,5 @@ GBool XRef::readXRef(int *pos) { obj.getDict()->lookupNF("Prev", &obj2); if (obj2.isInt()) { - *pos = obj2.getInt(); + *pos = (Guint)obj2.getInt(); more = gTrue; } else { @@ -338,5 +346,5 @@ GBool XRef::constructXRef() { Object obj; char buf[256]; - int pos; + Guint pos; int num, gen; int newSize; @@ -361,6 +369,7 @@ GBool XRef::constructXRef() { if (!strncmp(p, "trailer", 7)) { obj.initNull(); - parser = new Parser(NULL, new Lexer(NULL, - str->makeSubStream(start + pos + 7, -1, &obj))); + parser = new Parser(NULL, + new Lexer(NULL, + str->makeSubStream(start + pos + 7, gFalse, 0, &obj))); if (!trailerDict.isNone()) trailerDict.free(); @@ -404,5 +413,5 @@ GBool XRef::constructXRef() { grealloc(entries, newSize * sizeof(XRefEntry)); for (i = size; i < newSize; ++i) { - entries[i].offset = -1; + entries[i].offset = 0xffffffff; entries[i].used = gFalse; } @@ -422,5 +431,6 @@ GBool XRef::constructXRef() { if (streamEndsLen == streamEndsSize) { streamEndsSize += 64; - streamEnds = (int *)grealloc(streamEnds, streamEndsSize * sizeof(int)); + streamEnds = (Guint *)grealloc(streamEnds, + streamEndsSize * sizeof(int)); } streamEnds[streamEndsLen++] = pos; @@ -581,8 +591,9 @@ Object *XRef::fetch(int num, int gen, Object *obj) { e = &entries[num]; - if (e->gen == gen && e->offset >= 0) { + if (e->gen == gen && e->offset != 0xffffffff) { obj1.initNull(); - parser = new Parser(this, new Lexer(this, - str->makeSubStream(start + e->offset, -1, &obj1))); + parser = new Parser(this, + new Lexer(this, + str->makeSubStream(start + e->offset, gFalse, 0, &obj1))); parser->getObj(&obj1); parser->getObj(&obj2); @@ -619,10 +630,10 @@ Object *XRef::getDocInfoNF(Object *obj) { } -int XRef::getStreamEnd(int streamStart) { +GBool XRef::getStreamEnd(Guint streamStart, Guint *streamEnd) { int a, b, m; if (streamEndsLen == 0 || streamStart > streamEnds[streamEndsLen - 1]) { - return -1; + return gFalse; } @@ -638,4 +649,17 @@ int XRef::getStreamEnd(int streamStart) { } } - return streamEnds[b]; + *streamEnd = streamEnds[b]; + return gTrue; +} + +Guint XRef::strToUnsigned(char *s) { + Guint x; + char *p; + int i; + + x = 0; + for (p = s, i = 0; *p && isdigit(*p) && i < 10; ++p, ++i) { + x = 10 * x + (*p - '0'); + } + return x; } |