Skip to content

Extract shared subprocess execution into a common crate #32

Closed

Description

@nishide-dev

背景

外部コマンドを制限付きで実行するコードが、2 つの crate にほぼ同じ構造で実装されている(docs/security.md §3.2 / §3.4 / §3.6)。

共通する処理:

  • process_group(0) で起動する
  • try_wait・cancel・deadline・出力サイズを、1 つの poll ループで確認する
  • process group に SIGKILL を送る。正常終了した後も送る
  • reader thread で stdout / stderr を上限付きで最後まで読む
  • Linux では prlimit(2) で rlimit を設定する

細部の値や方針は、両者で食い違っている。

このまま機能を足していくと、片方だけ修正される不整合が起きやすい。
PR #31 のレビュー(N1)で提案された。

スコープ

  • 共通の crate(例: crates/texrun-process)を作り、次のものを移す
    • 制限付き実行の API(env allowlist、process group、poll ループ、group kill、Drop guard、EINTR の retry、出力の上限付き読み出し、Linux の prlimit)
  • feat(texlive): add latexmk engine #30 と feat(preview): render PDF pages to PNG previews #31 の実装をその crate に置き換える
  • poll 間隔・grace などの定数は、呼び出し側から指定できるようにするか、1 つに統一する
  • 次のものは移さない(非スコープ)
    • latexmk の rc や stdin gate など、engine 固有の部分
    • preview の backend 固有の部分

完了条件

  • 両 crate が共通の実行 API を使っている
  • process group kill・timeout・cancel・rlimit の test が、共通 crate にまとまっている
  • docs/security.md §3.6 の記述が、共通 crate を指している

依存

Activity

  1. added this to the MVP milestone on Sep 30, 2026
  2. added
    enhancement
    security
    on Sep 30, 2026
  3. nishide-dev commented on Sep 30, 2026

    @nishide-dev
    OwnerAuthor

    PR #31 再レビューからの追加: preview の scratch dir(.texrun-preview-* 作成、work/ の open、tool の cwd / 出力先)がまだ path ベース。共通化時に mkdirat / openat に揃える。また PdfInfo.pages の pt 値は UserUnit ページで backend により異なる(mupdf は係数反映、poppler は非反映)ので rustdoc に明記する。

  4. removed this from the MVP milestone on Sep 30, 2026
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

    enhancementsecurity

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions