PBXProjEncoder crashes when sorting projectReferences if ProjectRef file element has nil name

オープン
#1,055 コメント 1 件 リアクション 1 件 担当者 0 名 GitHub で見る

@Ant-tree がすでに取り組んでいます。

2026年2月11日 から。

  • #1056 @Ant-tree による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
swift
領域
build-system

調査の方向性

PBXProjEncoder.swift の 491 行目付近にある sortProjectReferences コードから始めます。ここでは PBXFileElement.name が force-unwrapped されています。ファイル要素がパスだけを持つプロジェクト参照でエンコードを再現し、その後、エンコードが成功し、ソートが利用可能な表示情報を使用してクラッシュしないことを検証します。

索引モデルが issue の本文から書いたものです。

説明

Summary

PBXProjEncoder crashes with Fatal error: Unexpectedly found nil while unwrapping an Optional value when encoding a project that containsPBXProject.projectReferences entries whose ProjectRef resolves to a PBXFileElement with name == nil.
This is common/valid in Xcode projects where PBXFileReference relies on path instead of name.

Steps to Reproduce

Create or open an .xcodeproj that includes a project reference (e.g., via Add Files to “…” → select another .xcodeproj).

Ensure the referenced PBXFileReference does NOT have a name field (only path), which is a typical pbxproj output.

Encode/write the project using XcodeProj with PBXOutputSettings.projReferenceFormat == .xcode (or any codepath that triggers sortProjectReferences).

Expected Behavior

Encoding should succeed. Sorting project references should use a stable display key even when name is nil (e.g., fallback to path).

Actual Behavior

Crash due to forced unwrap in PBXProjEncoder.sortProjectReferences:

  • let lName = lFile.name!
Stack Trace / Error
XcodeProj/PBXProjEncoder.swift:491: Fatal error: Unexpectedly found nil while unwrapping an Optional value
Root Cause

PBXFileElement.name is optional and may be nil for project references. The encoder assumes it is always non-nil and force-unwraps it during sorting.

Proposed Fix

Use a safe fallback when name is nil. For example:

displayName = name ?? path ?? ""

And compare displayName case-insensitively.

I have a PR ready that implements this fallback and prevents the crash.

Additional Notes

This occurs with valid pbxproj files produced by Xcode, since PBXFileReference often omits name and uses path as the display label.

主要言語
Swift
スター
2.2k
フォーク
356
平均マージ
5時間 54分
マージ済み PR(30日)
8

環境構築

  • Dockerfile・Docker Compose ファイルなし
  • プルリクエストのテンプレートあり
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

tuist/XcodeProj のほかの issue

tuist/XcodeProj の issue をすべて見る

似ている issue

Swift の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。