summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKen Sharp <ken.sharp@artifex.com>2018-08-27 11:15:16 +0100
committerKen Sharp <ken.sharp@artifex.com>2018-08-27 11:24:10 +0100
commitea735ba37dc0fd5f5622d031830b9a559dec1cc9 (patch)
tree093a32332728ba1b015073b18b82deb43c29c6c1
parent79cccf641486a6595c43f1de1cd7ade696020a31 (diff)
Fix error condition for SC and CS
The SC and CS PDF operators correctly checked the return code from the underlying setcolor and setcolorspace code, but we had already set up the exec stack for handling a non-error return. We have to do this before calling the underlying code, as that also uses a state machine, and alters the exec stack. We must push our own execution context first. Ordinarily this isn't a problem, but if we have a custom error handler which doesn't stop the interpreter, then we would continue on to try and use what we'd pushed onto the exec stack, with predictably dire results. Here we avoid this by saving the exec stack pointer on entry, and if an error occurs, restoring back to that point before returning control to the PostScript interpreter. A minor point, but we now also reset the space/color on an error as well, previously it would have been left with the wrong space set.
-rw-r--r--psi/zcolor.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/psi/zcolor.c b/psi/zcolor.c
index e27baf988..853cee1eb 100644
--- a/psi/zcolor.c
+++ b/psi/zcolor.c
@@ -6611,6 +6611,7 @@ static int
6611zsetstrokecolor(i_ctx_t * i_ctx_p) 6611zsetstrokecolor(i_ctx_t * i_ctx_p)
6612{ 6612{
6613 int code; 6613 int code;
6614 es_ptr iesp = esp; /* preserve exec stack in case of error */
6614 6615
6615 code = zswapcolors(i_ctx_p); 6616 code = zswapcolors(i_ctx_p);
6616 if (code < 0) 6617 if (code < 0)
@@ -6627,6 +6628,9 @@ zsetstrokecolor(i_ctx_t * i_ctx_p)
6627 if (code >= 0) 6628 if (code >= 0)
6628 return o_push_estack; 6629 return o_push_estack;
6629 6630
6631 /* Something went wrong, swap back to the non-stroking colour and restore the exec stack */
6632 esp = iesp;
6633 (void)zswapcolors(i_ctx_p);
6630 return code; 6634 return code;
6631} 6635}
6632static int 6636static int
@@ -6638,6 +6642,7 @@ static int
6638zsetstrokecolorspace(i_ctx_t * i_ctx_p) 6642zsetstrokecolorspace(i_ctx_t * i_ctx_p)
6639{ 6643{
6640 int code; 6644 int code;
6645 es_ptr iesp = esp; /* preserve exec stack in case of error */
6641 6646
6642 code = zswapcolors(i_ctx_p); 6647 code = zswapcolors(i_ctx_p);
6643 if (code < 0) 6648 if (code < 0)
@@ -6653,6 +6658,9 @@ zsetstrokecolorspace(i_ctx_t * i_ctx_p)
6653 if (code >= 0) 6658 if (code >= 0)
6654 return o_push_estack; 6659 return o_push_estack;
6655 6660
6661 /* Something went wrong, swap back to the non-stroking space and restore the exec stack */
6662 esp = iesp;
6663 (void)zswapcolors(i_ctx_p);
6656 return code; 6664 return code;
6657} 6665}
6658 6666