[gs-code-review] CET 20-02-02, handling of dictstackoverflow

Alex Cherepanov alexcher at quadnet.net
Sun Feb 18 17:02:42 PST 2007


Following Adobe implementation and CET 20-02-02, don't restore the
operand that caused dictionary stack overflow and exclude standard
3 dictionaries from the saved stack array.

DIFFERENCES:
None: no CET or copmparefiles differences.

The most uncertain part of the patch is overwriting the top of the
operand stack.


-------------- next part --------------
Index: gs/src/interp.c
===================================================================
--- gs/src/interp.c	(revision 7709)
+++ gs/src/interp.c	(working copy)
@@ -131,7 +131,7 @@
 private int interp(i_ctx_t **, const ref *, ref *);
 private int interp_exit(i_ctx_t *);
 private void set_gc_signal(i_ctx_t *, int *, int);
-private int copy_stack(i_ctx_t *, const ref_stack_t *, ref *);
+private int copy_stack(i_ctx_t *, const ref_stack_t *, int skip, ref *);
 private int oparray_pop(i_ctx_t *);
 private int oparray_cleanup(i_ctx_t *);
 private int zerrorexec(i_ctx_t *);
@@ -549,12 +549,13 @@
 		if ((ccode = ref_stack_extend(&o_stack, 1)) < 0)
 		    return ccode;
 	    }
-	    ccode = copy_stack(i_ctx_p, &d_stack, &saref);
+            /* Skip system dictionaries for CET 20-02-02 */
+	    ccode = copy_stack(i_ctx_p, &d_stack, min_dstack_size, &saref);
 	    if (ccode < 0)
 		return ccode;
 	    ref_stack_pop_to(&d_stack, min_dstack_size);
 	    dict_set_top();
-	    *++osp = saref;
+	    *osp = saref; /* overwrite the top element */
 	    break;
 	case e_dictstackunderflow:
 	    if (ref_stack_pop_block(&d_stack) >= 0) {
@@ -573,7 +574,7 @@
 		if ((ccode = ref_stack_extend(&o_stack, 1)) < 0)
 		    return ccode;
 	    }
-	    ccode = copy_stack(i_ctx_p, &e_stack, &saref);
+	    ccode = copy_stack(i_ctx_p, &e_stack, 0, &saref);
 	    if (ccode < 0)
 		return ccode;
 	    {
@@ -613,7 +614,7 @@
 		epref = &doref;
 		goto again;
 	    }
-	    ccode = copy_stack(i_ctx_p, &o_stack, &saref);
+	    ccode = copy_stack(i_ctx_p, &o_stack, 0, &saref);
 	    if (ccode < 0)
 		return ccode;
 	    ref_stack_clear(&o_stack);
@@ -685,9 +686,9 @@
 
 /* Copy the contents of an overflowed stack into a (local) array. */
 private int
-copy_stack(i_ctx_t *i_ctx_p, const ref_stack_t * pstack, ref * arr)
+copy_stack(i_ctx_t *i_ctx_p, const ref_stack_t * pstack, int skip, ref * arr)
 {
-    uint size = ref_stack_count(pstack);
+    uint size = ref_stack_count(pstack) - skip;
     uint save_space = ialloc_space(idmemory);
     int code;
 



More information about the gs-code-review mailing list