[latex3-commits] [latex3/latex2e] gh1100: Guard against overwiting function table for #1100 (543d8cd2)

github at latex-project.org github at latex-project.org
Sun Jul 2 18:20:36 CEST 2023


Repository : https://github.com/latex3/latex2e
On branch  : gh1100
Link       : https://github.com/latex3/latex2e/commit/543d8cd21671bceefcc57482932ebafc950479ae

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

commit 543d8cd21671bceefcc57482932ebafc950479ae
Author: David Carlisle <d.p.carlisle at gmail.com>
Date:   Sun Jul 2 17:20:36 2023 +0100

    Guard against overwiting function table for #1100


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

543d8cd21671bceefcc57482932ebafc950479ae
 base/ltluatex.dtx                        |  8 ++++++--
 base/testfiles-TU/github-1100.luatex.tlg |  9 +++++++++
 base/testfiles-TU/github-1100.lvt        | 32 ++++++++++++++++++++++++++++++++
 base/testfiles-TU/github-1100.tlg        |  2 ++
 4 files changed, 49 insertions(+), 2 deletions(-)

diff --git a/base/ltluatex.dtx b/base/ltluatex.dtx
index 135cb630..c0ac07bc 100644
--- a/base/ltluatex.dtx
+++ b/base/ltluatex.dtx
@@ -28,7 +28,7 @@
 \ProvidesFile{ltluatex.dtx}
 %</driver>
 %<*tex>
-[2023/01/19 v1.2b
+[2023/07/02 v1.2c
 %</tex>
 %<plain>  LuaTeX support for plain TeX (core)
 %<*tex>
@@ -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,10 @@ 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)
   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.