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)
downloadghostpdl-ea735ba37dc0fd5f5622d031830b9a559dec1cc9.tar.gz
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
zsetstrokecolor(i_ctx_t * i_ctx_p)
{
int code;
+ es_ptr iesp = esp; /* preserve exec stack in case of error */
code = zswapcolors(i_ctx_p);
if (code < 0)
@@ -6627,6 +6628,9 @@ zsetstrokecolor(i_ctx_t * i_ctx_p)
if (code >= 0)
return o_push_estack;
+ /* Something went wrong, swap back to the non-stroking colour and restore the exec stack */
+ esp = iesp;
+ (void)zswapcolors(i_ctx_p);
return code;
}
static int
@@ -6638,6 +6642,7 @@ static int
zsetstrokecolorspace(i_ctx_t * i_ctx_p)
{
int code;
+ es_ptr iesp = esp; /* preserve exec stack in case of error */
code = zswapcolors(i_ctx_p);
if (code < 0)
@@ -6653,6 +6658,9 @@ zsetstrokecolorspace(i_ctx_t * i_ctx_p)
if (code >= 0)
return o_push_estack;
+ /* Something went wrong, swap back to the non-stroking space and restore the exec stack */
+ esp = iesp;
+ (void)zswapcolors(i_ctx_p);
return code;
}