Bug 699722 - Color profiles cannot be read in -dSAFER mode
Summary: Color profiles cannot be read in -dSAFER mode
Status: RESOLVED FIXED
Alias: None
Product: Ghostscript
Classification: Unclassified
Component: Regression (show other bugs)
Version: master
Hardware: PC FreeBSD
: P4 normal
Assignee: Default assignee
QA Contact: Bug traffic
URL:
Keywords:
: 699724 699736 (view as bug list)
Depends on:
Blocks:
 
Reported: 2018-09-05 16:58 UTC by Tijl Coosemans
Modified: 2018-09-06 19:56 UTC (History)
3 users (show)

See Also:
Customer:
Word Size: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tijl Coosemans 2018-09-05 16:58:19 UTC
The following command fails with -dSAFER (infoflow.eps from doxygen source code):

gs -dSAFER -sDEVICE=pdfwrite -sColorConversionStrategy=Gray -dProcessColorModel=/DeviceGray -o test.pdf doc/infoflow.eps

GPL Ghostscript 9.24 (2018-09-03)
Copyright (C) 2018 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
  ./base/gsicc_manage.c:1244: gsicc_open_search(): Could not find default_gray.icc 
| ./base/gsicc_manage.c:2025: gsicc_set_device_profile(): cannot find device profile
  ./base/gsicc_manage.c:1244: gsicc_open_search(): Could not find default_gray.icc 
| ./base/gsicc_manage.c:2025: gsicc_set_device_profile(): cannot find device profile
Unrecoverable error: undefined in setpagedevice
Operand stack:
    true  true  --nostringval--  setpagedevice  --nostringval--  true


The problem is that ghostscript cannot read /usr/local/share/ghostscript/9.24/iccprofiles because it isn't listed in PermitFileReading.  The following hack fixes it, but it's a bit convoluted because ICCProfilesDir has a \000 character at the end.

--- Resource/Init/gs_init.ps.orig	2018-09-03 08:50:27 UTC
+++ Resource/Init/gs_init.ps
@@ -2041,6 +2041,7 @@ readonly def
             % Default resources (OpenVMS, see comment above.) :
           [ currentsystemparams /GenericResourceDir get] (*) .file_name_separator (*)
             concatstrings concatstrings .generate_dir_list_templates
+          currentuserparams /ICCProfilesDir get copystring dup dup length 1 sub (*) putinterval
         } if
       ]
       /PermitFileWriting [
Comment 1 Chris Liddell (chrisl) 2018-09-06 15:55:06 UTC
*** Bug 699736 has been marked as a duplicate of this bug. ***
Comment 2 Chris Liddell (chrisl) 2018-09-06 16:11:58 UTC
*** Bug 699724 has been marked as a duplicate of this bug. ***
Comment 3 Chris Liddell (chrisl) 2018-09-06 16:16:56 UTC
Fixed in:

http://git.ghostscript.com/?p=ghostpdl.git;a=commitdiff;h=c8c01f8c4164


I opted to fix the returned string so it didn't include the terminating NULL - otherwise, same fix - thank you!
Comment 4 Tijl Coosemans 2018-09-06 16:52:12 UTC
(In reply to Chris Liddell (chrisl) from comment #3)
> +        currentuserparams /ICCProfilesDir known {currentuserparams /ICCProfilesDir get} if

That doesn't have * at the end does it?  I think you need this:

currentuserparams /ICCProfilesDir known {[currentuserparams /ICCProfilesDir get] (*) .generate_dir_list_templates} if
Comment 5 Chris Liddell (chrisl) 2018-09-06 17:44:08 UTC
(In reply to Tijl Coosemans from comment #4)
> (In reply to Chris Liddell (chrisl) from comment #3)
> > +        currentuserparams /ICCProfilesDir known {currentuserparams /ICCProfilesDir get} if
> 
> That doesn't have * at the end does it?  I think you need this:
> 
> currentuserparams /ICCProfilesDir known {[currentuserparams /ICCProfilesDir
> get] (*) .generate_dir_list_templates} if

Oops, sorry about that. I'l sort it out in a moment.
Comment 6 Chris Liddell (chrisl) 2018-09-06 18:09:12 UTC
Add in the wildcard character:

http://git.ghostscript.com/?p=ghostpdl.git;a=commitdiff;h=13418541a5ae

Thanks for noticing.
Comment 7 Tijl Coosemans 2018-09-06 19:56:19 UTC
(In reply to Chris Liddell (chrisl) from comment #6)
> http://git.ghostscript.com/?p=ghostpdl.git;a=commitdiff;h=13418541a5ae

I haven't tested it, but I don't think you need to copy the tempfilepaths array.  You can just use:

//tempfilepaths (*) .generate_dir_list_templates