Skip to content

Commit 86eb24b

Browse files
committed
LuaTeX: several catches for indirect references to non existing objects.
git-svn-id: svn://tug.org/texlive/trunk/Build/source@50430 c570f23f-e606-0410-a88d-b1316a301751
1 parent 3b145ad commit 86eb24b

File tree

3 files changed

+92
-59
lines changed

3 files changed

+92
-59
lines changed

texk/web2c/luatexdir/image/pdftoepdf.c

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -552,15 +552,23 @@ static void writeRefs(PDF pdf, PdfDocument * pdf_doc)
552552
ppref * ref ;
553553
ppxref * xref = ppdoc_xref (pdf_doc->pdfe);
554554
for (r = pdf_doc->inObjList; r != NULL;) {
555-
ref = ppxref_find (xref, (ppuint) r->objnum);
556-
obj = ppref_obj(ref);
557-
if (obj->type == PPSTREAM) {
558-
pdf_begin_obj(pdf, r->num, OBJSTM_NEVER);
555+
if (xref != NULL) {
556+
ref = ppxref_find(xref, (ppuint) r->objnum);
557+
if (ref != NULL) {
558+
obj = ppref_obj(ref);
559+
if (obj->type == PPSTREAM) {
560+
pdf_begin_obj(pdf, r->num, OBJSTM_NEVER);
561+
} else {
562+
pdf_begin_obj(pdf, r->num, 2);
563+
}
564+
copyObject(pdf, pdf_doc, obj);
565+
pdf_end_obj(pdf);
566+
} else {
567+
formatted_warning("pdf inclusion","ignoring missing object %i, case 1\n",(int) r->objnum);
568+
}
559569
} else {
560-
pdf_begin_obj(pdf, r->num, 2);
570+
formatted_warning("pdf inclusion","ignoring missing object %i, case 2\n",(int) r->objnum);
561571
}
562-
copyObject(pdf, pdf_doc, obj);
563-
pdf_end_obj(pdf);
564572
n = r->next;
565573
free(r);
566574
r = n;
@@ -995,19 +1003,25 @@ int write_epdf_object(PDF pdf, image_dict * idict, int n)
9951003
} else {
9961004
PdfDocument * pdf_doc = refPdfDocument(img_filepath(idict), FE_FAIL, img_userpassword(idict), img_ownerpassword(idict));
9971005
ppdoc * pdfe = pdf_doc->pdfe;
998-
ppref * ref = ppxref_find(ppdoc_xref(pdfe), (ppuint) n);
999-
if (ref != NULL) {
1000-
ppobj *obj;
1001-
num = pdf->obj_count++;
1002-
obj = ppref_obj(ref);
1003-
if (obj->type == PPSTREAM) {
1004-
pdf_begin_obj(pdf, num, OBJSTM_NEVER);
1006+
if (ppdoc_xref(pdfe)) {
1007+
ppref * ref = ppxref_find(ppdoc_xref(pdfe), (ppuint) n);
1008+
if (ref != NULL) {
1009+
ppobj *obj;
1010+
num = pdf->obj_count++;
1011+
obj = ppref_obj(ref);
1012+
if (obj->type == PPSTREAM) {
1013+
pdf_begin_obj(pdf, num, OBJSTM_NEVER);
1014+
} else {
1015+
pdf_begin_obj(pdf, num, 2);
1016+
}
1017+
copyObject(pdf, pdf_doc, obj);
1018+
pdf_end_obj(pdf);
1019+
writeRefs(pdf, pdf_doc);
10051020
} else {
1006-
pdf_begin_obj(pdf, num, 2);
1021+
formatted_warning("pdf inclusion","ignoring missing image %i, case 1\n",(int) n);
10071022
}
1008-
copyObject(pdf, pdf_doc, obj);
1009-
pdf_end_obj(pdf);
1010-
writeRefs(pdf, pdf_doc);
1023+
} else {
1024+
formatted_warning("pdf inclusion","ignoring missing image %i, case 2\n",(int) n);
10111025
}
10121026
if (! img_keepopen(idict)) {
10131027
unrefPdfDocument(img_filepath(idict));

texk/web2c/luatexdir/lua/lpdfelib.c

Lines changed: 59 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ static int pushstreamonly(lua_State * L, ppstream * stream)
367367

368368
static int pushreference(lua_State * L, ppref * reference)
369369
{
370-
if (reference != NULL) {
370+
if (reference != NULL && reference->number != 0) {
371371
pdfe_push_reference;
372372
lua_pushinteger(L,reference->number);
373373
return 2;
@@ -502,8 +502,10 @@ static int pdfelib_getfromarray(lua_State * L)
502502
int index = luaL_checkint(L, 2) - 1;
503503
if (index < a->array->size) {
504504
ppobj *object = pparray_at(a->array,index);
505-
lua_pushinteger(L,(int) object->type);
506-
return 1 + pushvalue(L,object);
505+
if (object != NULL) {
506+
lua_pushinteger(L,(int) object->type);
507+
return 1 + pushvalue(L,object);
508+
}
507509
}
508510
}
509511
return 0;
@@ -524,10 +526,12 @@ static int pdfelib_getfromdictionary(lua_State * L)
524526
int index = luaL_checkint(L, 2) - 1;
525527
if (index < d->dictionary->size) {
526528
ppobj *object = ppdict_at(d->dictionary,index);
527-
ppname key = ppdict_key(d->dictionary,index);
528-
lua_pushstring(L,(const char *) key);
529-
lua_pushinteger(L,(int) object->type);
530-
return 2 + pushvalue(L,object);
529+
if (object != NULL) {
530+
ppname key = ppdict_key(d->dictionary,index);
531+
lua_pushstring(L,(const char *) key);
532+
lua_pushinteger(L,(int) object->type);
533+
return 2 + pushvalue(L,object);
534+
}
531535
}
532536
}
533537
}
@@ -550,10 +554,12 @@ static int pdfelib_getfromstream(lua_State * L)
550554
int index = luaL_checkint(L, 2) - 1;
551555
if (index < d->size) {
552556
ppobj *object = ppdict_at(d,index);
553-
ppname key = ppdict_key(d,index);
554-
lua_pushstring(L,(const char *) key);
555-
lua_pushinteger(L,(int) object->type);
556-
return 2 + pushvalue(L,object);
557+
if (object != NULL) {
558+
ppname key = ppdict_key(d,index);
559+
lua_pushstring(L,(const char *) key);
560+
lua_pushinteger(L,(int) object->type);
561+
return 2 + pushvalue(L,object);
562+
}
557563
}
558564
}
559565
}
@@ -622,14 +628,17 @@ static int pdfelib_arraytotable(lua_State * L)
622628
if (a != NULL) {
623629
int flat = lua_isboolean(L,2);
624630
int i = 0;
631+
int j = 0;
625632
lua_createtable(L,i,0);
626633
/* table */
627634
for (i=0;i<a->array->size;i++) {
628635
ppobj *object = pparray_at(a->array,i);
629-
pdfelib_totable(L,object,flat);
630-
/* table { type, [value], [extra], [more] } */
631-
lua_rawseti(L,-2,i+1);
632-
/* table[i] = { type, [value], [extra], [more] } */
636+
if (object != NULL) {
637+
pdfelib_totable(L,object,flat);
638+
/* table { type, [value], [extra], [more] } */
639+
lua_rawseti(L,-2,++j);
640+
/* table[i] = { type, [value], [extra], [more] } */
641+
}
633642
}
634643
return 1;
635644
}
@@ -646,13 +655,15 @@ static int pdfelib_dictionarytotable(lua_State * L)
646655
/* table */
647656
for (i=0;i<d->dictionary->size;i++) {
648657
ppobj *object = ppdict_at(d->dictionary,i);
649-
ppname key = ppdict_key(d->dictionary,i);
650-
lua_pushstring(L,(const char *) key);
651-
/* table key */
652-
pdfelib_totable(L,object,flat);
653-
/* table key { type, [value], [extra], [more] } */
654-
lua_rawset(L,-3);
655-
/* table[key] = { type, [value], [extra] } */
658+
if (object != NULL) {
659+
ppname key = ppdict_key(d->dictionary,i);
660+
lua_pushstring(L,(const char *) key);
661+
/* table key */
662+
pdfelib_totable(L,object,flat);
663+
/* table key { type, [value], [extra], [more] } */
664+
lua_rawset(L,-3);
665+
/* table[key] = { type, [value], [extra] } */
666+
}
656667
}
657668
return 1;
658669
}
@@ -676,22 +687,25 @@ static int pdfelib_pagestotable(lua_State * L)
676687
ppdoc *d = p->document;
677688
ppref *r = NULL;
678689
int i = 0;
690+
int j = 0;
679691
lua_createtable(L,ppdoc_page_count(d),0);
680692
/* pages[1..n] */
681693
for (r = ppdoc_first_page(d), i = 1; r != NULL; r = ppdoc_next_page(d), ++i) {
682694
lua_createtable(L,3,0);
683-
pushdictionary(L,ppref_obj(r)->dict);
684-
/* table dictionary n */
685-
lua_rawseti(L,-3,2);
686-
/* table dictionary */
687-
lua_rawseti(L,-2,1);
688-
/* table */
689-
lua_pushinteger(L,r->number);
690-
/* table reference */
691-
lua_rawseti(L,-2,3);
692-
/* table */
693-
lua_rawseti(L,-2,i);
694-
/* pages[i] = { dictionary, size, objnum } */
695+
if (ppref_obj(r) != NULL) {
696+
pushdictionary(L,ppref_obj(r)->dict);
697+
/* table dictionary n */
698+
lua_rawseti(L,-3,2);
699+
/* table dictionary */
700+
lua_rawseti(L,-2,1);
701+
/* table */
702+
lua_pushinteger(L,r->number);
703+
/* table reference */
704+
lua_rawseti(L,-2,3);
705+
/* table */
706+
lua_rawseti(L,-2,++j);
707+
/* pages[i] = { dictionary, size, objnum } */
708+
}
695709
}
696710
return 1;
697711
}
@@ -1158,10 +1172,15 @@ static int pdfelib_getbox(lua_State * L)
11581172
static int pdfelib_getfromreference(lua_State * L)
11591173
{
11601174
pdfe_reference *r = check_isreference(L, 1);
1161-
if (r != NULL) {
1162-
ppobj *o = ppref_obj(ppxref_find(r->xref, (ppuint) r->onum));
1163-
lua_pushinteger(L,o->type);
1164-
return 1 + pushvalue(L,o);
1175+
if (r != NULL && r->xref != NULL) {
1176+
ppref *rr = ppxref_find(r->xref, (ppuint) r->onum);
1177+
if (rr != NULL) {
1178+
ppobj *o = ppref_obj(rr);
1179+
if (o != NULL) {
1180+
lua_pushinteger(L,o->type);
1181+
return 1 + pushvalue(L,o);
1182+
}
1183+
}
11651184
}
11661185
return 0;
11671186
}
@@ -1213,8 +1232,8 @@ static int pdfelib_getfromreference(lua_State * L)
12131232
*/
12141233

12151234
# define pdfelib_get_indirect_o(p) \
1216-
ppref *r = ppxref_find(((pdfe_reference *) p)->xref, (ppuint) (((pdfe_reference *) p)->onum)); \
1217-
ppobj *o = ppref_obj(r); \
1235+
ppref *r = (((pdfe_reference *) p)->xref != NULL) ? ppxref_find(((pdfe_reference *) p)->xref, (ppuint) (((pdfe_reference *) p)->onum)) : NULL; \
1236+
ppobj *o = (r != NULL) ? ppref_obj(r) : NULL; \
12181237

12191238
# define pdfelib_get_value_direct(get_d,get_a) do { \
12201239
int t = lua_type(L,2); \
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
#define luatex_svn_revision 7116
1+
#define luatex_svn_revision 7119

0 commit comments

Comments
 (0)