[gs-code-review] Recovering from incorrect Encode length.

Alex Cherepanov alexcher at quadnet.net
Mon Oct 30 20:32:30 PST 2006


Many gradients in the CET test use Type 3 function with incorrect
Encoding array - 2 elements long instead of 4. Adobe Interpreters
appear to pad the missing elements with 0 (judging from the picture),
although Distiller 5 is indeterministic.

This problem affects
09-47h -> partial
09-47i -> fixed
09-47j -> partial
09-47k -> partial
09-47l -> partial
09-47m -> partial
12-14L -> fixed
12-14m -> partial, fixes all errors, but CPSI fails once
12-14n -> fixed
12-14o -> partial
12-14q -> fixed

I cannot figure out why a single function for /DeviceGray color space is
accepted, but a vector of 3 functions for DeviceRGB is not. See the
case 12-14m for details.
-------------- next part --------------
Index: gs/src/zfunc3.c
===================================================================
--- gs/src/zfunc3.c	(revision 7132)
+++ gs/src/zfunc3.c	(working copy)
@@ -96,10 +96,34 @@
 		goto fail;
 	}
     }
-    if ((code = fn_build_float_array(op, "Bounds", true, false, &params.Bounds, mem)) != params.k - 1 ||
-	(code = fn_build_float_array(op, "Encode", true, true, &params.Encode, mem)) != 2 * params.k
-	)
+    if ((code = fn_build_float_array(op, "Bounds", true, false, &params.Bounds, mem)) != params.k - 1 )
 	goto fail;
+    { /* Adobe implementation doesn't check the Encode length. */
+      /* Extra elements are ignored; missing elements are filled with 0. */
+      /* CET 12-14m.ps depends on this bug */
+      uint sz, k2 = 2 * params.k;
+      ref *encode;
+      float *p = (float *)gs_alloc_byte_array(mem, k2, sizeof(float), "Encode");
+      params.Encode = p;
+      if (p == 0) {
+          code = gs_note_error(e_VMerror);
+          goto fail;
+      }
+      if (dict_find_string(op, "Encode", &encode) <= 0) {
+          code = gs_note_error(e_undefined);
+          goto fail;
+      }
+      if (!r_is_array(encode)) {
+          code = gs_note_error(e_typecheck);
+          goto fail;
+      }
+      sz =  min(k2, r_size(encode));
+      code = process_float_array(mem, encode, sz, p);
+      while (sz < k2)
+        p[sz++] = 0.;
+      if (code < 0)
+          goto fail;
+    }
     if (params.Range == 0)
 	params.n = params.Functions[0]->params.n;
     code = gs_function_1ItSg_init(ppfn, &params, mem);


More information about the gs-code-review mailing list