Discussion:
[Dev-luatex] Opening files in safer mode
Marcel Krüger
2018-10-23 21:28:40 UTC
Permalink
Hi,

I think there is a bug in `io.open` in --safer mode:

\directlua{
io.open(tex.jobname .. '.tex'):close()
}
\bye

If this document is run with `luatex --safer` it leads to `bad argument #1 to 'gsub' (string expected, got nil)`.

The problem is a missing `not` in luatex-core.lua, function luatex_io_open_readonly:
The default argument 'r' is used if an explicit argument is given and when no "how" argument
is given it tries to interpret the non existing argument.

This can be fixed by (I omit the changes to `luatex-core.c` in the diff, they are auto-generated anyway):

diff --git a/source/texk/web2c/luatexdir/lua/luatex-core.lua b/source/texk/web2c/luatexdir/lua/luatex-core.lua
index f2d55fd99..de7f12006 100644
--- a/source/texk/web2c/luatexdir/lua/luatex-core.lua
+++ b/source/texk/web2c/luatexdir/lua/luatex-core.lua
@@ -54,7 +54,7 @@ local function luatex_io_open(name,how)
end

local function luatex_io_open_readonly(name,how)
- if how then
+ if not how then
how = 'r'
else
how = gsub(how,'[^rb]','')



Best regards,
Marcel Krüger
luigi scarso
2018-10-23 22:43:14 UTC
Permalink
Post by Marcel Krüger
Hi,
\directlua{
io.open(tex.jobname .. '.tex'):close()
}
\bye
If this document is run with `luatex --safer` it leads to `bad argument #1
to 'gsub' (string expected, got nil)`.
The problem is a missing `not` in luatex-core.lua, function
The default argument 'r' is used if an explicit argument is given and when
no "how" argument
is given it tries to interpret the non existing argument.
hm this is tricky.. we have to check it carefully,
these "safer" modes are quite complicated things.
--
luigi
luigi scarso
2018-10-25 06:06:51 UTC
Permalink
Post by luigi scarso
Post by Marcel Krüger
Hi,
\directlua{
io.open(tex.jobname .. '.tex'):close()
}
\bye
If this document is run with `luatex --safer` it leads to `bad argument
#1 to 'gsub' (string expected, got nil)`.
The problem is a missing `not` in luatex-core.lua, function
The default argument 'r' is used if an explicit argument is given and
when no "how" argument
is given it tries to interpret the non existing argument.
hm this is tricky.. we have to check it carefully,
these "safer" modes are quite complicated things.
We have committed a patch that also set debug=nil,
--- so statistics using debug doesn't work in --safer .
--
luigi
Continue reading on narkive:
Loading...