Skip to content

bug: non-Latin font insert crashes when regular_fonts has fewer than 3 entriesΒ #165

@yunanwg

Description

@yunanwg

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

  1. In metadata.toml, set:
[layout.fonts]
    regular_fonts = ["Source Sans 3"]  # only 1 font
  1. Compile with a non-Latin language:
typst compile template/cv.typ --input language=zh
  1. 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

Affected Files

  • src/lib.typ β€” cv() function (line 46) and letter() function (line 134)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions