summaryrefslogtreecommitdiff
path: root/Build
diff options
context:
space:
mode:
authorLuigi Scarso <luigi.scarso@gmail.com>2019-03-17 21:43:59 +0000
committerLuigi Scarso <luigi.scarso@gmail.com>2019-03-17 21:43:59 +0000
commit5698059f8aa4109c8f98d166ef398f04c515b022 (patch)
tree63c2dc21e4bac555b03180757f787e931c9f1fa1 /Build
parent92df70634c796daf81679360e2cc092d28cb6edc (diff)
LuaTeX: several catches for indirect references to non existing objects.
git-svn-id: svn://tug.org/texlive/trunk@50430 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build')
-rw-r--r--Build/source/texk/web2c/luatexdir/image/pdftoepdf.c50
-rw-r--r--Build/source/texk/web2c/luatexdir/lua/lpdfelib.c99
-rw-r--r--Build/source/texk/web2c/luatexdir/luatex_svnversion.h2
3 files changed, 92 insertions, 59 deletions
diff --git a/Build/source/texk/web2c/luatexdir/image/pdftoepdf.c b/Build/source/texk/web2c/luatexdir/image/pdftoepdf.c
index 664bfef18c9..547d0f67cac 100644
--- a/Build/source/texk/web2c/luatexdir/image/pdftoepdf.c
+++ b/Build/source/texk/web2c/luatexdir/image/pdftoepdf.c
@@ -552,15 +552,23 @@ static void writeRefs(PDF pdf, PdfDocument * pdf_doc)
ppref * ref ;
ppxref * xref = ppdoc_xref (pdf_doc->pdfe);
for (r = pdf_doc->inObjList; r != NULL;) {
- ref = ppxref_find (xref, (ppuint) r->objnum);
- obj = ppref_obj(ref);
- if (obj->type == PPSTREAM) {
- pdf_begin_obj(pdf, r->num, OBJSTM_NEVER);
+ if (xref != NULL) {
+ ref = ppxref_find(xref, (ppuint) r->objnum);
+ if (ref != NULL) {
+ obj = ppref_obj(ref);
+ if (obj->type == PPSTREAM) {
+ pdf_begin_obj(pdf, r->num, OBJSTM_NEVER);
+ } else {
+ pdf_begin_obj(pdf, r->num, 2);
+ }
+ copyObject(pdf, pdf_doc, obj);
+ pdf_end_obj(pdf);
+ } else {
+ formatted_warning("pdf inclusion","ignoring missing object %i, case 1\n",(int) r->objnum);
+ }
} else {
- pdf_begin_obj(pdf, r->num, 2);
+ formatted_warning("pdf inclusion","ignoring missing object %i, case 2\n",(int) r->objnum);
}
- copyObject(pdf, pdf_doc, obj);
- pdf_end_obj(pdf);
n = r->next;
free(r);
r = n;
@@ -995,19 +1003,25 @@ int write_epdf_object(PDF pdf, image_dict * idict, int n)
} else {
PdfDocument * pdf_doc = refPdfDocument(img_filepath(idict), FE_FAIL, img_userpassword(idict), img_ownerpassword(idict));
ppdoc * pdfe = pdf_doc->pdfe;
- ppref * ref = ppxref_find(ppdoc_xref(pdfe), (ppuint) n);
- if (ref != NULL) {
- ppobj *obj;
- num = pdf->obj_count++;
- obj = ppref_obj(ref);
- if (obj->type == PPSTREAM) {
- pdf_begin_obj(pdf, num, OBJSTM_NEVER);
+ if (ppdoc_xref(pdfe)) {
+ ppref * ref = ppxref_find(ppdoc_xref(pdfe), (ppuint) n);
+ if (ref != NULL) {
+ ppobj *obj;
+ num = pdf->obj_count++;
+ obj = ppref_obj(ref);
+ if (obj->type == PPSTREAM) {
+ pdf_begin_obj(pdf, num, OBJSTM_NEVER);
+ } else {
+ pdf_begin_obj(pdf, num, 2);
+ }
+ copyObject(pdf, pdf_doc, obj);
+ pdf_end_obj(pdf);
+ writeRefs(pdf, pdf_doc);
} else {
- pdf_begin_obj(pdf, num, 2);
+ formatted_warning("pdf inclusion","ignoring missing image %i, case 1\n",(int) n);
}
- copyObject(pdf, pdf_doc, obj);
- pdf_end_obj(pdf);
- writeRefs(pdf, pdf_doc);
+ } else {
+ formatted_warning("pdf inclusion","ignoring missing image %i, case 2\n",(int) n);
}
if (! img_keepopen(idict)) {
unrefPdfDocument(img_filepath(idict));
diff --git a/Build/source/texk/web2c/luatexdir/lua/lpdfelib.c b/Build/source/texk/web2c/luatexdir/lua/lpdfelib.c
index dc09d347aad..c4f598bf4e3 100644
--- a/Build/source/texk/web2c/luatexdir/lua/lpdfelib.c
+++ b/Build/source/texk/web2c/luatexdir/lua/lpdfelib.c
@@ -367,7 +367,7 @@ static int pushstreamonly(lua_State * L, ppstream * stream)
static int pushreference(lua_State * L, ppref * reference)
{
- if (reference != NULL) {
+ if (reference != NULL && reference->number != 0) {
pdfe_push_reference;
lua_pushinteger(L,reference->number);
return 2;
@@ -502,8 +502,10 @@ static int pdfelib_getfromarray(lua_State * L)
int index = luaL_checkint(L, 2) - 1;
if (index < a->array->size) {
ppobj *object = pparray_at(a->array,index);
- lua_pushinteger(L,(int) object->type);
- return 1 + pushvalue(L,object);
+ if (object != NULL) {
+ lua_pushinteger(L,(int) object->type);
+ return 1 + pushvalue(L,object);
+ }
}
}
return 0;
@@ -524,10 +526,12 @@ static int pdfelib_getfromdictionary(lua_State * L)
int index = luaL_checkint(L, 2) - 1;
if (index < d->dictionary->size) {
ppobj *object = ppdict_at(d->dictionary,index);
- ppname key = ppdict_key(d->dictionary,index);
- lua_pushstring(L,(const char *) key);
- lua_pushinteger(L,(int) object->type);
- return 2 + pushvalue(L,object);
+ if (object != NULL) {
+ ppname key = ppdict_key(d->dictionary,index);
+ lua_pushstring(L,(const char *) key);
+ lua_pushinteger(L,(int) object->type);
+ return 2 + pushvalue(L,object);
+ }
}
}
}
@@ -550,10 +554,12 @@ static int pdfelib_getfromstream(lua_State * L)
int index = luaL_checkint(L, 2) - 1;
if (index < d->size) {
ppobj *object = ppdict_at(d,index);
- ppname key = ppdict_key(d,index);
- lua_pushstring(L,(const char *) key);
- lua_pushinteger(L,(int) object->type);
- return 2 + pushvalue(L,object);
+ if (object != NULL) {
+ ppname key = ppdict_key(d,index);
+ lua_pushstring(L,(const char *) key);
+ lua_pushinteger(L,(int) object->type);
+ return 2 + pushvalue(L,object);
+ }
}
}
}
@@ -622,14 +628,17 @@ static int pdfelib_arraytotable(lua_State * L)
if (a != NULL) {
int flat = lua_isboolean(L,2);
int i = 0;
+ int j = 0;
lua_createtable(L,i,0);
/* table */
for (i=0;i<a->array->size;i++) {
ppobj *object = pparray_at(a->array,i);
- pdfelib_totable(L,object,flat);
- /* table { type, [value], [extra], [more] } */
- lua_rawseti(L,-2,i+1);
- /* table[i] = { type, [value], [extra], [more] } */
+ if (object != NULL) {
+ pdfelib_totable(L,object,flat);
+ /* table { type, [value], [extra], [more] } */
+ lua_rawseti(L,-2,++j);
+ /* table[i] = { type, [value], [extra], [more] } */
+ }
}
return 1;
}
@@ -646,13 +655,15 @@ static int pdfelib_dictionarytotable(lua_State * L)
/* table */
for (i=0;i<d->dictionary->size;i++) {
ppobj *object = ppdict_at(d->dictionary,i);
- ppname key = ppdict_key(d->dictionary,i);
- lua_pushstring(L,(const char *) key);
- /* table key */
- pdfelib_totable(L,object,flat);
- /* table key { type, [value], [extra], [more] } */
- lua_rawset(L,-3);
- /* table[key] = { type, [value], [extra] } */
+ if (object != NULL) {
+ ppname key = ppdict_key(d->dictionary,i);
+ lua_pushstring(L,(const char *) key);
+ /* table key */
+ pdfelib_totable(L,object,flat);
+ /* table key { type, [value], [extra], [more] } */
+ lua_rawset(L,-3);
+ /* table[key] = { type, [value], [extra] } */
+ }
}
return 1;
}
@@ -676,22 +687,25 @@ static int pdfelib_pagestotable(lua_State * L)
ppdoc *d = p->document;
ppref *r = NULL;
int i = 0;
+ int j = 0;
lua_createtable(L,ppdoc_page_count(d),0);
/* pages[1..n] */
for (r = ppdoc_first_page(d), i = 1; r != NULL; r = ppdoc_next_page(d), ++i) {
lua_createtable(L,3,0);
- pushdictionary(L,ppref_obj(r)->dict);
- /* table dictionary n */
- lua_rawseti(L,-3,2);
- /* table dictionary */
- lua_rawseti(L,-2,1);
- /* table */
- lua_pushinteger(L,r->number);
- /* table reference */
- lua_rawseti(L,-2,3);
- /* table */
- lua_rawseti(L,-2,i);
- /* pages[i] = { dictionary, size, objnum } */
+ if (ppref_obj(r) != NULL) {
+ pushdictionary(L,ppref_obj(r)->dict);
+ /* table dictionary n */
+ lua_rawseti(L,-3,2);
+ /* table dictionary */
+ lua_rawseti(L,-2,1);
+ /* table */
+ lua_pushinteger(L,r->number);
+ /* table reference */
+ lua_rawseti(L,-2,3);
+ /* table */
+ lua_rawseti(L,-2,++j);
+ /* pages[i] = { dictionary, size, objnum } */
+ }
}
return 1;
}
@@ -1158,10 +1172,15 @@ static int pdfelib_getbox(lua_State * L)
static int pdfelib_getfromreference(lua_State * L)
{
pdfe_reference *r = check_isreference(L, 1);
- if (r != NULL) {
- ppobj *o = ppref_obj(ppxref_find(r->xref, (ppuint) r->onum));
- lua_pushinteger(L,o->type);
- return 1 + pushvalue(L,o);
+ if (r != NULL && r->xref != NULL) {
+ ppref *rr = ppxref_find(r->xref, (ppuint) r->onum);
+ if (rr != NULL) {
+ ppobj *o = ppref_obj(rr);
+ if (o != NULL) {
+ lua_pushinteger(L,o->type);
+ return 1 + pushvalue(L,o);
+ }
+ }
}
return 0;
}
@@ -1213,8 +1232,8 @@ static int pdfelib_getfromreference(lua_State * L)
*/
# define pdfelib_get_indirect_o(p) \
- ppref *r = ppxref_find(((pdfe_reference *) p)->xref, (ppuint) (((pdfe_reference *) p)->onum)); \
- ppobj *o = ppref_obj(r); \
+ ppref *r = (((pdfe_reference *) p)->xref != NULL) ? ppxref_find(((pdfe_reference *) p)->xref, (ppuint) (((pdfe_reference *) p)->onum)) : NULL; \
+ ppobj *o = (r != NULL) ? ppref_obj(r) : NULL; \
# define pdfelib_get_value_direct(get_d,get_a) do { \
int t = lua_type(L,2); \
diff --git a/Build/source/texk/web2c/luatexdir/luatex_svnversion.h b/Build/source/texk/web2c/luatexdir/luatex_svnversion.h
index a087bc9827a..39bdfd96928 100644
--- a/Build/source/texk/web2c/luatexdir/luatex_svnversion.h
+++ b/Build/source/texk/web2c/luatexdir/luatex_svnversion.h
@@ -1 +1 @@
-#define luatex_svn_revision 7116
+#define luatex_svn_revision 7119