From 4ab4495fbd7df630ad313b9a93a2950c644fbd64 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Mon, 2 May 2016 20:59:14 +0200 Subject: [letterspace] fix crash with fonts with missing glyphs Fix issue #351 The letterspace node handler dereferences kern values of non-existant character information under some circumstances, causing Luatex to crash. To avoid this crash, check more thoroughly for the presence of the fields accessed. Discovered by @schlcht --- src/luaotfload-letterspace.lua | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) (limited to 'src/luaotfload-letterspace.lua') diff --git a/src/luaotfload-letterspace.lua b/src/luaotfload-letterspace.lua index 007fa51..bda56b2 100644 --- a/src/luaotfload-letterspace.lua +++ b/src/luaotfload-letterspace.lua @@ -411,11 +411,20 @@ kerncharacters = function (head) if keeptogether and keeptogether(prev, start) then -- keep 'm elseif identifiers[lastfont] then - local kerns = chardata[lastfont] and chardata[lastfont][prevchar].kerns - local kern = kerns and kerns[lastchar] or 0 - krn = kern + quaddata[lastfont]*krn -- here - insert_node_before(head,start,kern_injector(fillup,krn)) - done = true + local lastfontchars = chardata[lastfont] + if lastfontchars then + local prevchardata = lastfontchars[prevchar] + if not prevchardata then + --- font doesn’t contain the glyph + else + local kern = 0 + local kerns = prevchardata.kerns + if kerns then kern = kerns[lastchar] end + krn = kern + quaddata[lastfont]*krn -- here + insert_node_before(head,start,kern_injector(fillup,krn)) + done = true + end + end end else krn = quaddata[lastfont]*krn -- here @@ -477,10 +486,19 @@ kerncharacters = function (head) and getid(prv) == glyph_code and getfont(prv) == lastfont then + local kern = 0 local prevchar = getchar(prv) local lastchar = getchar(start) - local kerns = chardata[lastfont] and chardata[lastfont][prevchar].kerns - local kern = kerns and kerns[lastchar] or 0 + local lastfontchars = chardata[lastfont] + if lastfontchars then + local prevchardata = lastfontchars[prevchar] + if not prevchardata then + --- font doesn’t contain the glyph + else + local kerns = prevchardata.kerns + if kerns then kern = kerns[lastchar] end + end + end krn = kern + quaddata[lastfont]*krn -- here else krn = quaddata[lastfont]*krn -- here -- cgit v1.2.3 From 687430a81dcd658d664e6a8c7dca6f53bc093a8c Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Mon, 2 May 2016 21:07:14 +0200 Subject: [letterspace] remove useless state variable --- src/luaotfload-letterspace.lua | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'src/luaotfload-letterspace.lua') diff --git a/src/luaotfload-letterspace.lua b/src/luaotfload-letterspace.lua index bda56b2..40b3015 100644 --- a/src/luaotfload-letterspace.lua +++ b/src/luaotfload-letterspace.lua @@ -277,7 +277,7 @@ local kernfactors = { } --- fontid -> factor local kerncharacters kerncharacters = function (head) - local start, done = head, false + local start = head local lastfont = nil local keepligature = letterspace.keepligature --- function local keeptogether = letterspace.keeptogether --- function @@ -352,7 +352,6 @@ kerncharacters = function (head) start = c setfield(s, "components", nil) free_node(s) - done = true c = getfield (start, "components") end end @@ -378,7 +377,6 @@ kerncharacters = function (head) local shrunk = (getfield(spec,"shrink") * newwd) / wd setfield(prev, "spec", spec_injector(fillup, newwd, stretched, shrunk)) - done = true end elseif pid == kern_code then @@ -400,7 +398,6 @@ kerncharacters = function (head) local prev_kern = getfield(prev, "kern") prev_kern = prev_kern + quaddata[lastfont] * krn setfield (prev, "kern", prev_kern) - done = true end end @@ -422,14 +419,12 @@ kerncharacters = function (head) if kerns then kern = kerns[lastchar] end krn = kern + quaddata[lastfont]*krn -- here insert_node_before(head,start,kern_injector(fillup,krn)) - done = true end end end else krn = quaddata[lastfont]*krn -- here insert_node_before(head,start,kern_injector(fillup,krn)) - done = true end elseif pid == disc_code then @@ -514,7 +509,7 @@ kerncharacters = function (head) start = getnext(start) end end - return head, done + return head end ---=================================================================--- @@ -566,7 +561,7 @@ local enablefontkerning = function ( ) logreport ("term", 5, "letterspace", "kerncharacters() invoked with node.direct interface \z (``%s`` -> ``%s``)", tostring (hd), tostring (direct_hd)) - local direct_hd, _done = kerncharacters (direct_hd) + local direct_hd = kerncharacters (direct_hd) if not direct_hd then --- bad logreport ("both", 0, "letterspace", "kerncharacters() failed to return a valid new head") -- cgit v1.2.3