Bug 692105 - limitcheck in setcolorspace with more then 14 Colors defined in DeviceN
Summary: limitcheck in setcolorspace with more then 14 Colors defined in DeviceN
Status: NOTIFIED FIXED
Alias: None
Product: Ghostscript
Classification: Unclassified
Component: Color (show other bugs)
Version: master
Hardware: PC Windows XP
: P2 normal
Assignee: Alex Cherepanov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-03-29 10:02 UTC by Thomas
Modified: 2014-02-17 04:44 UTC (History)
2 users (show)

See Also:
Customer: 582
Word Size: ---


Attachments
Handy PS example (475 bytes, application/postscript)
2011-03-29 10:02 UTC, Thomas
Details
PS example distilled to PDF (9.00 KB, application/pdf)
2011-03-29 10:02 UTC, Thomas
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas 2011-03-29 10:02:13 UTC
Created attachment 7401 [details]
Handy PS example

Current Head (RELEASE CANDIDATE 9.02) produces an error "/limitcheck in --setcolorspace--" when a DeviceN Colorspace contains more then 14 color components.

This seems to happen with all Devices.

I checked this against Acrobat Distiller and several other Rip´s. In the PLRM, Page 739, "TABLE B.1 Architectural limits" it says "Maximum number of separations, colorants, or color components in DeviceN color space".

Attached there are 2 files, one quick handwritten PS and the resulting PDF from Distiller. Both pdf and ps produce the same error with gs.


GPL Ghostscript RELEASE CANDIDATE 9.02 (2011-03-28)
Copyright (C) 2010 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Error: /limitcheck in --setcolorspace--
Operand stack:
   --nostringval--
Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval-
-   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   fa
lse   1   %stopped_push   1910   1   3   %oparray_pop   1909   1   3   %oparray_
pop   1893   1   3   %oparray_pop   1787   1   3   %oparray_pop   --nostringval-
-   %errorexec_pop   .runexec2   --nostringval--   --nostringval--   --nostringv
al--   2   %stopped_push   --nostringval--
Dictionary stack:
   --dict:1157/1684(ro)(G)--   --dict:0/20(G)--   --dict:77/200(L)--
