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 @@ | |||
4 | // | 4 | // |
5 | // Copyright 1996 Derek B. Noonburg | 5 | // Copyright 1996-2002 Glyph & Cog, LLC |
6 | // | 6 | // |
@@ -27,2 +27,3 @@ | |||
27 | #include "Error.h" | 27 | #include "Error.h" |
28 | #include "ErrorCodes.h" | ||
28 | #include "XRef.h" | 29 | #include "XRef.h" |
@@ -51,3 +52,3 @@ | |||
51 | XRef::XRef(BaseStream *strA, GString *ownerPassword, GString *userPassword) { | 52 | XRef::XRef(BaseStream *strA, GString *ownerPassword, GString *userPassword) { |
52 | int pos; | 53 | Guint pos; |
53 | int i; | 54 | int i; |
@@ -55,2 +56,3 @@ XRef::XRef(BaseStream *strA, GString *ownerPassword, GString *userPassword) { | |||
55 | ok = gTrue; | 56 | ok = gTrue; |
57 | errCode = errNone; | ||
56 | size = 0; | 58 | size = 0; |
@@ -69,2 +71,3 @@ XRef::XRef(BaseStream *strA, GString *ownerPassword, GString *userPassword) { | |||
69 | if (!(ok = constructXRef())) { | 71 | if (!(ok = constructXRef())) { |
72 | errCode = errDamaged; | ||
70 | return; | 73 | return; |
@@ -76,3 +79,3 @@ XRef::XRef(BaseStream *strA, GString *ownerPassword, GString *userPassword) { | |||
76 | for (i = 0; i < size; ++i) { | 79 | for (i = 0; i < size; ++i) { |
77 | entries[i].offset = -1; | 80 | entries[i].offset = 0xffffffff; |
78 | entries[i].used = gFalse; | 81 | entries[i].used = gFalse; |
@@ -88,2 +91,3 @@ XRef::XRef(BaseStream *strA, GString *ownerPassword, GString *userPassword) { | |||
88 | if (!(ok = constructXRef())) { | 91 | if (!(ok = constructXRef())) { |
92 | errCode = errDamaged; | ||
89 | return; | 93 | return; |
@@ -103,2 +107,3 @@ XRef::XRef(BaseStream *strA, GString *ownerPassword, GString *userPassword) { | |||
103 | ok = gFalse; | 107 | ok = gFalse; |
108 | errCode = errEncrypted; | ||
104 | return; | 109 | return; |
@@ -117,3 +122,3 @@ XRef::~XRef() { | |||
117 | // first xref position. | 122 | // first xref position. |
118 | int XRef::readTrailer() { | 123 | Guint XRef::readTrailer() { |
119 | Parser *parser; | 124 | Parser *parser; |
@@ -121,3 +126,4 @@ int XRef::readTrailer() { | |||
121 | char buf[xrefSearchSize+1]; | 126 | char buf[xrefSearchSize+1]; |
122 | int n, pos, pos1; | 127 | int n; |
128 | Guint pos, pos1; | ||
123 | char *p; | 129 | char *p; |
@@ -127,3 +133,3 @@ int XRef::readTrailer() { | |||
127 | // read last xrefSearchSize bytes | 133 | // read last xrefSearchSize bytes |
128 | str->setPos(-xrefSearchSize); | 134 | str->setPos(xrefSearchSize, -1); |
129 | for (n = 0; n < xrefSearchSize; ++n) { | 135 | for (n = 0; n < xrefSearchSize; ++n) { |
@@ -143,3 +149,3 @@ int XRef::readTrailer() { | |||
143 | for (p = &buf[i+9]; isspace(*p); ++p) ; | 149 | for (p = &buf[i+9]; isspace(*p); ++p) ; |
144 | pos = lastXRefPos = atoi(p); | 150 | pos = lastXRefPos = strToUnsigned(p); |
145 | 151 | ||
@@ -178,4 +184,5 @@ int XRef::readTrailer() { | |||
178 | obj.initNull(); | 184 | obj.initNull(); |
179 | parser = new Parser(NULL, new Lexer(NULL, str->makeSubStream(start + pos1, | 185 | parser = new Parser(NULL, |
180 | -1, &obj))); | 186 | new Lexer(NULL, |
187 | str->makeSubStream(start + pos1, gFalse, 0, &obj))); | ||
181 | parser->getObj(&trailerDict); | 188 | parser->getObj(&trailerDict); |
@@ -206,3 +213,3 @@ int XRef::readTrailer() { | |||
206 | // Read an xref table and the prev pointer from the trailer. | 213 | // Read an xref table and the prev pointer from the trailer. |
207 | GBool XRef::readXRef(int *pos) { | 214 | GBool XRef::readXRef(Guint *pos) { |
208 | Parser *parser; | 215 | Parser *parser; |
@@ -263,3 +270,3 @@ GBool XRef::readXRef(int *pos) { | |||
263 | for (i = size; i < newSize; ++i) { | 270 | for (i = size; i < newSize; ++i) { |
264 | entries[i].offset = -1; | 271 | entries[i].offset = 0xffffffff; |
265 | entries[i].used = gFalse; | 272 | entries[i].used = gFalse; |
@@ -275,5 +282,5 @@ GBool XRef::readXRef(int *pos) { | |||
275 | } | 282 | } |
276 | if (entries[i].offset < 0) { | 283 | if (entries[i].offset == 0xffffffff) { |
277 | s[10] = '\0'; | 284 | s[10] = '\0'; |
278 | entries[i].offset = atoi(s); | 285 | entries[i].offset = strToUnsigned(s); |
279 | s[16] = '\0'; | 286 | s[16] = '\0'; |
@@ -295,3 +302,3 @@ GBool XRef::readXRef(int *pos) { | |||
295 | entries[0] = entries[1]; | 302 | entries[0] = entries[1]; |
296 | entries[1].offset = -1; | 303 | entries[1].offset = 0xffffffff; |
297 | } | 304 | } |
@@ -303,4 +310,5 @@ GBool XRef::readXRef(int *pos) { | |||
303 | obj.initNull(); | 310 | obj.initNull(); |
304 | parser = new Parser(NULL, new Lexer(NULL, str->makeSubStream(str->getPos(), | 311 | parser = new Parser(NULL, |
305 | -1, &obj))); | 312 | new Lexer(NULL, |
313 | str->makeSubStream(str->getPos(), gFalse, 0, &obj))); | ||
306 | parser->getObj(&obj); | 314 | parser->getObj(&obj); |
@@ -316,3 +324,3 @@ GBool XRef::readXRef(int *pos) { | |||
316 | if (obj2.isInt()) { | 324 | if (obj2.isInt()) { |
317 | *pos = obj2.getInt(); | 325 | *pos = (Guint)obj2.getInt(); |
318 | more = gTrue; | 326 | more = gTrue; |
@@ -339,3 +347,3 @@ GBool XRef::constructXRef() { | |||
339 | char buf[256]; | 347 | char buf[256]; |
340 | int pos; | 348 | Guint pos; |
341 | int num, gen; | 349 | int num, gen; |
@@ -362,4 +370,5 @@ GBool XRef::constructXRef() { | |||
362 | obj.initNull(); | 370 | obj.initNull(); |
363 | parser = new Parser(NULL, new Lexer(NULL, | 371 | parser = new Parser(NULL, |
364 | str->makeSubStream(start + pos + 7, -1, &obj))); | 372 | new Lexer(NULL, |
373 | str->makeSubStream(start + pos + 7, gFalse, 0, &obj))); | ||
365 | if (!trailerDict.isNone()) | 374 | if (!trailerDict.isNone()) |
@@ -405,3 +414,3 @@ GBool XRef::constructXRef() { | |||
405 | for (i = size; i < newSize; ++i) { | 414 | for (i = size; i < newSize; ++i) { |
406 | entries[i].offset = -1; | 415 | entries[i].offset = 0xffffffff; |
407 | entries[i].used = gFalse; | 416 | entries[i].used = gFalse; |
@@ -423,3 +432,4 @@ GBool XRef::constructXRef() { | |||
423 | streamEndsSize += 64; | 432 | streamEndsSize += 64; |
424 | streamEnds = (int *)grealloc(streamEnds, streamEndsSize * sizeof(int)); | 433 | streamEnds = (Guint *)grealloc(streamEnds, |
434 | streamEndsSize * sizeof(int)); | ||
425 | } | 435 | } |
@@ -582,6 +592,7 @@ Object *XRef::fetch(int num, int gen, Object *obj) { | |||
582 | e = &entries[num]; | 592 | e = &entries[num]; |
583 | if (e->gen == gen && e->offset >= 0) { | 593 | if (e->gen == gen && e->offset != 0xffffffff) { |
584 | obj1.initNull(); | 594 | obj1.initNull(); |
585 | parser = new Parser(this, new Lexer(this, | 595 | parser = new Parser(this, |
586 | str->makeSubStream(start + e->offset, -1, &obj1))); | 596 | new Lexer(this, |
597 | str->makeSubStream(start + e->offset, gFalse, 0, &obj1))); | ||
587 | parser->getObj(&obj1); | 598 | parser->getObj(&obj1); |
@@ -620,3 +631,3 @@ Object *XRef::getDocInfoNF(Object *obj) { | |||
620 | 631 | ||
621 | int XRef::getStreamEnd(int streamStart) { | 632 | GBool XRef::getStreamEnd(Guint streamStart, Guint *streamEnd) { |
622 | int a, b, m; | 633 | int a, b, m; |
@@ -625,3 +636,3 @@ int XRef::getStreamEnd(int streamStart) { | |||
625 | streamStart > streamEnds[streamEndsLen - 1]) { | 636 | streamStart > streamEnds[streamEndsLen - 1]) { |
626 | return -1; | 637 | return gFalse; |
627 | } | 638 | } |
@@ -639,3 +650,16 @@ int XRef::getStreamEnd(int streamStart) { | |||
639 | } | 650 | } |
640 | return streamEnds[b]; | 651 | *streamEnd = streamEnds[b]; |
652 | return gTrue; | ||
653 | } | ||
654 | |||
655 | Guint XRef::strToUnsigned(char *s) { | ||
656 | Guint x; | ||
657 | char *p; | ||
658 | int i; | ||
659 | |||
660 | x = 0; | ||
661 | for (p = s, i = 0; *p && isdigit(*p) && i < 10; ++p, ++i) { | ||
662 | x = 10 * x + (*p - '0'); | ||
663 | } | ||
664 | return x; | ||
641 | } | 665 | } |