Skip to content

harden performance and safety - #18

Merged
takeokunn merged 5 commits into
mainfrom
feat/harden-performance-and-safety
Jul 18, 2026
Merged

harden performance and safety#18
takeokunn merged 5 commits into
mainfrom
feat/harden-performance-and-safety

Conversation

@takeokunn

Copy link
Copy Markdown
Collaborator

概要 / Summary

paredit安全性と性能をハードニングする変更です。信頼できない入力(悪意あるシンボル名・パス・深いネスト・シンボリックリンク)や書き込み中の失敗に対する堅牢性を高め、CI のサプライチェーンを固めます。全体で 199 files, +18,870 / −2,981。テーマ別に 5 コミットへ整理しています。

変更内容 / What changed

1. ci: サプライチェーン / MSRV / macOS 対応

  • すべての GitHub Actions を commit SHA でピン留め(タグ差し替え型攻撃対策)
  • cargo audit --deny warnings の supply-chain ジョブを追加、flake checks に cargo-audit と MSRV ツールチェーンのビルド/テストを組み込み
  • 検証ワークフローを ubuntu-latest + macos-latest のマトリクスで実行
  • CI 契約を回帰テスト(action_contract)で担保

2. feat(io): 原子的書き込み + workspace discovery 強化

  • インプレース書き込みを staged temp-file + atomic-exchange 方式へ置換し、失敗時はロールバック
  • symlink / TOCTOU 攻撃対策として device/inode 同一性チェック(FilesystemIdentity)と cap-std のケーパビリティアクセスを導入
  • 書き換え時に xattr を保存、macOS では ACL も保存
  • 入力を MAX_SOURCE_INPUT_BYTES で上限化、成果物を blake3 でハッシュ
  • workspace discovery で symlink をスキップし、スキップ数を隠蔽 API で公開
  • ACL FFI モジュール限定で unsafe_codeforbid → deny に緩和

3. feat(cli): 端末出力の制御文字エスケープ

  • ANSI エスケープ・双方向オーバーライド等でターミナルを偽装/破壊しうる制御文字を、terminal_safe ラッパと safe_text! マクロで全 CLI 出力パスでエスケープ
  • エラーチェーンも terminal_safe_error_chain 経由に
  • terminal_output_safety 統合テストを追加

4. refactor(domain): パーサ / リファクタリングエンジンの堅牢化

  • パーサの panic / 暗黙失敗を明示的な ParseError 化、MAX_DISCARDED_FORM_STACK_FRAMES で再帰を有界化(リソース枯渇対策)
  • span 置換を境界・オーバーフロー検査つきに(replace_span_checked)、Result を伝播
  • 構文木がソーステキストを保持する設計へ変更(呼び出し側の再スレッド不要に)
  • diff 計算にリソース上限(LCS セル数・行/操作/出力サイズ)

5. perf(similarity): similarity レポート収集の高速化

  • 候補フォーム収集の重複走査・アロケーションを削減、収集エラーを破棄せず保持

検証 / Verification

  • cargo build ✅ / cargo test1088 passed, 0 failed / cargo clippy --all-targets ✅ / cargo fmt --check

備考: 各コミットはレビュー単位でテーマ分割していますが、SyntaxTree のテキスト所有化リファクタが層をまたぐため、中間コミット単体でのビルドは保証していません(ブランチ先端はグリーン)。

…coverage

- Pin every GitHub Action to a commit SHA in the CI, docs, and composite
  action workflows to prevent tag-repointing supply-chain attacks.
- Add a supply-chain job that runs `cargo audit --deny warnings`, and wire
  cargo-audit plus an MSRV toolchain build/test into the flake checks.
- Run the verification workflow on both ubuntu-latest and macos-latest.
- Cover the new CI contract with an action_contract regression test.
@takeokunn
takeokunn force-pushed the feat/harden-performance-and-safety branch 2 times, most recently from ae2f190 to 202a184 Compare July 18, 2026 00:26
- Replace in-place writes with staged temp-file + atomic-exchange writes that
  roll back on failure, guarded against symlink and TOCTOU attacks via device
  and inode identity checks (FilesystemIdentity) and cap-std capability access.
- Preserve extended attributes (xattr) and, on macOS, ACLs when rewriting files.
- Cap source input at MAX_SOURCE_INPUT_BYTES and content-hash artifacts (blake3).
- Skip symlinks during workspace discovery and expose skip counts through an
  encapsulated Discovery API (files()/into_files()/read_file()).
- Relax unsafe_code from forbid to deny so the isolated macOS ACL FFI module can
  opt in locally; add cap-std, xattr, blake3, and libc dependencies.
- Expand the packaging include list and cover symlink refusal with tests.
Untrusted symbol names, paths, and error messages can carry ANSI escapes,
bidirectional overrides, and other control characters that spoof or corrupt
terminal output. Introduce a terminal_safe wrapper and safe_text! macro that
escape these code points, route error chains through terminal_safe_error_chain,
and apply the wrapper across every CLI render and workflow path.
Add a terminal_output_safety integration test.
…med input

- Turn parser panics and silent failures into explicit ParseError variants
  (DanglingSingleEscape, MissingReaderForm) and bound discarded-form recursion
  with MAX_DISCARDED_FORM_STACK_FRAMES to resist resource-exhaustion inputs.
- Make span replacement bounds- and overflow-checked (replace_span_checked) and
  propagate Result through Edit::replace and downstream refactorings.
- Let the syntax tree own its source text so selections and renames no longer
  require the caller to re-thread the original input.
- Cap diff computation (LCS cells, line/op/output limits) to avoid pathological
  blowups on adversarial inputs.
- Refresh domain and CLI regression tests for the new signatures and errors.
Restructure similarity report collection to reduce redundant traversal and
allocation when gathering candidate forms, and preserve collection errors
instead of discarding them.
@takeokunn
takeokunn force-pushed the feat/harden-performance-and-safety branch from 202a184 to d8c7a85 Compare July 18, 2026 00:40
@takeokunn
takeokunn merged commit d556540 into main Jul 18, 2026
3 checks passed
@takeokunn
takeokunn deleted the feat/harden-performance-and-safety branch July 18, 2026 00:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant