Re: security trap mode

Emil Jerabek <[email protected]>
Newsgroups gmane.comp.tex.tetex.general
Message-ID <[email protected]>
On Fri, 04 Feb 2005 18:22:10 +0100, Johannes Berg wrote:
[...]
> I have two questions about this:
>  1) from what I read in The TeXbook and the sources, there's no way
>     to loop in TeX that doesn't take iterations of the main loop. Is
>     that correct?

Others have already suggested using ulimit and friends. But just for
the record: no, it is not, if "main loop" means "main_control". It is
possible to create fully expandable loops, e.g.,

   \def\a{\a}\a

takes a single call to main_control, and spins in get_x_token. (Making
such a loop finite is more tricky, but possible.)

BTW, if you want to limit also memory resources, do not rely on the
fact that TeX arrays have a fixed size given in texmf.cnf. Some of the
routines in TeX are recursive, and can thus use huge amount of stack (as in
OS-supplied stack, not TeX stack) before overflowing TeX memory. The
example below needs almost 10x more stack size than data size (YMMV).

[~/tex]% (ulimit -s 77000; tex '\def\a{\csname\a}\a')
This is TeXk, Version 3.14159 (Web2C 7.4.5)
 %&-line parsing enabled.
! TeX capacity exceeded, sorry [main memory size=1000001].
\a ->\csname
             \a
<*> \def\a{\csname\a}\a

No pages of output.
Transcript written on texput.log.
[~/tex]% (ulimit -s 76000; tex '\def\a{\csname\a}\a')
This is TeXk, Version 3.14159 (Web2C 7.4.5)
 %&-line parsing enabled.
zsh: segmentation fault  (; ulimit -s 76000; tex '\def\a{\csname\a}\a'; )


Emil Jerabek
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.