Bug 24492

Summary: gs -dSAFER не дает открывать файлы на чтение
Product: Sisyphus Reporter: Vladislav Zavjalov <slazav>
Component: ghostscriptAssignee: Vitaly Lipatov <lav>
Status: CLOSED NOTABUG QA Contact: qa-sisyphus
Severity: normal    
Priority: P3 CC: george, kirill, lav, vitty
Version: unstable   
Hardware: all   
OS: Linux   
See Also: https://bugzilla.redhat.com/show_bug.cgi?id=1632030

Description Vladislav Zavjalov 2010-11-03 13:22:20 MSK
На всякий случай дублирую сюда из sisyphus@ накопанное, чтоб не потерялось

$ > a.txt
$ echo "(a.txt) (r) file" > a.ps

$ gs -dBATCH -dNODISPLAY a.ps
GPL Ghostscript  9.00 (2010-09-14)
Copyright (C) 2010 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.

$ gs -dBATCH -dNODISPLAY -dSAFER a.ps
GPL Ghostscript  9.00 (2010-09-14)
Copyright (C) 2010 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Error: /invalidfileaccess in --file--
Operand stack:
   (a.txt)   (r)
...

То есть, gs в режиме safer не дает открывать файл на чтение.
(file) run, например, тоже не работает. Хотя, казалось бы, man gs
нам говорит:

-dSAFER Disables  the  "deletefile"  and  "renamefile" operators
 and the ability to open files in any mode other than read-only.

Одно из важных следствий - gv не читает pdf-файлы (они читаются довольно хитро: скрипт pdf2dsc.ps создает некоторый временный ps-файл, который уже читает pdf), так как по дефолту в gv включен режим safer. Соответственно, в качестве временного лечения - помогает отключить кнопку Safer в меню "State/Ghostscript options"...
Comment 1 Vitaly Lipatov 2020-09-20 22:47:35 MSK
(Ответ для Vladislav Zavjalov на комментарий #0)
> На всякий случай дублирую сюда из sisyphus@ накопанное, чтоб не потерялось
> 
> $ > a.txt
> $ echo "(a.txt) (r) file" > a.ps
> 
> $ gs -dBATCH -dNODISPLAY a.ps
> GPL Ghostscript  9.00 (2010-09-14)
> Copyright (C) 2010 Artifex Software, Inc.  All rights reserved.
> This software comes with NO WARRANTY: see the file PUBLIC for details.
> 
> $ gs -dBATCH -dNODISPLAY -dSAFER a.ps
> GPL Ghostscript  9.00 (2010-09-14)
> Copyright (C) 2010 Artifex Software, Inc.  All rights reserved.
> This software comes with NO WARRANTY: see the file PUBLIC for details.
> Error: /invalidfileaccess in --file--
> Operand stack:
>    (a.txt)   (r)
> ...
> 
> То есть, gs в режиме safer не дает открывать файл на чтение.
> (file) run, например, тоже не работает. Хотя, казалось бы, man gs
> нам говорит:
Воспроизводится с -dSAFER. Этот режим нужен для того, чтобы документ ничего не стащил у вас из файловой системы.

Тут ещё есть обсуждение подобного поведения при этом ограничении:
https://bugzilla.redhat.com/show_bug.cgi?id=1632030


> 
> -dSAFER Disables  the  "deletefile"  and  "renamefile" operators
>  and the ability to open files in any mode other than read-only.
Там уже написано так:
...
       -dSAFER
              Restricts  file  operations the job can perform.  Strongly recommended for spoolers, conversion scripts or other sensitive environments where a badly
              written or malicious PostScript program code must be prevented from changing important files.