Skip to content

Crash when determining link parent in PDF export #7301

Closed

Description

@aersam

Description

We generate lot's of PDF's using typst, but sometimes we randomly get this error:

panicked at ...\typst-pdf-0.14.0\src\link.rs:87:55: link parent

Reproduction URL

No response

Operating system

Windows

Typst version

  • I am using the latest version of Typst

Activity

  1. added
    bug
    on Nov 4, 2025
  2. laurmaedje commented on Nov 10, 2025

    @laurmaedje
    Member

    Would you be able to provide the source code that led to the crash?

    Also a note for the future: The issue contains a lot of irrelevant information, which diverts from the point being made. The whole PyO3 thing is unrelated. It's best to keep the issue focused to the problem itself. I edited it now to make it a bit clearer.

  3. changed the title [-]pyo3_runtime.PanicException: link parent[/-] [+]Crash when determining link parent in PDF export[/+] on Nov 10, 2025
  4. added
    pdf
    crash
    on Nov 10, 2025
  5. aersam commented on Nov 12, 2025

    @aersam
    Author

    Would you be able to provide the source code that led to the crash?

    Also a note for the future: The issue contains a lot of irrelevant information, which diverts from the point being made. The whole PyO3 thing is unrelated. It's best to keep the issue focused to the problem itself. I edited it now to make it a bit clearer.

    Ok, I was able to create a pretty minimal repo:

    #link("asf")[#none\ #none]
  6. added
    urgent
    on Nov 12, 2025
  7. saecki commented on Nov 12, 2025

    @saecki
    Member

    The problem is that the space which has the LinkElem::curent style applied is extracted from within the link-marker tags:

    for _ in s.sink.extract_if(end.., |(c, _)| c.is::<SpaceElem>()) {}

  8. Pascal-So commented on Nov 14, 2025

    @Pascal-So
    Sponsor

    I stumbled across another example of this same panic which I managed to reduce to this snippet:

    #footnote(numbering: it => "", [asdf])

    Note however that the following code works just fine??

    #place(footnote(numbering: it => "", [asdf]))

    Not sure if this is the same underlying issue of if it's a different case. Hope it helps. Tested in typst 0.14.0.

  9. saecki commented on Nov 24, 2025

    @saecki
    Member

    I stumbled across another example of this same panic which I managed to reduce to this snippet:

    #footnote(numbering: it => "", [asdf])

    This seems to be the same root cause. Since there is no other content inside the link body, the link target is applied to a space element.

  10. laurmaedje commented on Nov 25, 2025

    @laurmaedje
    Member

    Here's a spaceless reproduction:

    #link("asdf", linebreak())

    (Should be saved without any trailing whitespace.)

  11. saecki commented on Nov 25, 2025

    @saecki
    Member

    I think I get it now, in order for the FrameItem::Link to be generated within the start and end tags of the LinkMarker, the content of the link marker has to produce a frame (which may then be inlined depending on Frame::should_inline). If for some reason the style applies to the outer frame which already contains the start and end tags, the FrameItem::Link is appended to that frame and thus not inside the tags.
    I'm not yet sure, when exactly this happens and how to prevent this but I'll investigate further.

    Somewhere during inline::linebreak the linebreak text item "\n" gets removed from between the tags, and an empty text item "" is inserted after the end tags.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugcrashpdfurgent

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions