Skip to content

Failed subsetting for bitmap fonts #4572

Closed

Description

@qarmin

Description

File content(at the bottom should be attached raw, not formatted file - github removes some non-printable characters, so copying from here may not work):

\00

command

timeout -v 100 typst compile TEST___FILE.typ

cause this

thread 'main' panicked at crates/typst-pdf/src/font.rs:203:75:
called `Result::unwrap()` on an `Err` value: UnknownKind
stack backtrace:
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

##### Automatic Fuzzer note, output status "Some(101)", output signal "None"

compressed.zip

Reproduction URL

No response

Operating system

Linux

Typst version

  • I am using the latest version of Typst

Activity

  1. added
    bug
    on Jul 17, 2024
  2. bluebear94 commented on Jul 17, 2024

    @bluebear94
    Contributor

    This is planned to be turned into an export diagnostic:

    fn subset_font(font: &Font, glyph_remapper: &GlyphRemapper) -> Arc<Vec<u8>> {
    let data = font.data();
    // TODO: Fail export instead of unwrapping once export diagnoistics exist.
    let subsetted = subsetter::subset(data, font.index(), glyph_remapper).unwrap();

  3. LaurenzV commented on Jul 18, 2024

    @LaurenzV
    Collaborator

    That's weird though, in theory this should only fail if the font is invalid. So either some invalid font is used when rendering this, or there is a bug in the subsetter.

  4. LaurenzV commented on Jul 18, 2024

    @LaurenzV
    Collaborator

    And I can't reproduce it on my local machine. Do you think you could find out what font Typst is trying to use here? In case you can compile Typst yourself locally, you could do it by printing the font name in the subset_font method, for example.

  5. qarmin commented on Jul 18, 2024

    @qarmin
    Author

    Ubuntu 24.04, probably default font

    typst compile appendix_1182521647_IDX_13_RAND_16144817441186598688330.typ 
    [crates/typst-pdf/src/font.rs:201:5] &font = Font(Noto Color Emoji, Normal-400-FontStretch(1000))
    thread 'main' panicked at crates/typst-pdf/src/font.rs:204:75:
    called `Result::unwrap()` on an `Err` value: UnknownKind
    note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
    
  6. added
    urgent
    on Jul 18, 2024
  7. added
    crash
    on Jul 22, 2024
  8. laurmaedje commented on Jul 22, 2024

    @laurmaedje
    Member

    I can't reproduce this either, also not by setting Noto Color Emoji manually.

  9. qarmin commented on Jul 22, 2024

    @qarmin
    Author

    I cannot reproduce this with precompiled typst 0.11.1 (786457e) from https://github.com/typst/typst/releases/tag/v0.11.1
    but can with self-compiled version from git branch.

    This file was found by CI, so I'm almost sure that this not happens to only me

  10. LaurenzV commented on Jul 26, 2024

    @LaurenzV
    Collaborator

    I'm able to reproduce this on my Ubuntu virtual machine now, will try to look into it.

  11. LaurenzV commented on Jul 26, 2024

    @LaurenzV
    Collaborator

    @laurmaedje So it's pretty much as I expected, the bitmap version of Noto Color Emoji only has the CBDT/CBLC table, and in the subsetter we only check whether either CFF or glyf exists, otherwise we return UnknownKind. There was another user on Discord who also reported getting a crash, but in this case I suspect it's because it's trying to embed a CFF2 font.

    For this particular issue, we should probably try to figure out why Typst attempts to subset the font in the first place, as for bitmap-based fonts it should only ever store them as a color font.

    More generally, regarding the CFF2 thing, what should happen before the next update is:

    1. In subsetter we should probably add an additional hint to the error if CFF2 or any other of the color tables are present.
    2. Either we get export diagnostics before the next update, in which case we can catch the error and inform the user about it more appropriately, or we figure out some mechanism to not let Typst pick up CFF2 fonts in the first place.
  12. Andrew15-5 commented on Jul 29, 2024

    @Andrew15-5
    Contributor

    I can only reproduce with the git version, and it panics here:

    let subsetted = subsetter::subset(data, font.index(), glyph_remapper).unwrap();

    Reproduction:

    git checkout c4dd6fa06227b8c4a04cf488f371f52d5379ef9b &&
    printf '\x0' | RUST_BACKTRACE=full cargo run -- c -f pdf - /dev/null

    release and dev profiles. Linux.

    The title should include the NULL character instead of any 1 byte. Because other bytes are compiling just fine.

  13. removed
    needs-reproduction
    on Aug 5, 2024
  14. pavelzw commented on Aug 8, 2024

    @pavelzw
    Contributor

    I could reproduce the same/a similar error as well with a different example:

    #set text(font: "Apple Color Emoji")
    #emoji.face.grin some text

    With AppleColorEmoji.ttf being present in fonts/AppleColorEmoji.ttf

    ❯ typst compile --font-path fonts test.typ
    thread 'main' panicked at crates/typst-pdf/src/font.rs:202:75:
    called `Result::unwrap()` on an `Err` value: UnknownKind
    note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
    

    I got AppleColorEmoji.ttf from https://github.com/samuelngs/apple-emoji-linux/releases/download/v17.4/AppleColorEmoji.ttf (sha256 486dc940bc9b858fdf317f97aa607f04a850481074375551a9af87ea569550f1)
    Using the typst build from 7496dd7 on an M1 Pro MacBook (installed with brew install --HEAD typst).

  15. changed the title [-]Panic when compiling 1 byte file[/-] [+]Panic due to failed subsetting for bitmap fonts[/+] on Aug 12, 2024
  16. laurmaedje commented on Sep 17, 2024

    @laurmaedje
    Member

    I investigated this a bit with the Apple Color Emoji version linked above. While what Typst does is certainly not ideal, this font seems rather broken to me:

    • As @LaurenzV mentioned, it only contains a CBDT table, no glyf or CFF table. So far so good.
    • Its cmap maps the space character to glyph ID 3.
    • But the CDBT table does not contain an image for ID 3!

    Typst's is_color_glyph function thus returns false for id 3 and therefore tries to encode it as normal text and subsequently attempts subsetting it.

  17. laurmaedje commented on Oct 1, 2024

    @laurmaedje
    Member

    Subsetting shouldn't crash anymore as there are now export stage diagnostics. The font handling is still buggy though.

  18. removed
    crash
    urgent
    on Oct 1, 2024
  19. changed the title [-]Panic due to failed subsetting for bitmap fonts[/-] [+]Failed subsetting for bitmap fonts[/+] on Oct 1, 2024
  20. added
    pdf
    on Oct 1, 2024
  21. added
    urgent
    on Oct 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugpdfurgent

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions