From fd71d18a0afb5efcd1c9c34d3775bdc257f88488 Mon Sep 17 00:00:00 2001 From: Taco de Wolff Date: Mon, 29 Jan 2024 11:03:34 -0300 Subject: [PATCH] SFNT: don't parse script/feature/lookup/featureVariation tables in GSUB/GPOS if their offset is zero, fixes #274 --- font/sfnt_layout.go | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/font/sfnt_layout.go b/font/sfnt_layout.go index dce0ceec..7915a602 100644 --- a/font/sfnt_layout.go +++ b/font/sfnt_layout.go @@ -58,10 +58,9 @@ func (sfnt *SFNT) parseScriptList(b []byte) (scriptList, error) { r3.Seek(uint32(scriptOffset) + uint32(langSysOffset)) lookupOrderOffset := r3.ReadUint16() - _ = lookupOrderOffset - //if lookupOrderOffset != 0 { - // return scripts, fmt.Errorf("lookupOrderOffset must be NULL") - //} + if lookupOrderOffset != 0 { + return scripts, fmt.Errorf("lookupOrderOffset must be NULL") + } requiredFeatureIndex := r3.ReadUint16() featureIndexCount := r3.ReadUint16() featureIndices := make([]uint16, featureIndexCount) @@ -804,25 +803,29 @@ func (sfnt *SFNT) parseGPOSGSUB(name string, subtableMap subtableMap) (*gposgsub scriptListOffset := r.ReadUint16() if len(b)-2 < int(scriptListOffset) { return nil, fmt.Errorf("%s: bad scriptList offset", name) - } - table.scriptList, err = sfnt.parseScriptList(b[scriptListOffset:]) - if err != nil { - return nil, fmt.Errorf("%s: %w", name, err) + } else if scriptListOffset != 0 { + table.scriptList, err = sfnt.parseScriptList(b[scriptListOffset:]) + if err != nil { + return nil, fmt.Errorf("%s: %w", name, err) + } + } else { + table.scriptList = scriptList{} } featureListOffset := r.ReadUint16() if len(b)-2 < int(featureListOffset) { return nil, fmt.Errorf("%s: bad featureList offset", name) + } else if featureListOffset != 0 { + table.featureList = sfnt.parseFeatureList(b[featureListOffset:]) } - table.featureList = sfnt.parseFeatureList(b[featureListOffset:]) lookupListOffset := r.ReadUint16() if len(b)-2 < int(lookupListOffset) { return nil, fmt.Errorf("%s: bad lookupList offset", name) - } - if lookupListOffset != 0 { + } else if lookupListOffset != 0 { table.lookupList = sfnt.parseLookupList(b[lookupListOffset:]) } + table.tables = make([]interface{}, len(table.lookupList)) for j, lookup := range table.lookupList { if parseSubtable, ok := subtableMap[lookup.lookupType]; ok { @@ -847,8 +850,9 @@ func (sfnt *SFNT) parseGPOSGSUB(name string, subtableMap subtableMap) (*gposgsub featureVariationsOffset = r.ReadUint32() if len(b)-8 < int(featureVariationsOffset) { return nil, fmt.Errorf("%s: bad featureVariations offset", name) + } else if featureVariationsOffset != 0 { + table.featureVariationsList = featureVariationsList{b[featureVariationsOffset:]} } - table.featureVariationsList = featureVariationsList{b[featureVariationsOffset:]} } return table, nil }