[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#1009196: [Dev-luatex] Bug#1009196: texlive-binaries: Reproducible content of .fmt files



Hello list,

On 12/04/2022 08:44, Roland Clobus wrote:
I'll follow-up soon with an updated patch.

As discussed, I've updated the patch.

For Lua-based TeX binaries, only when FORCE_SOURCE_DATE=1 and SOURCE_DATE_EPOCH are set, this will initialise the Lua seed to the value of SOURCE_DATE_EPOCH instead of a random value.
With this patch, the .fmt files can be generated bit-for-bit identical.

Regarding the patch:
* This patch is intended only for Lua 5.3 that is embedded in texlive-binaries * A re-definition of `luai_makeseed` is unfortunately not sufficient for Lua 5.3, for 5.4.4 and later it would be. [1]
* I've added no validation for the content of SOURCE_DATE_EPOCH:
** 1) That happens in other code locations already
** 2) Even if the value would be incorrect, the Lua seed will still be de-randomized
* Do you want some comment lines?
* The sorting from by previous patch is no longer required. Only lstate.c needs to be modified.

With kind regards,
Roland Clobus


PS: If you later intend to upgrade to another version of Lua, the fixed seed value can help you in automated tests to see different behaviour due to the upgrade.

[1] https://github.com/lua/lua/commit/97e394ba1805fbe394a5704de660403901559e54
diff --git a/libs/lua53/lua53-src/src/lstate.c b/libs/lua53/lua53-src/src/lstate.c
index c1a76643..c67141f1 100644
--- a/libs/lua53/lua53-src/src/lstate.c
+++ b/libs/lua53/lua53-src/src/lstate.c
@@ -12,6 +12,7 @@
 
 #include <stddef.h>
 #include <string.h>
+#include <stdlib.h>
 
 #include "lua.h"
 
@@ -296,6 +297,8 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
   int i;
   lua_State *L;
   global_State *g;
+  const char *enable_source_date_epoch = getenv("FORCE_SOURCE_DATE");
+  const char *fixed_seed = getenv("SOURCE_DATE_EPOCH");
   LG *l = cast(LG *, (*f)(ud, NULL, LUA_TTHREAD, sizeof(LG)));
   if (l == NULL) return NULL;
   L = &l->l.l;
@@ -308,7 +311,11 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
   g->frealloc = f;
   g->ud = ud;
   g->mainthread = L;
-  g->seed = makeseed(L);
+  if (enable_source_date_epoch && !strcmp(enable_source_date_epoch, "1") && fixed_seed) {
+    g->seed = strtoull(fixed_seed, NULL, 10);
+  } else {
+    g->seed = makeseed(L);
+  }
   g->gcrunning = 0;  /* no GC while building state */
   g->GCestimate = 0;
   g->strt.size = g->strt.nuse = 0;

Attachment: OpenPGP_signature
Description: OpenPGP digital signature


Reply to: