summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKen Sharp <ken.sharp@artifex.com>2022-01-20 10:56:28 +0000
committerKen Sharp <ken.sharp@artifex.com>2022-01-20 12:19:21 +0000
commit0294d0c6937fc6fcc6eeed86fcba4679ffeea5fc (patch)
treee2bf09aadeb28aee79b738b6c94b4f4ecd93bc26
parent47b3cf18f08c7d6258b773572723b80c6405ffae (diff)
downloadghostpdl-0294d0c6937fc6fcc6eeed86fcba4679ffeea5fc.tar.gz
Check the return values from setting up the Default colour and QState
When running a stream (XObject, type 3 character etc) we may need to set up the DefaultGray etc colour spaces and we may need to set up a graphics state which differs from the current one. We were not checking the return code from the functions performing these tasks. In this case, if we cannot set up the required state, we simply abandon the stream (it probably wouldn't be correct anyway)
-rw-r--r--pdf/pdf_int.c29
1 files changed, 23 insertions, 6 deletions
diff --git a/pdf/pdf_int.c b/pdf/pdf_int.c
index e98bc1f66..a983ee3d2 100644
--- a/pdf/pdf_int.c
+++ b/pdf/pdf_int.c
@@ -1787,8 +1787,8 @@ void initialise_stream_save(pdf_context *ctx)
int pdfi_run_context(pdf_context *ctx, pdf_stream *stream_obj,
pdf_dict *page_dict, bool stoponerror, const char *desc)
{
- int code;
- gs_gstate *DefaultQState;
+ int code = 0, code1 = 0;
+ gs_gstate *DefaultQState = NULL;
/* Save any existing Default* colour spaces */
gs_color_space *PageDefaultGray = ctx->page.DefaultGray_cs;
gs_color_space *PageDefaultRGB = ctx->page.DefaultRGB_cs;
@@ -1805,12 +1805,29 @@ int pdfi_run_context(pdf_context *ctx, pdf_stream *stream_obj,
/* If the stream has any Default* colour spaces, replace the page level ones.
* This will derement the reference counts to the current spaces if they are replaced.
*/
- pdfi_setup_DefaultSpaces(ctx, stream_obj->stream_dict);
+ code = pdfi_setup_DefaultSpaces(ctx, stream_obj->stream_dict);
+ if (code < 0)
+ goto exit;
+
+ code = pdfi_copy_DefaultQState(ctx, &DefaultQState);
+ if (code < 0)
+ goto exit;
+
+ code = pdfi_set_DefaultQState(ctx, ctx->pgs);
+ if (code < 0)
+ goto exit;
- pdfi_copy_DefaultQState(ctx, &DefaultQState);
- pdfi_set_DefaultQState(ctx, ctx->pgs);
code = pdfi_interpret_inner_content_stream(ctx, stream_obj, page_dict, stoponerror, desc);
- pdfi_restore_DefaultQState(ctx, &DefaultQState);
+
+ code1 = pdfi_restore_DefaultQState(ctx, &DefaultQState);
+ if (code >= 0)
+ code = code1;
+
+exit:
+ if (DefaultQState != NULL) {
+ gs_gstate_free(DefaultQState);
+ DefaultQState = NULL;
+ }
/* Count down any Default* colour spaces */
rc_decrement(ctx->page.DefaultGray_cs, "pdfi_run_context");