Patch ShellEscape
Packages such as pdftricks.sty, epstopdf.sty (or pdftex.def)
call external programs. They do not work at all, if the
\write18 feature is not enabled. Therefore a robust method
would be useful in order to inform the user. For security
reasons the \write18 featuer must not be set by TeX macro
code.
Thus the patch introduces a new readonly primitive
\pdfshellescape that expands to "0" if the \write 18 feature
is disabled and "1" in the other case.
Use, for instance:
\ifnum\pdfshellescape=0
\message{The \string\write18 feature is disabled.}
\else
\message{The \string\write18 feature is enabled.}
\fi
Patch files:
pdftex.ch.diff for TeX/texk/web2c/pdftexdir/pdftex.ch
pdfetex.ch2.diff for TeX/texk/web2c/pdfetexdir/pdfetex.ch2
Yours sincerely
Heiko
Patch ShellEscape [...] Patch files: pdftex.ch.diff for TeX/texk/web2c/pdftexdir/pdftex.ch pdfetex.ch2.diff for TeX/texk/web2c/pdfetexdir/pdfetex.ch2
On Thu, Jun 05, 2003 at 09:44:45PM +0200, Heiko Oberdiek wrote:
pdftex-syntax.diff for .../pdftexdir/pdftex-syntax.diff
Sorry I had forgotten the patches.
Yours sincerely
Heiko
Hi pdftex fans, there is some minor loose end within pdftex: Using teTeX-2.0.2 pdflatex (pdfTeX, Version 3.14159-1.10b (Web2C 7.4.5)), I tried to do a goto-remote to a page by its number in another document. As this is not possible with \hyperref AFAIK (there was some c.t.t. thread in 2002), I tried the following macro (not using the user{} action): \def\pdfhref#1#2#3{% \leavevmode\pdfstartlink attr{/Border[0 0 1]/H/I/C[0 .5 .5]}% goto file{#1}page#2{/Fit}#3% \pdfendlink } Example: \pdfhref{foo.pdf}{8}{Click here!}. This produced lines in the PDF file like: /A << /F (foo.pdf) /S /GoToR /D [1 /Fit] >> But some lines looked as follows (!): /A << /F (Pay.pdf) /NewWindow false /S /GoToR /D [2 /Fit] >> File pdftex.ch shows, that /NewWindow is produced when pdf_action_new_window(p) > 0. Printing out the pdf_action_new_window(p) values in the cases, where /NewWindow was in the PDF file, brought crazy large numbers, as with an uninitialized variable; here is why: Function scan_action in pdftex.ch has a return statement at the end of the "page" case, so the code for setting the pdf_action_new_window(p) variable at the end of the function is not reached. In the goto-name and goto-num case, pdf_action_new_window(p) is initialized. So the problem of spurious /NewWindow happens only in the goto-page case. Now I tried the newwindow/nonewwindow tag, but got an error, which should not be there: "`newwindow'/`nonewwindow' must be used with `goto' and `file' option". See end of function scan_action. Reason is, that in the goto-page case the pdf_action_type(p) changes from pdf_action_goto into pdf_action_page, but this is not checked by the if-statement at the end of the function. It seems to work now (no spurious /NewWindow, (no)newwindow usable also in page case), with the small patch below. The problem is rather minor, as \pdfstartlink...\pdfendlink seems to be used in most cases (e. g. by hyperref.sty) through the more versatile user{} action. Anyway... Here is the patch to pdftex.ch (hope it doen't break anything): ------------------------------------------------------------------------ --- pdftex.ch.orig Fri Jun 27 23:16:00 2003 +++ pdftex.ch Fri Jun 27 23:50:03 2003 @@ -6858,7 +6858,6 @@ pdf_action_named_id(p) := 0; call_func(scan_toks(false, true)); pdf_action_page_tokens(p) := def_ref; - return; end else if scan_keyword("name") then begin call_func(scan_toks(false, true)); @@ -6885,10 +6884,11 @@ else pdf_action_new_window(p) := 0; if (pdf_action_new_window(p) > 0) and - ((pdf_action_type(p) <> pdf_action_goto) or - (pdf_action_file(p) = null)) then - pdf_error("ext1", - "`newwindow'/`nonewwindow' must be used with `goto' and `file' option"); + (((pdf_action_type(p) <> pdf_action_goto) and + (pdf_action_type(p) <> pdf_action_page)) or + (pdf_action_file(p) = null)) then + pdf_error("ext1", + "`newwindow'/`nonewwindow' must be used with `goto' and `file' option"); end; procedure new_annot_whatsit(w, s: small_number); {create a new whatsit node for ------------------------------------------------------------------------ Here is a small update for file pdftex-syntax.txt, showing that the (no)newwindow stuff is allowed only in remote-goto's: ------------------------------------------------------------------------ --- pdftex-syntax.txt.orig Thu Jan 16 15:37:00 2003 +++ pdftex-syntax.txt Fri Jun 27 23:39:27 2003 @@ -94,19 +94,19 @@ <resources spec> --> resources <general text> <image attr spec> --> [<rule spec>] [<attr spec>] [<page spec>] [<pdf box spec>] <outline spec> --> <action spec> [count <number>] <general text> -<action spec> --> <select action spec> [<newwindow spec>] -<newwindow spec> --> newwindow - | nonewwindow +<action spec> --> <select action spec> <select action spec> --> user <user-action spec> | goto <goto-action spec> | thread <thread-action spec> <user-action spec> --> user <general text> <goto-action spec> --> <numid> - | [<file spec>] <nameid> - | [<file spec>] [<page spec>] <general text> + | [<file spec>] <nameid> [<newwindow spec>] + | [<file spec>] [<page spec>] <general text> [<newwindow spec>] <pdf box spec> --> artbox|trimbox|bleedbox|cropbox|mediabox <numid> --> num <number> <nameid> --> name <general text> +<newwindow spec> --> newwindow + | nonewwindow <thread-action spec> --> [<file spec>] <numid> | [<file spec>] <nameid> <dest spec> --> <numid> <dest type> ------------------------------------------------------------------------ Greetings Hartmut ------------------------------------------------------------------------ Hartmut Henkel, Oftersheim, Germany ------------------------------------------------------------------------
Hi Hartmut, I wonder what the newwindow keyword is doing in the pdftex syntax since there is no reason for having it (it can be handled by the attributes); the more such keywords are added (kept) the messier the pdftex code will be and the bigger the chance on errors like the one that you uncovered. I fear that we are stuck with it now (and therefore need your patch) but we could consider removing the feature. At least it's a signal to be careful with future extensions, Thanks, Hans
there is some minor loose end within pdftex: Using teTeX-2.0.2 pdflatex (pdfTeX, Version 3.14159-1.10b (Web2C 7.4.5)), I tried to do a goto-remote to a page by its number in another document. As this is not possible with \hyperref AFAIK (there was some c.t.t. thread in 2002), I tried the following macro (not using the user{} action):
\def\pdfhref#1#2#3{% \leavevmode\pdfstartlink attr{/Border[0 0 1]/H/I/C[0 .5 .5]}% goto file{#1}page#2{/Fit}#3% \pdfendlink }
Example: \pdfhref{foo.pdf}{8}{Click here!}. This produced lines in the PDF file like:
/A << /F (foo.pdf) /S /GoToR /D [1 /Fit] >>
But some lines looked as follows (!):
/A << /F (Pay.pdf) /NewWindow false /S /GoToR /D [2 /Fit] >>
File pdftex.ch shows, that /NewWindow is produced when pdf_action_new_window(p) > 0. Printing out the pdf_action_new_window(p) values in the cases, where /NewWindow was in the PDF file, brought crazy large numbers, as with an uninitialized variable; here is why: Function scan_action in pdftex.ch has a return statement at the end of the "page" case, so the code for setting the pdf_action_new_window(p) variable at the end of the function is not reached. In the goto-name and goto-num case, pdf_action_new_window(p) is initialized. So the problem of spurious /NewWindow happens only in the goto-page case.
Now I tried the newwindow/nonewwindow tag, but got an error, which should not be there: "`newwindow'/`nonewwindow' must be used with `goto' and `file' option". See end of function scan_action. Reason is, that in the goto-page case the pdf_action_type(p) changes from pdf_action_goto into pdf_action_page, but this is not checked by the if-statement at the end of the function.
It seems to work now (no spurious /NewWindow, (no)newwindow usable also in page case), with the small patch below. The problem is rather minor, as \pdfstartlink...\pdfendlink seems to be used in most cases (e. g. by hyperref.sty) through the more versatile user{} action. Anyway... Here is the patch to pdftex.ch (hope it doen't break anything):
------------------------------------------------------------------------ --- pdftex.ch.orig Fri Jun 27 23:16:00 2003 +++ pdftex.ch Fri Jun 27 23:50:03 2003 @@ -6858,7 +6858,6 @@ pdf_action_named_id(p) := 0; call_func(scan_toks(false, true)); pdf_action_page_tokens(p) := def_ref; - return; end else if scan_keyword("name") then begin call_func(scan_toks(false, true)); @@ -6885,10 +6884,11 @@ else pdf_action_new_window(p) := 0; if (pdf_action_new_window(p) > 0) and - ((pdf_action_type(p) <> pdf_action_goto) or - (pdf_action_file(p) = null)) then - pdf_error("ext1", - "`newwindow'/`nonewwindow' must be used with `goto' and `file' option"); + (((pdf_action_type(p) <> pdf_action_goto) and + (pdf_action_type(p) <> pdf_action_page)) or + (pdf_action_file(p) = null)) then + pdf_error("ext1", + "`newwindow'/`nonewwindow' must be used with `goto' and `file' option"); end;
procedure new_annot_whatsit(w, s: small_number); {create a new whatsit node for ------------------------------------------------------------------------
Here is a small update for file pdftex-syntax.txt, showing that the (no)newwindow stuff is allowed only in remote-goto's:
------------------------------------------------------------------------ --- pdftex-syntax.txt.orig Thu Jan 16 15:37:00 2003 +++ pdftex-syntax.txt Fri Jun 27 23:39:27 2003 @@ -94,19 +94,19 @@ <resources spec> --> resources <general text> <image attr spec> --> [<rule spec>] [<attr spec>] [<page spec>] [<pdf box spec>] <outline spec> --> <action spec> [count <number>] <general text> -<action spec> --> <select action spec> [<newwindow spec>] -<newwindow spec> --> newwindow - | nonewwindow +<action spec> --> <select action spec> <select action spec> --> user <user-action spec> | goto <goto-action spec> | thread <thread-action spec> <user-action spec> --> user <general text> <goto-action spec> --> <numid> - | [<file spec>] <nameid> - | [<file spec>] [<page spec>] <general text> + | [<file spec>] <nameid> [<newwindow spec>] + | [<file spec>] [<page spec>] <general text> [<newwindow spec>] <pdf box spec> --> artbox|trimbox|bleedbox|cropbox|mediabox <numid> --> num <number> <nameid> --> name <general text> +<newwindow spec> --> newwindow + | nonewwindow <thread-action spec> --> [<file spec>] <numid> | [<file spec>] <nameid> <dest spec> --> <numid> <dest type> ------------------------------------------------------------------------
Greetings Hartmut
------------------------------------------------------------------------ Hartmut Henkel, Oftersheim, Germany ------------------------------------------------------------------------
_______________________________________________ ntg-pdftex mailing list ntg-pdftex@ntg.nl http://www.ntg.nl/mailman/listinfo/ntg-pdftex
================================================================ Deze e-mail is door E-mail VirusScanner van Planet Internet gecontroleerd op virussen. Op http://www.planet.nl/evs staat een verwijzing naar de actuele lijst waar op wordt gecontroleerd.
------------------------------------------------------------------------- Hans Hagen | PRAGMA ADE | pragma@wxs.nl Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: +31 (0)38 477 53 69 | fax: +31 (0)38 477 53 74 | www.pragma-ade.com ------------------------------------------------------------------------- information: http://www.pragma-ade.com/roadmap.pdf documentation: http://www.pragma-ade.com/showcase.pdf -------------------------------------------------------------------------
On 2003-06-05 23:10:43 +0200, Heiko Oberdiek wrote:
Sorry I had forgotten the patches.
It's in (#3306): - New readonly primitive \pdfshellescape which can be used to test if the \write18 feature is enabled or not (it expands to "1" if it's enabled and to 0 if it's not) Best regards Martin -- Martin Schröder, MS@ArtCom-GmbH.DE ArtCom GmbH, Lise-Meitner-Str 5, 28359 Bremen, Germany Voice +49 421 20419-44 / Fax +49 421 20419-10
On 2003-07-10 14:35:48 +0200, Martin Schröder wrote:
- New readonly primitive \pdfshellescape which can be used to test if the
Thinking further (and being reminded by Rolf): Is there a reason why this can _not_ be called \shellescape? It's got nothing to do with pdf (and would be usefull in all web2c-based TeX engines, no matter what they are called). Best regards Martin -- Martin Schröder, MS@ArtCom-GmbH.DE ArtCom GmbH, Lise-Meitner-Str 5, 28359 Bremen, Germany Voice +49 421 20419-44 / Fax +49 421 20419-10
On Thu, Jul 10, 2003 at 02:57:25PM +0200, Martin Schroeder wrote:
On 2003-07-10 14:35:48 +0200, Martin Schröder wrote:
- New readonly primitive \pdfshellescape which can be used to test if the
Thinking further (and being reminded by Rolf): Is there a reason why this can _not_ be called \shellescape? It's got nothing to do with pdf (and would be usefull in all web2c-based TeX engines, no matter what they are called).
\write18 is a property of web2c-based TeX engines, so
\shellescape is the better name and it would be even better,
if this can be added to the other web2c-based TeX engines, too.
Yours sincerely
Heiko
On 2003-07-10 15:49:50 +0200, Heiko Oberdiek wrote:
On Thu, Jul 10, 2003 at 02:57:25PM +0200, Martin Schroeder wrote:
On 2003-07-10 14:35:48 +0200, Martin Schröder wrote:
- New readonly primitive \pdfshellescape which can be used to test if the
Thinking further (and being reminded by Rolf): Is there a reason why this can _not_ be called \shellescape? It's got nothing to do with pdf (and would be usefull in all web2c-based TeX engines, no matter what they are called).
\write18 is a property of web2c-based TeX engines, so \shellescape is the better name and it would be even better, if this can be added to the other web2c-based TeX engines, too.
Same here. Olaf? Or does this belong to tex-implementors? Best regards Martin -- Martin Schröder, MS@ArtCom-GmbH.DE ArtCom GmbH, Lise-Meitner-Str 5, 28359 Bremen, Germany Voice +49 421 20419-44 / Fax +49 421 20419-10
Martin Schroeder writes:
On 2003-07-10 15:49:50 +0200, Heiko Oberdiek wrote:
On Thu, Jul 10, 2003 at 02:57:25PM +0200, Martin Schroeder wrote:
On 2003-07-10 14:35:48 +0200, Martin Schröder wrote:
- New readonly primitive \pdfshellescape which can be used to test if the
Thinking further (and being reminded by Rolf): Is there a reason why this can _not_ be called \shellescape? It's got nothing to do with pdf (and would be usefull in all web2c-based TeX engines, no matter what they are called).
\write18 is a property of web2c-based TeX engines, so \shellescape is the better name and it would be even better, if this can be added to the other web2c-based TeX engines, too.
Same here. Olaf? Or does this belong to tex-implementors?
\shellescape sits in Knuth's namespace. This seems to have come up private mail as well, and there the suggestion was to use \ifeof18 instead. For various reasons I still haven't been able to spend time on TeX. :-( -- Olaf Weber (This space left blank for technical reasons.)
On Thu, Jul 10, 2003 at 10:05:25PM +0200, Olaf Weber wrote:
Martin Schroeder writes:
On 2003-07-10 15:49:50 +0200, Heiko Oberdiek wrote:
On Thu, Jul 10, 2003 at 02:57:25PM +0200, Martin Schroeder wrote:
On 2003-07-10 14:35:48 +0200, Martin Schröder wrote:
- New readonly primitive \pdfshellescape which can be used to test if the
Thinking further (and being reminded by Rolf): Is there a reason why this can _not_ be called \shellescape? It's got nothing to do with pdf (and would be usefull in all web2c-based TeX engines, no matter what they are called).
\write18 is a property of web2c-based TeX engines, so \shellescape is the better name and it would be even better, if this can be added to the other web2c-based TeX engines, too.
Same here. Olaf? Or does this belong to tex-implementors?
\shellescape sits in Knuth's namespace.
This seems to have come up private mail as well, and there the suggestion was to use \ifeof18 instead.
For various reasons I still haven't been able to spend time on TeX. :-(
Ok, I have done it:
Patch ShellEscapeIfeof18
Packages such as pdftricks.sty, epstopdf.sty (or pdftex.def)
call external programs. They do not work at all, if the
\write18 feature is not enabled. Therefore a robust method
would be useful in order to inform the user. For security
reasons the \write18 feature must not be set by TeX macro
code.
In opposite to patch "ShellEscape" this patch now uses
\ifeof18 for a test of the shell escape feature. Thus the
introduction of a new primitive is avoided. Also it works
now for other TeX engines (tex, etex, pdftex, pdfetex).
Use, for instance:
\ifeof18
\message{The \string\write18 feature is disabled.}
\else
\message{The \string\write18 feature is enabled.}
\fi
Patch files based on 2003/07/11 v1.11a:
tex.ch.diff for TeX/texk/web2c/tex.ch
Attachted are files tex.ch.diff and a test file test.tex.
Yours sincerely
Heiko
On 2003-07-11 01:37:20 +0200, Heiko Oberdiek wrote:
Patch ShellEscapeIfeof18
Sounds good. I've removed \pdfshellescape (#3320). Best regards Martin -- Martin Schröder, MS@ArtCom-GmbH.DE ArtCom GmbH, Lise-Meitner-Str 5, 28359 Bremen, Germany Voice +49 421 20419-44 / Fax +49 421 20419-10
On Fri, Jul 11, 2003 at 01:08:47PM +0200, Martin Schroeder wrote:
On 2003-07-11 01:37:20 +0200, Heiko Oberdiek wrote:
Patch ShellEscapeIfeof18
Sounds good.
A short discussion about the two methods \shellescape vs. \ifeof18:
* \ifeof18: the temptation for enabling the \write18 feature at
macro level, because this interface only provides asking/reading
and not writing. For security reasons the \write18 feature
must not be enabled at macro level.
* The implementation is easier and more portable,
because there is no need for the nasty magic *_code number of
a new primitive that would also affect change files of other
TeX enginges.
* \ifeof18 avoids a new primitive. The "namespace" problem, however,
could be solved by funny names, eg.: "\.web2c.shellescape".
* But there is also a disadvantage of the \ifeof18 method:
TeX generates a error message, if \ifeof18 is not supported.
Unhappily TeX does not provide an exception mechanism, so this
error cannot be catched.
For "tex" and "etex" I see no way to avoid this without a new
primitive that can easily checked for existence. The primitive
can be either a command that indicates the presence of the
feature or returns the version number of web2c.
For "pdf(e)tex" this is not a problem, because here
\pdfversion and \pdfrevision can be asked. So packages such
as pdftricks, pdftex.def, ... will be happy.
Yours sincerely
Heiko
participants (5)
-
Hans Hagen
-
Hartmut Henkel
-
Heiko Oberdiek
-
Martin Schroeder
-
Olaf Weber