summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--psi/zdevice2.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/psi/zdevice2.c b/psi/zdevice2.c
index 5447c8c84..159a0c0d9 100644
--- a/psi/zdevice2.c
+++ b/psi/zdevice2.c
@@ -278,8 +278,8 @@ restore_page_device(i_ctx_t *i_ctx_p, const gs_gstate * pgs_old, const gs_gstate
278 } 278 }
279 279
280 if (LockSafetyParams && !samepagedevice) { 280 if (LockSafetyParams && !samepagedevice) {
281 os_ptr op = osp; 281 const int required_ops = 512;
282 const int max_ops = 512; 282 const int required_es = 32;
283 283
284 /* The %grestorepagedevice must complete: the biggest danger 284 /* The %grestorepagedevice must complete: the biggest danger
285 is operand stack overflow. As we use get/putdeviceparams 285 is operand stack overflow. As we use get/putdeviceparams
@@ -289,9 +289,16 @@ restore_page_device(i_ctx_t *i_ctx_p, const gs_gstate * pgs_old, const gs_gstate
289 424 entries on the op stack. Allowing for working stack 289 424 entries on the op stack. Allowing for working stack
290 space, and safety margin..... 290 space, and safety margin.....
291 */ 291 */
292 if (max_ops > op - osbot) { 292 if (required_ops + ref_stack_count(&o_stack) >= ref_stack_max_count(&o_stack)) {
293 if (max_ops >= ref_stack_count(&o_stack)) 293 gs_currentdevice(pgs_old)->LockSafetyParams = LockSafetyParams;
294 return_error(gs_error_stackoverflow); 294 return_error(gs_error_stackoverflow);
295 }
296 /* We also want enough exec stack space - 32 is an overestimate of
297 what we need to complete the Postscript call out.
298 */
299 if (required_es + ref_stack_count(&e_stack) >= ref_stack_max_count(&e_stack)) {
300 gs_currentdevice(pgs_old)->LockSafetyParams = LockSafetyParams;
301 return_error(gs_error_execstackoverflow);
295 } 302 }
296 } 303 }
297 /* 304 /*