Skip to content

Terminating typst may leave package cache in broken state #5935

Closed

Description

@laurmaedje

Description

If the typst process is terminated while it's unpacking a package, it will leave it in a half-extracted state and any future usage of the package may be broken.

Reproduction URL

No response

Operating system

No response

Typst version

  • I am using the latest version of Typst

Activity

  1. added
    bug
    cli
    packages
    on Feb 23, 2025
  2. laurmaedje commented on Feb 23, 2025

    @laurmaedje
    MemberAuthor

    Maybe we could download into a temporary directory and atomically move into the package cache, if it's not already there? That might also fix #2739.

  3. MultisampledNight commented on Feb 23, 2025

    @MultisampledNight
    Contributor

    It'd fix #2739 iff a different temporary directory is chosen for each Typst instance (i.e mktemp -d should suffice I think).

  4. Andrew15-5 commented on Feb 23, 2025

    @Andrew15-5
    Contributor

    Yes, but in the end, both instance would have to put the downloaded package into the same directory. Actually, I think on Unix it should be fine, since mv is an atomic operation and the files are only read and not written to. So if one instance will mv the exact same package directory to the target directory, replacing another one (package directory) would basically be a no-op. But I'm not sure that this is the case with all OSes/FSes.

  5. MultisampledNight commented on Feb 23, 2025

    @MultisampledNight
    Contributor

    Another possibility for this issue would be to keep an index of hashes. This would also allow detection of corruption due to e.g. faulty disks or sudden network disconnects.

    Cryptography rambling

    That would suffice to ensure integrity (contents haven't been modified since hashed).

    Theoretically we could also go one step further and also ensure authenticity via signing. The workflow for that could look like a set of ed25519 pubkeys in the repo, each package author has to submit theirs and sign each package addition/update with their key. The signature could be stored alongside the package.
    Advantages: Authenticity, hash index replaced by less often updated key index, could decentralize package index to instead fetch from author repos at a later point.
    Disadvantages: The key index still has to be updated, cryptography is difficult and it's likely to be at least somewhere minimally wrong → more attack surface.

  6. Andrew15-5 commented on Feb 23, 2025

    @Andrew15-5
    Contributor

    The hashes are nice, but Typst is not Nix, and usually checksum is checked manually, so this can be somewhat possible in the future, but I don't think it's necessary. If anything, an author absolutely can add some integrity/authenticity files in the package for anyone to check that, but adding this to the CLI at least now is definitely overkill. And mandating any of that from the authors is definitely a bad experience, as most people don't care, or it will be bothersome, and some might not even know about this (and how it works).

  7. istudyatuni commented on Feb 25, 2025

    @istudyatuni
    Contributor

    mktemp -d

    I think this is bad because tmp directory could be on another drive, so it's better to store downloads alongside main cache

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

    bugclipackages

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions