[latex3-commits] [latex3/latex2e] develop: Guard against overwiting function table for #1100 (#1104) (3f41c4da)

github at latex-project.org github at latex-project.org
Tue Aug 29 21:13:31 CEST 2023


Repository : https://github.com/latex3/latex2e
On branch  : develop
Link       : https://github.com/latex3/latex2e/commit/3f41c4daef548c30c28b05949d976b9b1c2562b8

>---------------------------------------------------------------

commit 3f41c4daef548c30c28b05949d976b9b1c2562b8
Author: David Carlisle <d.p.carlisle at gmail.com>
Date:   Tue Aug 29 20:13:31 2023 +0100

    Guard against overwiting function table for #1100 (#1104)
    
    * Guard against overwiting function table for #1100
    
    * set new slot to false as suggested by @zauguin
    
    * change log for #1100


>---------------------------------------------------------------

3f41c4daef548c30c28b05949d976b9b1c2562b8
 base/changes.txt                         |  6 ++++++
 base/ltluatex.dtx                        |  7 ++++++-
 base/testfiles-TU/github-1100.luatex.tlg |  9 +++++++++
 base/testfiles-TU/github-1100.lvt        | 32 ++++++++++++++++++++++++++++++++
 base/testfiles-TU/github-1100.tlg        |  2 ++
 5 files changed, 55 insertions(+), 1 deletion(-)

diff --git a/base/changes.txt b/base/changes.txt
index cc3e024d..c7c1d94e 100644
--- a/base/changes.txt
+++ b/base/changes.txt
@@ -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 at latex-project.org>
+
+	* ltluatex.dtx modify new_luafunction to ensure
+	\e at alloc@luafunction at count always matches the size of the Lua
+	table of function allocations (gh100)
+
 2023-06-12  Joseph Wright  <Joseph.Wright at latex-project.org>
 
 	* usrguide.tex
diff --git a/base/ltluatex.dtx b/base/ltluatex.dtx
index 892e4214..6d274ed5 100644
--- a/base/ltluatex.dtx
+++ b/base/ltluatex.dtx
@@ -1284,6 +1284,7 @@ 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}
@@ -1291,7 +1292,11 @@ local luafunction_count_name =
                          luafunction_count_name or "e at alloc@luafunction at 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
diff --git a/base/testfiles-TU/github-1100.luatex.tlg b/base/testfiles-TU/github-1100.luatex.tlg
new file mode 100644
index 00000000..898a0a7a
--- /dev/null
+++ b/base/testfiles-TU/github-1100.luatex.tlg
@@ -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
diff --git a/base/testfiles-TU/github-1100.lvt b/base/testfiles-TU/github-1100.lvt
new file mode 100644
index 00000000..5de191ab
--- /dev/null
+++ b/base/testfiles-TU/github-1100.lvt
@@ -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
\ No newline at end of file
diff --git a/base/testfiles-TU/github-1100.tlg b/base/testfiles-TU/github-1100.tlg
new file mode 100644
index 00000000..1d0c6975
--- /dev/null
+++ b/base/testfiles-TU/github-1100.tlg
@@ -0,0 +1,2 @@
+This is a generated file for the LaTeX2e validation system.
+Don't change this file in any respect.





More information about the latex3-commits mailing list.