Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/pdf/xpdf/XRef.cc
diff options
context:
space:
mode:
authorMartin Kretzschmar <mkretzschmar@src.gnome.org>2004-05-16 22:45:42 (GMT)
committer Martin Kretzschmar <mkretzschmar@src.gnome.org>2004-05-16 22:45:42 (GMT)
commitad63666daeeda50acc7630132d61fe044634fddd (patch)
tree487b52b30f8a563cbb2e16c6fd2527a6eeb5990f /pdf/xpdf/XRef.cc
parentd57c02ebc09bfd1a0cac44140ec7a80dbe43877e (diff)
Imported Xpdf 2.03 and fixed build.
* ANNOUNCE: * CHANGES: * README: * aconf2.h: * configure.in: * dj_make.bat: * doc/pdffonts.1: * doc/pdffonts.cat: * doc/pdffonts.hlp: * doc/pdfimages.1: * doc/pdfimages.cat: * doc/pdfimages.hlp: * doc/pdfinfo.1: * doc/pdfinfo.cat: * doc/pdfinfo.hlp: * doc/pdftopbm.1: * doc/pdftopbm.cat: * doc/pdftopbm.hlp: * doc/pdftops.1: * doc/pdftops.cat: * doc/pdftops.hlp: * doc/pdftotext.1: * doc/pdftotext.cat: * doc/pdftotext.hlp: * doc/xpdf.1: * doc/xpdf.cat: * doc/xpdf.hlp: * doc/xpdfrc.5: * doc/xpdfrc.cat: * doc/xpdfrc.hlp: * goo/gfile.cc: * ms_make.bat: * vms_make.com: * xpdf/Annot.cc: * xpdf/Array.cc: * xpdf/BuiltinFontTables.cc: * xpdf/CMap.cc: * xpdf/CMap.h: * xpdf/Catalog.cc: * xpdf/CharCodeToUnicode.cc: * xpdf/CharCodeToUnicode.h: * xpdf/Decrypt.cc: * xpdf/Dict.cc: * xpdf/ErrorCodes.h: * xpdf/FTFont.cc: * xpdf/FTFont.h: * xpdf/FontFile.cc: * xpdf/FontFile.h: * xpdf/Function.cc: * xpdf/Gfx.cc: * xpdf/Gfx.h: * xpdf/GfxFont.cc: * xpdf/GfxFont.h: * xpdf/GfxState.cc: * xpdf/GfxState.h: * xpdf/GlobalParams.cc: * xpdf/GlobalParams.h: * xpdf/JBIG2Stream.cc: * xpdf/Link.cc: * xpdf/Link.h: * xpdf/Makefile.am: * xpdf/OutputDev.h: * xpdf/PDFDoc.cc: * xpdf/PDFDoc.h: * xpdf/PSOutputDev.cc: * xpdf/PSOutputDev.h: * xpdf/Page.cc: * xpdf/Page.h: * xpdf/Parser.cc: * xpdf/Stream.cc: * xpdf/Stream.h: * xpdf/TTFont.cc: * xpdf/TTFont.h: * xpdf/TextOutputDev.cc: * xpdf/TextOutputDev.h: * xpdf/UnicodeMap.cc: * xpdf/UnicodeMap.h: * xpdf/UnicodeTypeTable.cc: * xpdf/UnicodeTypeTable.h: * xpdf/XOutputDev.cc: * xpdf/XOutputDev.h: * xpdf/XPDFApp.cc: * xpdf/XPDFCore.cc: * xpdf/XPDFCore.h: * xpdf/XPDFViewer.cc: * xpdf/XPDFViewer.h: * xpdf/XRef.cc: * xpdf/about-text.h: * xpdf/config.h: * xpdf/gpdf-control.cc: * xpdf/gpdf-link-canvas-item.cc: * xpdf/gpdf-links-canvas-layer.cc: * xpdf/pdffonts.cc: * xpdf/pdfimages.cc: * xpdf/pdfinfo.cc: * xpdf/pdftopbm.cc: * xpdf/pdftops.cc: * xpdf/pdftotext.cc: * xpdf/tests/test-links.cc: * xpdf/vms_make.com: * xpdf/xpdf.cc: Imported Xpdf 2.03 and fixed build.
Diffstat (limited to 'pdf/xpdf/XRef.cc')
-rw-r--r--pdf/xpdf/XRef.cc90
1 files changed, 54 insertions, 36 deletions
diff --git a/pdf/xpdf/XRef.cc b/pdf/xpdf/XRef.cc
index 56cb131..eca638d 100644
--- a/pdf/xpdf/XRef.cc
+++ b/pdf/xpdf/XRef.cc
@@ -134,19 +134,22 @@ Guint XRef::readTrailer() {
// read last xrefSearchSize bytes
str->setPos(xrefSearchSize, -1);
for (n = 0; n < xrefSearchSize; ++n) {
- if ((c = str->getChar()) == EOF)
+ if ((c = str->getChar()) == EOF) {
break;
+ }
buf[n] = c;
}
buf[n] = '\0';
// find startxref
for (i = n - 9; i >= 0; --i) {
- if (!strncmp(&buf[i], "startxref", 9))
+ if (!strncmp(&buf[i], "startxref", 9)) {
break;
+ }
+ }
+ if (i < 0) {
+ goto err1;
}
- if (i < 0)
- return 0;
for (p = &buf[i+9]; isspace(*p); ++p) ;
pos = lastXRefPos = strToUnsigned(p);
@@ -154,20 +157,24 @@ Guint XRef::readTrailer() {
// (NB: we can't just use the trailer dict at the end of the file --
// this won't work for linearized files.)
str->setPos(start + pos);
- for (i = 0; i < 4; ++i)
+ for (i = 0; i < 4; ++i) {
buf[i] = str->getChar();
- if (strncmp(buf, "xref", 4))
- return 0;
+ }
+ if (strncmp(buf, "xref", 4)) {
+ goto err1;
+ }
pos1 = pos + 4;
while (1) {
str->setPos(start + pos1);
for (i = 0; i < 35; ++i) {
- if ((c = str->getChar()) == EOF)
- return 0;
+ if ((c = str->getChar()) == EOF) {
+ goto err1;
+ }
buf[i] = c;
}
- if (!strncmp(buf, "trailer", 7))
+ if (!strncmp(buf, "trailer", 7)) {
break;
+ }
p = buf;
while (isspace(*p)) ++p;
while ('0' <= *p && *p <= '9') ++p;
@@ -175,8 +182,9 @@ Guint XRef::readTrailer() {
n = atoi(p);
while ('0' <= *p && *p <= '9') ++p;
while (isspace(*p)) ++p;
- if (p == buf)
- return 0;
+ if (p == buf) {
+ goto err1;
+ }
pos1 += (p - buf) + n * 20;
}
pos1 += 7;
@@ -189,26 +197,36 @@ Guint XRef::readTrailer() {
parser->getObj(&trailerDict);
if (trailerDict.isDict()) {
trailerDict.dictLookupNF("Size", &obj);
- if (obj.isInt())
+ if (obj.isInt()) {
size = obj.getInt();
- else
- pos = 0;
+ } else {
+ goto err3;
+ }
obj.free();
trailerDict.dictLookupNF("Root", &obj);
if (obj.isRef()) {
rootNum = obj.getRefNum();
rootGen = obj.getRefGen();
} else {
- pos = 0;
+ goto err3;
}
obj.free();
} else {
- pos = 0;
+ goto err2;
}
delete parser;
// return first xref position
return pos;
+
+ err3:
+ obj.free();
+ err2:
+ trailerDict.free();
+ delete parser;
+ err1:
+ size = 0;
+ return 0;
}
// Read an xref table and the prev pointer from the trailer.
@@ -266,7 +284,7 @@ GBool XRef::readXRef(Guint *pos) {
// check for buggy PDF files with an incorrect (too small) xref
// table size
if (first + n > size) {
- newSize = size + 256;
+ newSize = first + n;
entries = (XRefEntry *)grealloc(entries, newSize * sizeof(XRefEntry));
for (i = size; i < newSize; ++i) {
entries[i].offset = 0xffffffff;
@@ -373,12 +391,14 @@ GBool XRef::constructXRef() {
// got trailer dictionary
if (!strncmp(p, "trailer", 7)) {
+ gotRoot = gFalse;
obj.initNull();
parser = new Parser(NULL,
new Lexer(NULL,
str->makeSubStream(start + pos + 7, gFalse, 0, &obj)));
- if (!trailerDict.isNone())
+ if (!trailerDict.isNone()) {
trailerDict.free();
+ }
parser->getObj(&trailerDict);
if (trailerDict.isDict()) {
trailerDict.dictLookupNF("Root", &obj);
@@ -389,7 +409,7 @@ GBool XRef::constructXRef() {
}
obj.free();
} else {
- pos = 0;
+ trailerDict.free();
}
delete parser;
@@ -457,6 +477,8 @@ GBool XRef::checkEncrypted(GString *ownerPassword, GString *userPassword) {
GBool encrypted1;
GBool ret;
+ keyLength = 0;
+ encVersion = encRevision = 0;
ret = gFalse;
permFlags = defPermFlags;
@@ -551,38 +573,34 @@ GBool XRef::checkEncrypted(GString *ownerPassword, GString *userPassword) {
GBool XRef::okToPrint(GBool ignoreOwnerPW) {
#ifndef NO_DECRYPTION
- if ((ignoreOwnerPW || !ownerPasswordOk) && !(permFlags & permPrint)) {
- return gFalse;
- }
-#endif
+ return (!ignoreOwnerPW && ownerPasswordOk) || (permFlags & permPrint);
+#else
return gTrue;
+#endif
}
GBool XRef::okToChange(GBool ignoreOwnerPW) {
#ifndef NO_DECRYPTION
- if ((ignoreOwnerPW || !ownerPasswordOk) && !(permFlags & permChange)) {
- return gFalse;
- }
-#endif
+ return (!ignoreOwnerPW && ownerPasswordOk) || (permFlags & permChange);
+#else
return gTrue;
+#endif
}
GBool XRef::okToCopy(GBool ignoreOwnerPW) {
#ifndef NO_DECRYPTION
- if ((ignoreOwnerPW || !ownerPasswordOk) && !(permFlags & permCopy)) {
- return gFalse;
- }
-#endif
+ return (!ignoreOwnerPW && ownerPasswordOk) || (permFlags & permCopy);
+#else
return gTrue;
+#endif
}
GBool XRef::okToAddNotes(GBool ignoreOwnerPW) {
#ifndef NO_DECRYPTION
- if ((ignoreOwnerPW || !ownerPasswordOk) && !(permFlags & permNotes)) {
- return gFalse;
- }
-#endif
+ return (!ignoreOwnerPW && ownerPasswordOk) || (permFlags & permNotes);
+#else
return gTrue;
+#endif
}
Object *XRef::fetch(int num, int gen, Object *obj) {