Current allocation mode is local
Last OS error: No such file or directory
Current file position is 385
GPL Ghostscript RELEASE CANDIDATE 9.02: Unrecoverable error, exit code 1
Close this window with the close button on the title bar or the system menu.
Comment 1 Thomas 2011-03-29 10:02:58 UTC
Created attachment 7402 [details]
PS example distilled to PDF
Comment 2 Michael Vrhel 2011-05-19 04:19:13 UTC
Looking into this now.
Comment 3 Ray Johnston 2011-05-19 15:42:32 UTC
Since it isn't commonly used and allowing for large numbers of 'CLIENT_COLOR'
components slightly degrades performance (less now that we don't have the
image clues used in cases where it doesn't make sense), the default limit
is 14.

This is set in base/gsccolor.h:

/*
 * Define the maximum number of components in a client color.
 * This must be at least 4, and should be at least 6 to accommodate
 * hexachrome DeviceN color spaces. We saw 9-component (bug 691002)
 * and 13-component (bug 691425) colors in the wild.
 */
#ifndef GS_CLIENT_COLOR_MAX_COMPONENTS		/* Allow override with XCFLAGS */
#  define GS_CLIENT_COLOR_MAX_COMPONENTS (14)
#endif

This can be overridden by a compiler command line define e.g.
   -DGS_CLIENT_COLOR_MAX_COMPONENTS=252
or by changing the default in gsccolor.h

We have tested (not recently) with values up to 252 which corresponds to a
limit in Adobe CPSI.

On July 27, 2008 we had set it to 8, but that was a little too small for some
users, so on July 6, 2010 we increased it to 14.

If you can provide justification for a default higher than 14, please do so.

In the meantime, please rebuild with the changed value. Note that if you don't actually change the gsccolor.h file, then remove all objects and rebuild since
a compile line define won't affect dependencies.
Comment 4 Michael Vrhel 2011-05-20 00:51:41 UTC
I tested the file in question after bumping the value to 20 and the file rendered correctly.   Closing this one since it is quite rare to run across files with that many spot colors in the wild.  Applications that typically do use gs to handle files like this should compile with a larger value.
Comment 5 Thomas 2011-05-20 08:41:53 UTC
Sorry, I didn´t know the XCFLAGS="-DGS_CLIENT_COLOR_MAX_COMPONENTS=XXX"
Parameter for this.

Recompiling with "-DGS_CLIENT_COLOR_MAX_COMPONENTS=64" works with the Attached PS File but produces an error with the PDF File.

GPL Ghostscript GIT PRERELEASE 9.03 (2011-03-30)
Copyright (C) 2010 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 1.
Page 1
Error: /limitcheck in --.buildfunction--
Operand stack:
   --dict:5/14(L)--   --nostringval--   --nostringval--   --dict:12/12(L)--
Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval-
-   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   fa
lse   1   %stopped_push   1910   1   3   %oparray_pop   1909   1   3   %oparray_
pop   1893   1   3   %oparray_pop   --nostringval--   --nostringval--   2   1
1   --nostringval--   %for_pos_int_continue   --nostringval--   --nostringval--
  --nostringval--   --nostringval--   %array_continue   --nostringval--   false
  1   %stopped_push   --nostringval--   %loop_continue   --nostringval--   --nos
tringval--   --nostringval--
Dictionary stack:
   --dict:1161/1684(ro)(G)--   --dict:1/20(G)--   --dict:82/200(L)--   --dict:82
/200(L)--   --dict:108/127(ro)(G)--   --dict:292/300(ro)(G)--   --dict:23/30(L)-
-   --dict:6/8(L)--   --dict:21/40(L)--
Current allocation mode is local
Last OS error: No such file or directory
GPL Ghostscript GIT PRERELEASE 9.03: Unrecoverable error, exit code 1

Close this window with the close button on the title bar or the system menu.
Comment 6 Michael Vrhel 2011-05-20 12:32:16 UTC
Reopening to look at the why the PDF file is causing a complaint.
Comment 7 Michael Vrhel 2011-07-25 17:44:13 UTC
Assigning to Alex.  The PS file runs fine with the proper adjustment to GS_CLIENT_COLOR_MAX_COMPONENTS.  The PDF file gives a complaint

 **** Error reading a content stream. The page may be incomplete.
 **** File did not complete the page properly and may be damaged.

Running with -dPDFSTOPONERROR errors out with a rangelimit error even
with GS_CLIENT_COLOR_MAX_COMPONENTS set sufficiently high.
Comment 8 Ken Sharp 2011-08-23 12:21:58 UTC
(In reply to comment #7)
> Assigning to Alex.  The PS file runs fine with the proper adjustment to
> GS_CLIENT_COLOR_MAX_COMPONENTS.  The PDF file gives a complaint
> 
>  **** Error reading a content stream. The page may be incomplete.
>  **** File did not complete the page properly and may be damaged.
> 
> Running with -dPDFSTOPONERROR errors out with a rangelimit error even
> with GS_CLIENT_COLOR_MAX_COMPONENTS set sufficiently high.

The PDF file creates a sampled function to convert the DeviceN colour space into the Alternate CMYK space (the original PostScript simply throws the extra channel data away), this trips over a compile-time limit in zfunc.c which defines the maximum number of inputs and outputs for a sampled function:

#define max_Sd_m 16
#define max_Sd_n 16

Changing these to 32 causes the file to run to completion and produces the correct output. I have changed these to be dependent on either a compile-time definition of GS_CLIENT_SAMPLED_FN_MAX_COMPONENTS, or the definition of GS_CLIENT_COLOR_MAX_COMPONENTS if that definition is not present.

So if either a specific definition of sampled functions sizes is defined or the number of spot colours is changed using GS_CLIENT_COLOR_MAX_COMPONENTS or the #define is changed in gxccolor.h, we will allow a larger number of inputs and outputs in sampled functions.

Committed as :
ec7e68e9054c8b1e91f588a358101c24d281555b

Log and patch here:
http://ghostscript.com/pipermail/gs-cvs/2011-August/013319.html