From a88bb19016c621b4ce37e3d3205ef8698b694b5a Mon Sep 17 00:00:00 2001
From: Luigi Scarso <luigi.scarso@gmail.com>
Date: Fri, 31 Jan 2025 20:15:01 +0100
Subject: [PATCH] In read_tfm_info avoid scaling fonts to >= 2048pt, which can
 cause overflow (TeXLive rev. 73614)

---
 source/texk/web2c/luatexdir/ChangeLog           |  4 ++--
 source/texk/web2c/luatexdir/font/tfmofm.c       | 14 ++++++++++++++
 source/texk/web2c/luatexdir/luatex_svnversion.h |  2 +-
 3 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/source/texk/web2c/luatexdir/ChangeLog b/source/texk/web2c/luatexdir/ChangeLog
index 2972639d1..bc49345ff 100644
--- a/source/texk/web2c/luatexdir/ChangeLog
+++ b/source/texk/web2c/luatexdir/ChangeLog
@@ -1,8 +1,8 @@
-2025-01-19 Luigi Scarso <luigi.scarso@gmail.com>
+2025-01-31 Luigi Scarso <luigi.scarso@gmail.com>
+	* In read_tfm_info avoid scaling fonts to >= 2048pt, which can cause overflow (TeXLive rev. 73614)
 	* \ignoreprimitiveerror as in pdftex
 
 
-
 2025-01-19 Luigi Scarso <luigi.scarso@gmail.com>
 	* Fixed \shapemode does not reset at end of paragraphs (thanks to udifoglle@gmail.com)
 
diff --git a/source/texk/web2c/luatexdir/font/tfmofm.c b/source/texk/web2c/luatexdir/font/tfmofm.c
index f5d8c2e92..57989b8c8 100644
--- a/source/texk/web2c/luatexdir/font/tfmofm.c
+++ b/source/texk/web2c/luatexdir/font/tfmofm.c
@@ -849,7 +849,21 @@ int read_tfm_info(internal_font_number f, const char *cnom, scaled s)
     /*tex Read the arrays before the character info. */
     set_font_dsize(f, z);
     if (s != -1000) {
+        boolean saved_arith_error = arith_error;
+	scaled sw = z;
+	arith_error = false;
         z = (s >= 0 ? s : xn_over_d(z, -s, 1000));
+	if ((arith_error) || (z>= 01000000000)) {
+	  char err[256];
+	  const char *errhelp[] = {
+	    "I will ignore the scaling factor.",
+	    NULL
+	  };
+	  snprintf(err, 255, "Font scaled to 2048pt or higher");
+	  tex_error(err, errhelp);
+	}
+	z = sw ;
+	arith_error = saved_arith_error;
     }
     set_font_size(f, z);
     if (np > 7) {
diff --git a/source/texk/web2c/luatexdir/luatex_svnversion.h b/source/texk/web2c/luatexdir/luatex_svnversion.h
index de09af0f9..c7865db02 100644
--- a/source/texk/web2c/luatexdir/luatex_svnversion.h
+++ b/source/texk/web2c/luatexdir/luatex_svnversion.h
@@ -1,4 +1,4 @@
 #ifndef luatex_svn_revision_h
 #define luatex_svn_revision_h
-#define luatex_svn_revision 7646
+#define luatex_svn_revision 7647
 #endif
-- 
GitLab