[gs-cvs] rev 7763 - trunk/gs/src

raph at ghostscript.com raph at ghostscript.com
Sun Mar 4 21:30:39 PST 2007


Author: raph
Date: 2007-03-04 21:30:38 -0800 (Sun, 04 Mar 2007)
New Revision: 7763

Modified:
   trunk/gs/src/zfdctd.c
Log:
Make sure that memory for jpeg_decompress_data gets allocated from the
same memory as the stream structure that owns it. Previously, the
stream structure would be allocated in global, and the jddp in stable
local, which is a violation of GC invariants. Fixes bug 689118, which
was a GC crash in the regression file H00216q.pdf.


Modified: trunk/gs/src/zfdctd.c
===================================================================
--- trunk/gs/src/zfdctd.c	2007-03-04 21:31:28 UTC (rev 7762)
+++ trunk/gs/src/zfdctd.c	2007-03-05 05:30:38 UTC (rev 7763)
@@ -31,13 +31,27 @@
 /* Import the parameter processing procedure from sddparam.c */
 stream_state_proc_put_params(s_DCTD_put_params, stream_DCT_state);
 
+/* Find the memory that will be used for allocating the stream. */
+private gs_ref_memory_t *
+find_stream_memory(i_ctx_t *i_ctx_p, int npop, uint space)
+{
+    uint use_space = max(space, avm_global);
+    os_ptr sop = osp - npop;
+
+    if (r_has_type(sop, t_dictionary)) {
+	--sop;
+    }
+    use_space = max(use_space, r_space(sop));
+    return idmemory->spaces_indexed[use_space >> r_space_shift];
+}
+
 /* <source> <dict> DCTDecode/filter <file> */
 /* <source> DCTDecode/filter <file> */
 private int
 zDCTD(i_ctx_t *i_ctx_p)
 {
     os_ptr op = osp;
-    gs_memory_t *mem = gs_memory_stable(imemory);
+    gs_memory_t *mem;
     stream_DCT_state state;
     dict_param_list list;
     jpeg_decompress_data *jddp;
@@ -45,6 +59,11 @@
     const ref *dop;
     uint dspace;
 
+    if (r_has_type(op, t_dictionary))
+	dop = op, dspace = r_space(op);
+    else
+	dop = 0, dspace = 0;
+    mem = (gs_memory_t *)find_stream_memory(i_ctx_p, 0, dspace);
     /* First allocate space for IJG parameters. */
     jddp = gs_alloc_struct_immovable(mem,jpeg_decompress_data,
       &st_jpeg_decompress_data, "zDCTD");
@@ -59,10 +78,6 @@
     if ((code = gs_jpeg_create_decompress(&state)) < 0)
 	goto fail;		/* correct to do jpeg_destroy here */
     /* Read parameters from dictionary */
-    if (r_has_type(op, t_dictionary))
-	dop = op, dspace = r_space(op);
-    else
-	dop = 0, dspace = 0;
     if ((code = dict_param_list_read(&list, dop, NULL, false, iimemory)) < 0)
 	goto fail;
     if ((code = s_DCTD_put_params((gs_param_list *) & list, &state)) < 0)



More information about the gs-cvs mailing list