summaryrefslogtreecommitdiff
path: root/source/pdf/pdf-repair.c
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2016-06-30 15:21:56 +0200
committerTor Andersson <tor.andersson@artifex.com>2016-07-06 13:34:37 +0200
commit255776a778b519183d6935ff0cb4b766644fa830 (patch)
tree16c2d411870b31cc25a2941d90ca862c10083667 /source/pdf/pdf-repair.c
parentb644ed1360d0e47c03a637bbc568000d57d0cdbf (diff)
downloadmupdf-255776a778b519183d6935ff0cb4b766644fa830.tar.xz
pdf: Drop generation number from public interfaces.
The generation number is only needed for decryption, and is assumed to be zero or irrelevant for all other uses. Store the original object number and generation in the xref slot, so that we can decrypt them even when the objects have been renumbered, without needing to pass the original object number around through the stream loading APIs.
Diffstat (limited to 'source/pdf/pdf-repair.c')
-rw-r--r--source/pdf/pdf-repair.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/source/pdf/pdf-repair.c b/source/pdf/pdf-repair.c
index b0c56be0..fdb48fe9 100644
--- a/source/pdf/pdf-repair.c
+++ b/source/pdf/pdf-repair.c
@@ -193,7 +193,7 @@ atobjend:
}
static void
-pdf_repair_obj_stm(fz_context *ctx, pdf_document *doc, int num, int gen)
+pdf_repair_obj_stm(fz_context *ctx, pdf_document *doc, int stm_num)
{
pdf_obj *obj;
fz_stream *stm = NULL;
@@ -207,13 +207,13 @@ pdf_repair_obj_stm(fz_context *ctx, pdf_document *doc, int num, int gen)
fz_try(ctx)
{
- obj = pdf_load_object(ctx, doc, num, gen);
+ obj = pdf_load_object(ctx, doc, stm_num);
count = pdf_to_int(ctx, pdf_dict_get(ctx, obj, PDF_NAME_N));
pdf_drop_obj(ctx, obj);
- stm = pdf_open_stream(ctx, doc, num, gen);
+ stm = pdf_open_stream(ctx, doc, stm_num);
for (i = 0; i < count; i++)
{
@@ -221,7 +221,7 @@ pdf_repair_obj_stm(fz_context *ctx, pdf_document *doc, int num, int gen)
tok = pdf_lex(ctx, stm, &buf);
if (tok != PDF_TOK_INT)
- fz_throw(ctx, FZ_ERROR_GENERIC, "corrupt object stream (%d %d R)", num, gen);
+ fz_throw(ctx, FZ_ERROR_GENERIC, "corrupt object stream (%d 0 R)", stm_num);
n = buf.i;
if (n < 0)
@@ -236,8 +236,9 @@ pdf_repair_obj_stm(fz_context *ctx, pdf_document *doc, int num, int gen)
}
entry = pdf_get_populating_xref_entry(ctx, doc, n);
- entry->ofs = num;
+ entry->ofs = stm_num;
entry->gen = i;
+ entry->num = n;
entry->stm_ofs = 0;
pdf_drop_obj(ctx, entry->obj);
entry->obj = NULL;
@@ -245,7 +246,7 @@ pdf_repair_obj_stm(fz_context *ctx, pdf_document *doc, int num, int gen)
tok = pdf_lex(ctx, stm, &buf);
if (tok != PDF_TOK_INT)
- fz_throw(ctx, FZ_ERROR_GENERIC, "corrupt object stream (%d %d R)", num, gen);
+ fz_throw(ctx, FZ_ERROR_GENERIC, "corrupt object stream (%d 0 R)", stm_num);
}
}
fz_always(ctx)
@@ -509,6 +510,7 @@ pdf_repair_xref(fz_context *ctx, pdf_document *doc)
entry->type = 'f';
entry->ofs = 0;
entry->gen = 0;
+ entry->num = 0;
entry->stm_ofs = 0;
}
@@ -519,13 +521,14 @@ pdf_repair_xref(fz_context *ctx, pdf_document *doc)
entry->type = 'n';
entry->ofs = list[i].ofs;
entry->gen = list[i].gen;
+ entry->num = list[i].num;
entry->stm_ofs = list[i].stm_ofs;
/* correct stream length for unencrypted documents */
if (!encrypt && list[i].stm_len >= 0)
{
- dict = pdf_load_object(ctx, doc, list[i].num, list[i].gen);
+ dict = pdf_load_object(ctx, doc, list[i].num);
length = pdf_new_int(ctx, doc, list[i].stm_len);
pdf_dict_put(ctx, dict, PDF_NAME_Length, length);
@@ -539,6 +542,7 @@ pdf_repair_xref(fz_context *ctx, pdf_document *doc)
entry->type = 'f';
entry->ofs = 0;
entry->gen = 65535;
+ entry->num = 0;
entry->stm_ofs = 0;
next = 0;
@@ -651,11 +655,11 @@ pdf_repair_obj_stms(fz_context *ctx, pdf_document *doc)
if (entry->stm_ofs)
{
- dict = pdf_load_object(ctx, doc, i, 0);
+ dict = pdf_load_object(ctx, doc, i);
fz_try(ctx)
{
if (pdf_name_eq(ctx, pdf_dict_get(ctx, dict, PDF_NAME_Type), PDF_NAME_ObjStm))
- pdf_repair_obj_stm(ctx, doc, i, 0);
+ pdf_repair_obj_stm(ctx, doc, i);
}
fz_catch(ctx)
{