summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ghostscript.com>2010-07-27 16:41:49 +0000
committerTor Andersson <tor@ghostscript.com>2010-07-27 16:41:49 +0000
commite5d46b949009a1759fdf252ffc9dfd3f49d5fec0 (patch)
tree56378d4ba4ca3e8bc35748d0553c5d17506d18f0
parent37211633cf44cc8fead75933e9f594a030998a33 (diff)
downloadmupdf-e5d46b949009a1759fdf252ffc9dfd3f49d5fec0.tar.xz
Don't cache resolved objects in the indirect reference object (rely on the xref cache instead).
-rw-r--r--fitz/fitz.h1
-rw-r--r--fitz/obj_simple.c30
-rw-r--r--mupdf/pdf_xref.c23
3 files changed, 20 insertions, 34 deletions
diff --git a/fitz/fitz.h b/fitz/fitz.h
index 150c3e56..89a1cc63 100644
--- a/fitz/fitz.h
+++ b/fitz/fitz.h
@@ -371,7 +371,6 @@ struct fz_obj_s
int num;
int gen;
struct pdf_xref_s *xref;
- fz_obj *obj;
} r;
} u;
};
diff --git a/fitz/obj_simple.c b/fitz/obj_simple.c
index fdd18ce1..f279bd55 100644
--- a/fitz/obj_simple.c
+++ b/fitz/obj_simple.c
@@ -74,7 +74,6 @@ fz_newindirect(int num, int gen, pdf_xref *xref)
o->u.r.num = num;
o->u.r.gen = gen;
o->u.r.xref = xref;
- o->u.r.obj = nil;
return o;
}
@@ -93,23 +92,11 @@ fz_dropobj(fz_obj *o)
if (--o->refs == 0)
{
if (o->kind == FZ_ARRAY)
- {
fz_freearray(o);
- }
else if (o->kind == FZ_DICT)
- {
fz_freedict(o);
- }
- else if (o->kind == FZ_INDIRECT)
- {
- if (o->u.r.obj)
- fz_dropobj(o->u.r.obj);
- fz_free(o);
- }
else
- {
fz_free(o);
- }
}
}
@@ -234,22 +221,23 @@ int fz_togen(fz_obj *obj)
fz_obj *fz_resolveindirect(fz_obj *ref)
{
- int error;
-
if (fz_isindirect(ref))
{
- if (!ref->u.r.obj && ref->u.r.xref)
+ pdf_xref *xref = ref->u.r.xref;
+ int num = fz_tonum(ref);
+ int gen = fz_togen(ref);
+ if (xref)
{
- error = pdf_loadobject(&ref->u.r.obj, ref->u.r.xref, fz_tonum(ref), fz_togen(ref));
+ fz_error error = pdf_cacheobject(xref, num, gen);
if (error)
{
- fz_catch(error, "cannot resolve reference (%d %d R); ignoring error", fz_tonum(ref), fz_togen(ref));
- ref->u.r.obj = fz_keepobj(ref);
+ fz_catch(error, "cannot load object (%d %d R) into cache", num, gen);
+ return ref;
}
+ if (xref->table[num].obj)
+ return xref->table[num].obj;
}
- return ref->u.r.obj;
}
-
return ref;
}
diff --git a/mupdf/pdf_xref.c b/mupdf/pdf_xref.c
index 9dec068c..196b633e 100644
--- a/mupdf/pdf_xref.c
+++ b/mupdf/pdf_xref.c
@@ -888,13 +888,12 @@ pdf_cacheobject(pdf_xref *xref, int num, int gen)
if (x->obj)
return fz_okay;
- if (x->type == 'f' || x->type == 'd')
+ if (x->type == 'f')
{
x->obj = fz_newnull();
return fz_okay;
}
-
- if (x->type == 'n')
+ else if (x->type == 'n')
{
error = fz_seek(xref->file, x->ofs, 0);
if (error)
@@ -911,7 +910,6 @@ pdf_cacheobject(pdf_xref *xref, int num, int gen)
if (xref->crypt)
pdf_cryptobj(xref->crypt, x->obj, num, gen);
}
-
else if (x->type == 'o')
{
if (!x->obj)
@@ -919,8 +917,14 @@ pdf_cacheobject(pdf_xref *xref, int num, int gen)
error = pdf_loadobjstm(xref, x->ofs, 0, xref->scratch, sizeof xref->scratch);
if (error)
return fz_rethrow(error, "cannot load object stream containing object (%d %d R)", num, gen);
+ if (!x->obj)
+ return fz_throw("object (%d %d R) was not found in its object stream", num, gen);
}
}
+ else
+ {
+ return fz_throw("assert: corrupt xref struct");
+ }
return fz_okay;
}
@@ -934,14 +938,9 @@ pdf_loadobject(fz_obj **objp, pdf_xref *xref, int num, int gen)
if (error)
return fz_rethrow(error, "cannot load object (%d %d R) into cache", num, gen);
- if (xref->table[num].obj)
- *objp = fz_keepobj(xref->table[num].obj);
- else
- {
- fz_warn("cannot load missing object (%d %d R), assuming null object", num, gen);
- xref->table[num].obj = fz_newnull();
- *objp = fz_keepobj(xref->table[num].obj);
- }
+ assert(xref->table[num].obj);
+
+ *objp = fz_keepobj(xref->table[num].obj);
return fz_okay;
}