-
-
Notifications
You must be signed in to change notification settings - Fork 87
Description
Description
When using a non-Latin language (zh, ja, ko, ru) with a regular_fonts configuration that has fewer than 3 entries, compilation crashes with an array index out of bounds error.
This affects both CV and cover letter modules in the current 3.2.0 release.
Reproduction
- In
metadata.toml, set:
[layout.fonts]
regular_fonts = ["Source Sans 3"] # only 1 font- Compile with a non-Latin language:
typst compile template/cv.typ --input language=zh- Error:
error: array index out of bounds (index: 2, len: 1)
ββ src/lib.typ:46:4
β
46 β fonts.insert(2, nonLatinFont)
β ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Root Cause
In src/lib.typ, both cv() (line 46) and letter() (line 134) use fonts.insert(2, non-latin-font) which assumes the font array has at least 2 elements. When overwrite-fonts() returns a user-defined regular_fonts with only 1 entry, the insert at index 2 is out of bounds.
The default _latin-font-list in styles.typ has 3 fonts so it works by default β but any user customization with fewer fonts will crash.
Suggested Fix
Use fonts.push(non-latin-font) or fonts.insert(calc.min(2, fonts.len()), non-latin-font) to handle arrays of any length.
Affected Versions
- 3.2.0 (current release)
- Also present in the cover letter modernization work (Cover Letter improvement - proposalΒ #96 / RFC: Cover letter module modernization (#96)Β #164)
Affected Files
src/lib.typβcv()function (line 46) andletter()function (line 134)