Skip to content

Commit

Permalink
Guard against overwiting function table for #1100 (#1104)
Browse files Browse the repository at this point in the history
* Guard against overwiting function table for #1100

* set new slot to false as suggested by @zauguin

* change log for #1100
  • Loading branch information
davidcarlisle committed Aug 29, 2023
1 parent 163a10b commit 3f41c4d
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 1 deletion.
6 changes: 6 additions & 0 deletions base/changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ are not part of the distribution.
* ltfilehook.dtx (subsection{Declaring a file substitution}):
Drop a redundant \ExplSyntaxOff

2023-07-02 David Carlisle <David.Carlisle@latex-project.org>

* ltluatex.dtx modify new_luafunction to ensure
\e@alloc@luafunction@count always matches the size of the Lua
table of function allocations (gh100)

2023-06-12 Joseph Wright <Joseph.Wright@latex-project.org>

* usrguide.tex
Expand Down
7 changes: 6 additions & 1 deletion base/ltluatex.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -1284,14 +1284,19 @@ luatexbase.new_chunkname = new_chunkname
%
% \begin{macro}{new_luafunction}
% \changes{v1.1i}{2018/10/21}{Function added}
% \changes{v1.2c}{2023/07/02}{Ensure existing table entries not overwritten gh/1100}
% Much the same as for attribute allocation in Lua.
% The optional \meta{name} argument is used in the log if given.
% \begin{macrocode}
local luafunction_count_name =
luafunction_count_name or "e@alloc@luafunction@count"
local function new_luafunction(name)
tex_setcount("global", luafunction_count_name,
tex_count[luafunction_count_name] + 1)
math.max(
#(lua.get_functions_table()),
tex_count[luafunction_count_name])
+ 1)
lua.get_functions_table()[tex_count[luafunction_count_name]] = false
if tex_count[luafunction_count_name] > 65534 then
luatexbase_error("No room for a new luafunction register")
end
Expand Down
9 changes: 9 additions & 0 deletions base/testfiles-TU/github-1100.luatex.tlg
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
This is a generated file for the LaTeX2e validation system.
Don't change this file in any respect.
> \fone=expandable luacall 25.
l. ...\show\fone
Lua function ftwo = ...
> \ftwo=expandable luacall 26.
l. ...\show\ftwo
f1: FUNCTION 1
f2: FUNCTION 2
32 changes: 32 additions & 0 deletions base/testfiles-TU/github-1100.lvt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
\input test2e
% github issue 1100
\START
\ifx\directlua\undefined
\expandafter\END
\fi

\directlua{
local lft = lua.get_functions_table()
lft[\string#lft+1] = function()
tex.sprint(-2, "FUNCTION 1")
end
token.set_lua("fone", \string#lft, "global")
}

\show\fone

\directlua{
local func = luatexbase.new_luafunction('ftwo')
token.set_lua('ftwo', func)
lua.get_functions_table()[func] = function()
tex.sprint(-2, "FUNCTION 2")
end
}

% should not be same as fone
\show\ftwo

\typeout{f1: \fone}
\typeout{f2: \ftwo}

\END
2 changes: 2 additions & 0 deletions base/testfiles-TU/github-1100.tlg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This is a generated file for the LaTeX2e validation system.
Don't change this file in any respect.

0 comments on commit 3f41c4d

Please sign in to comment.