summaryrefslogtreecommitdiff
path: root/pdf
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2012-01-19 00:58:09 +0100
committerTor Andersson <tor.andersson@artifex.com>2012-01-19 17:48:49 +0100
commit75b6425fe9ce8136dbc852415471708d365b4d25 (patch)
tree3d5533b150d5eb5fd3fe8efa8b667512a44edef7 /pdf
parent08e84b18e5c1dbe8f3d32dd0aeb4b4c43debce9f (diff)
downloadmupdf-75b6425fe9ce8136dbc852415471708d365b4d25.tar.xz
Remove confusing optional 'password' argument to pdf_open_xref.
Require that clients call pdf_needs_password/pdf_authenticate_password instead. For dumb clients, we still allow for decrypting a file with a blank password without calling those functions.
Diffstat (limited to 'pdf')
-rw-r--r--pdf/mupdf.h4
-rw-r--r--pdf/pdf_crypt.c2
-rw-r--r--pdf/pdf_xref.c20
3 files changed, 9 insertions, 17 deletions
diff --git a/pdf/mupdf.h b/pdf/mupdf.h
index b1b2a7e1..dfce00c1 100644
--- a/pdf/mupdf.h
+++ b/pdf/mupdf.h
@@ -106,8 +106,8 @@ fz_stream *pdf_open_raw_stream(pdf_xref *, int num, int gen);
fz_stream *pdf_open_stream(pdf_xref *, int num, int gen);
fz_stream *pdf_open_stream_at(pdf_xref *xref, int num, int gen, fz_obj *dict, int stm_ofs);
-pdf_xref *pdf_open_xref_with_stream(fz_stream *file, char *password);
-pdf_xref *pdf_open_xref(fz_context *ctx, const char *filename, char *password);
+pdf_xref *pdf_open_xref_with_stream(fz_stream *file);
+pdf_xref *pdf_open_xref(fz_context *ctx, const char *filename);
void pdf_free_xref(pdf_xref *);
/* private */
diff --git a/pdf/pdf_crypt.c b/pdf/pdf_crypt.c
index c272562e..18b3d554 100644
--- a/pdf/pdf_crypt.c
+++ b/pdf/pdf_crypt.c
@@ -579,6 +579,8 @@ pdf_authenticate_password(pdf_xref *xref, char *password)
{
if (xref->crypt)
{
+ if (!password)
+ password = "";
if (pdf_authenticate_user_password(xref->crypt, (unsigned char *)password, strlen(password)))
return 1;
if (pdf_authenticate_owner_password(xref->crypt, (unsigned char *)password, strlen(password)))
diff --git a/pdf/pdf_xref.c b/pdf/pdf_xref.c
index 2411c21e..796c9ce3 100644
--- a/pdf/pdf_xref.c
+++ b/pdf/pdf_xref.c
@@ -639,7 +639,7 @@ pdf_free_ocg(fz_context *ctx, pdf_ocg_descriptor *desc)
*/
pdf_xref *
-pdf_open_xref_with_stream(fz_stream *file, char *password)
+pdf_open_xref_with_stream(fz_stream *file)
{
pdf_xref *xref;
fz_obj *encrypt, *id;
@@ -692,18 +692,8 @@ pdf_open_xref_with_stream(fz_stream *file, char *password)
if (fz_is_dict(encrypt))
xref->crypt = pdf_new_crypt(ctx, encrypt, id);
- if (pdf_needs_password(xref))
- {
- /* Only care if we have a password */
- if (password)
- {
- int okay = pdf_authenticate_password(xref, password);
- if (!okay)
- {
- fz_throw(ctx, "invalid password");
- }
- }
- }
+ /* Allow lazy clients to read encrypted files with a blank password */
+ pdf_authenticate_password(xref, "");
if (repaired)
{
@@ -1082,7 +1072,7 @@ pdf_update_object(pdf_xref *xref, int num, int gen, fz_obj *newobj)
*/
pdf_xref *
-pdf_open_xref(fz_context *ctx, const char *filename, char *password)
+pdf_open_xref(fz_context *ctx, const char *filename)
{
fz_stream *file = NULL;
pdf_xref *xref;
@@ -1091,7 +1081,7 @@ pdf_open_xref(fz_context *ctx, const char *filename, char *password)
fz_try(ctx)
{
file = fz_open_file(ctx, filename);
- xref = pdf_open_xref_with_stream(file, password);
+ xref = pdf_open_xref_with_stream(file);
}
fz_catch(ctx)
{