From 2225c84a1b23a83e0b2d5a01fafd0f901ffc4006 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 27 May 2024 15:18:05 -0600 Subject: [PATCH] [CFFToCFF2] Allow fdIndex==0 Oops. --- Lib/fontTools/cffLib/CFFToCFF2.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Lib/fontTools/cffLib/CFFToCFF2.py b/Lib/fontTools/cffLib/CFFToCFF2.py index 37463a5b9..2555f0b24 100644 --- a/Lib/fontTools/cffLib/CFFToCFF2.py +++ b/Lib/fontTools/cffLib/CFFToCFF2.py @@ -81,7 +81,7 @@ def _convertCFFToCFF2(cff, otFont): thisLocalSubrs = ( localSubrs[fdIndex] - if fdIndex + if fdIndex is not None else ( getattr(topDict.Private, "Subrs", []) if hasattr(topDict, "Private") @@ -104,9 +104,10 @@ def _convertCFFToCFF2(cff, otFont): # just pop the first number since it may be a subroutine call. # Instead, when seeing that, we embed the subroutine and recurse. # If this ever happened, we later prune unused subroutines. - while program[1] in ["callsubr", "callgsubr"]: + while len(program) >= 2 and program[1] in ["callsubr", "callgsubr"]: removeUnusedSubrs = True subrNumber = program.pop(0) + assert isinstance(subrNumber, int), subrNumber op = program.pop(0) bias = extractor.localBias if op == "callsubr" else extractor.globalBias subrNumber += bias @@ -114,6 +115,7 @@ def _convertCFFToCFF2(cff, otFont): subrProgram = subrSet[subrNumber].program program[:0] = subrProgram # Now pop the actual width + assert len(program) >= 1, program program.pop(0) if program and program[-1] == "endchar":