gpt4 book ai didi

GhostScript:错误:/invalidfileaccess in --file--

转载 作者:行者123 更新时间:2023-12-03 14:11:54 25 4
gpt4 key购买 nike

如果我尝试包含已知路径之外的文件,则会出现众所周知的错误:

Error: /invalidfileaccess in --file--

我知道我可以使用 -DNOSAFER但我想避免这种情况,因为这将允许执行恶意代码。

是否可以选择告诉 gs “您可以读取任何文件,但不得移除或删除任何文件”?

最佳答案

(Answer duplicated from gGt an output file with a count of PDF pages for each file with Ghostscript; both these SO issues popped up while I was looking for a solution myself and no dice. :'-( )



请注意,从 GhostScript 9.50 开始,默认情况下已开启 SAFER 模式,导致 /invalidfileaccess像这样的错误,通过确保路径中的所有目录分隔符都是 / 不会消失。正斜杠,摆弄当前路径等。

这让我今天花了很多时间和几个小时,但是 2020 年你需要做这样的事情:

解决方案 1:使用 --permit-file-read=<path> 将源路径添加到接受列表中制作 /invalidfileaccess离开
gs -q --permit-file-read=d:/ -dNODISPLAY -c "(d:/test.pdf) (r) file runpdfbegin pdfpagecount = quit"


即确保您在 PostScript 命令/脚本中加载的 PDF 的路径在批准列表中,即权限列表, using one of the --permit-file-xyz commandline arguments .

解决方案 2:使用 -I<path> 快速破解制作 /invalidfileaccess离开
gs -q -Id:/ -dNODISPLAY -c "(d:/test.pdf) (r) file runpdfbegin pdfpagecount = quit"


即确保您在 PostScript 命令/脚本中加载的 PDF 的路径在批准列表中,即权限列表。
-Id:/在上面的例子中只是一个快速的技巧,以确保您的路径的源路径在该列表中,考虑到这一点 from the official documentation :

Finally, paths supplied on the command line (such as those in -I, -sFONTPATH parameters) are added to the permitted reading list. Similarly, paths read during initialisation from Fontmap, cidfmap, and the platform specific font file enumeration (e.g. fontconfig on Unix systems) are automatically added to the permit read lists.



注意/抛开使用时的期望 -I像那样:

对我来说另一个惊喜是

gs -q  -I d:/ -dNODISPLAY -c "(test.pdf) (r) file runpdfbegin pdfpagecount = quit"

即在 -I 中指定 PDF 的源路径包含 set 然后在 PostScript 命令中省略它, 仍然给了我一个 /invalidfileaccess所以一定要指定一个正确的 绝对路径 对于您正在加载的 PDF。

笔记

适用于 PostScript 脚本,而不是 -f命令行

此问题仅发生在 -c 中的文件加载中PostScript 命令,而不是使用 -f <file> 在命令行上直接指定的 PDF/PS 源文件.

如何检查这是否是您的实际问题

测试 1:在没有额外的情况下尝试相同的 -I<path>--permit-file-read=<path> : 错误返回吗?如果是,那么宾果游戏!

当这个命令行(注意缺少的 -Id:/--permit-file-read=d:/ 是唯一的变化):
gs -q -dNODISPLAY -c "(d:/test.pdf) (r) file runpdfbegin pdfpagecount = quit"

为您提供“无效文件访问”错误,如下所示:
   Error: /invalidfileaccess in --file--
Operand stack:
(d:/test.pdf) (r)
Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval--
Dictionary stack:
--dict:737/1123(ro)(G)-- --dict:0/20(G)-- --dict:75/200(L)--
Current allocation mode is local
Last OS error: Permission denied
GPL Ghostscript 9.52: Unrecoverable error, exit code 1

比你很可能有 a -dSAFER problem这是通过上述添加的 修复的PDF源目录到接受的路径列表(另见 the GhostScript documentation at 'NOSAFER' 及以后,包括关于 --permit-file-read=pathlist 等人的部分。

测试 2:当您使用 -dNOSAFER 运行时,问题是否会消失? ?如果是,那么宾果游戏!

当这个命令行:
gs -q -dNOSAFER -dNODISPLAY -c "(d:/test.pdf) (r) file runpdfbegin pdfpagecount = quit"

工作正常,那么这是一个肯定的迹象,您需要上述任何一种解决方案来摆脱 /invalidfileaccess错误。

警告:您在网上找到的旧答案可能不再适用

正如我在 SO 和其他地方看到的很多讨论一样,包括各种错误跟踪器,似乎没有人在任何地方提到这一点,因为所有这些页面/条目都来自 GhostScript 9.50 和 2019AD 版之前。

报价 from the 9.50 change notes :

The file access control capability (enable with -dSAFER) has been completely rewritten, with a ground-up rethink of the design. For more details, see: SAFER.

It is important to note that -dSAFER now only enables the file access controls, and no longer applies restrictions to standard Postscript functionality (specifically, restrictions on setpagedevice). If your application relies on these Postscript restrictions, see OLDSAFER, and please get in touch, as we do plan to remove those Postscript restrictions unless we have reason not to.

IMPORTANT: File access controls are now enabled by default. In order to run Ghostscript without these controls, see NOSAFER

Important Note for Windows Users: See below under Incompatible Changes


SAFER更改时间为 2019-09-30(9.50 版)

关于GhostScript:错误:/invalidfileaccess in --file--,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40156190/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com