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 @@ -4,3 +4,3 @@ // -// Copyright 1996 Derek B. Noonburg +// Copyright 1996-2002 Glyph & Cog, LLC // @@ -27,2 +27,3 @@ #include "Error.h" +#include "ErrorCodes.h" #include "XRef.h" @@ -51,3 +52,3 @@ XRef::XRef(BaseStream *strA, GString *ownerPassword, GString *userPassword) { - int pos; + Guint pos; int i; @@ -55,2 +56,3 @@ XRef::XRef(BaseStream *strA, GString *ownerPassword, GString *userPassword) { ok = gTrue; + errCode = errNone; size = 0; @@ -69,2 +71,3 @@ XRef::XRef(BaseStream *strA, GString *ownerPassword, GString *userPassword) { if (!(ok = constructXRef())) { + errCode = errDamaged; return; @@ -76,3 +79,3 @@ XRef::XRef(BaseStream *strA, GString *ownerPassword, GString *userPassword) { for (i = 0; i < size; ++i) { - entries[i].offset = -1; + entries[i].offset = 0xffffffff; entries[i].used = gFalse; @@ -88,2 +91,3 @@ XRef::XRef(BaseStream *strA, GString *ownerPassword, GString *userPassword) { if (!(ok = constructXRef())) { + errCode = errDamaged; return; @@ -103,2 +107,3 @@ XRef::XRef(BaseStream *strA, GString *ownerPassword, GString *userPassword) { ok = gFalse; + errCode = errEncrypted; return; @@ -117,3 +122,3 @@ XRef::~XRef() { // first xref position. -int XRef::readTrailer() { +Guint XRef::readTrailer() { Parser *parser; @@ -121,3 +126,4 @@ int XRef::readTrailer() { char buf[xrefSearchSize+1]; - int n, pos, pos1; + int n; + Guint pos, pos1; char *p; @@ -127,3 +133,3 @@ int XRef::readTrailer() { // read last xrefSearchSize bytes - str->setPos(-xrefSearchSize); + str->setPos(xrefSearchSize, -1); for (n = 0; n < xrefSearchSize; ++n) { @@ -143,3 +149,3 @@ int XRef::readTrailer() { for (p = &buf[i+9]; isspace(*p); ++p) ; - pos = lastXRefPos = atoi(p); + pos = lastXRefPos = strToUnsigned(p); @@ -178,4 +184,5 @@ int XRef::readTrailer() { 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); @@ -206,3 +213,3 @@ 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; @@ -263,3 +270,3 @@ GBool XRef::readXRef(int *pos) { for (i = size; i < newSize; ++i) { - entries[i].offset = -1; + entries[i].offset = 0xffffffff; entries[i].used = gFalse; @@ -275,5 +282,5 @@ GBool XRef::readXRef(int *pos) { } - 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'; @@ -295,3 +302,3 @@ GBool XRef::readXRef(int *pos) { entries[0] = entries[1]; - entries[1].offset = -1; + entries[1].offset = 0xffffffff; } @@ -303,4 +310,5 @@ GBool XRef::readXRef(int *pos) { 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); @@ -316,3 +324,3 @@ GBool XRef::readXRef(int *pos) { if (obj2.isInt()) { - *pos = obj2.getInt(); + *pos = (Guint)obj2.getInt(); more = gTrue; @@ -339,3 +347,3 @@ GBool XRef::constructXRef() { char buf[256]; - int pos; + Guint pos; int num, gen; @@ -362,4 +370,5 @@ GBool XRef::constructXRef() { 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()) @@ -405,3 +414,3 @@ GBool XRef::constructXRef() { for (i = size; i < newSize; ++i) { - entries[i].offset = -1; + entries[i].offset = 0xffffffff; entries[i].used = gFalse; @@ -423,3 +432,4 @@ GBool XRef::constructXRef() { streamEndsSize += 64; - streamEnds = (int *)grealloc(streamEnds, streamEndsSize * sizeof(int)); + streamEnds = (Guint *)grealloc(streamEnds, + streamEndsSize * sizeof(int)); } @@ -582,6 +592,7 @@ 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); @@ -620,3 +631,3 @@ Object *XRef::getDocInfoNF(Object *obj) { -int XRef::getStreamEnd(int streamStart) { +GBool XRef::getStreamEnd(Guint streamStart, Guint *streamEnd) { int a, b, m; @@ -625,3 +636,3 @@ int XRef::getStreamEnd(int streamStart) { streamStart > streamEnds[streamEndsLen - 1]) { - return -1; + return gFalse; } @@ -639,3 +650,16 @@ 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; } |