summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/pdfapp.c6
-rw-r--r--apps/pdftool.c8
-rw-r--r--mupdf/mupdf.h2
-rw-r--r--mupdf/pdf_open.c27
4 files changed, 21 insertions, 22 deletions
diff --git a/apps/pdfapp.c b/apps/pdfapp.c
index 4ec65148..145f49db 100644
--- a/apps/pdfapp.c
+++ b/apps/pdfapp.c
@@ -103,9 +103,9 @@ void pdfapp_open(pdfapp_t *app, char *filename, int fd)
*/
file = fz_openfile(fd);
- app->xref = pdf_openxref(file);
- if (!app->xref)
- pdfapp_error(app, fz_rethrow(-1, "cannot open PDF file '%s'", filename));
+ error = pdf_openxref(&app->xref, file);
+ if (error)
+ pdfapp_error(app, fz_rethrow(error, "cannot open document '%s'", filename));
fz_dropstream(file);
/*
diff --git a/apps/pdftool.c b/apps/pdftool.c
index 5724e022..094eeaa5 100644
--- a/apps/pdftool.c
+++ b/apps/pdftool.c
@@ -36,12 +36,12 @@ void openxref(char *filename, char *password, int dieonbadpass, int loadpages)
fd = open(filename, O_BINARY | O_RDONLY, 0666);
if (fd < 0)
- die(fz_throw("cannot open file '%s'", filename));
+ die(fz_throw("cannot open file '%s': %s", filename, strerror(errno)));
file = fz_openfile(fd);
- xref = pdf_openxref(file);
- if (!xref)
- die(fz_throw("cannot open PDF file '%s'", basename));
+ error = pdf_openxref(&xref, file);
+ if (error)
+ die(fz_rethrow(error, "cannot open document '%s'", basename));
fz_dropstream(file);
if (pdf_needspassword(xref))
diff --git a/mupdf/mupdf.h b/mupdf/mupdf.h
index 1f48d7f8..eea518d5 100644
--- a/mupdf/mupdf.h
+++ b/mupdf/mupdf.h
@@ -148,7 +148,7 @@ struct pdf_xrefentry_s
int type; /* 0=unset (f)ree i(n)use (o)bjstm */
};
-pdf_xref * pdf_openxref(fz_stream *file);
+fz_error pdf_openxref(pdf_xref **xrefp, fz_stream *file);
void pdf_closexref(pdf_xref *);
void pdf_debugxref(pdf_xref *);
void pdf_flushxref(pdf_xref *, int force);
diff --git a/mupdf/pdf_open.c b/mupdf/pdf_open.c
index 4acac6e2..04d3fb6a 100644
--- a/mupdf/pdf_open.c
+++ b/mupdf/pdf_open.c
@@ -616,8 +616,8 @@ pdf_loadxref(pdf_xref *xref, char *buf, int bufsize)
* Open PDF file and load or reconstruct xref table.
*/
-pdf_xref *
-pdf_openxref(fz_stream *file)
+fz_error
+pdf_openxref(pdf_xref **xrefp, fz_stream *file)
{
pdf_xref *xref;
fz_error error;
@@ -625,6 +625,7 @@ pdf_openxref(fz_stream *file)
fz_obj *id;
xref = fz_malloc(sizeof(pdf_xref));
+
memset(xref, 0, sizeof(pdf_xref));
pdf_logxref("openxref %p\n", xref);
@@ -644,7 +645,10 @@ pdf_openxref(fz_stream *file)
}
error = pdf_repairxref(xref, xref->scratch, sizeof xref->scratch);
if (error)
- goto cleanup;
+ {
+ pdf_closexref(xref);
+ return fz_rethrow(error, "cannot repair document");
+ }
}
encrypt = fz_dictgets(xref->trailer, "Encrypt");
@@ -653,17 +657,12 @@ pdf_openxref(fz_stream *file)
{
error = pdf_newcrypt(&xref->crypt, encrypt, id);
if (error)
- goto cleanup;
+ {
+ pdf_closexref(xref);
+ return fz_rethrow(error, "cannot decrypt document");
+ }
}
- return xref;
-
-cleanup:
- if (xref->file)
- fz_dropstream(xref->file);
- if (xref->table)
- fz_free(xref->table);
- fz_free(xref);
- fz_rethrow(error, "cannot open document");
- return NULL;
+ *xrefp = xref;
+ return fz_okay;
}