Skip to content

fix(torrent): write torrent files on iPhones - #653

Merged
linroid merged 1 commit into
mainfrom
fix/ios-torrent-sandbox-write
Oct 29, 2026
Merged

linroid merged 1 commit into
mainfrom
fix/ios-torrent-sandbox-write

Conversation

@linroid

@linroid linroid commented Oct 29, 2026

Copy link
Copy Markdown
Owner

Summary

A user with 30 GB free could not download a 1 GB torrent on an iPhone: every attempt failed with "Cannot write file · check free space and folder permissions" (KetchError.Disk).

  • SafeTorrentFileSystem (iOS) refused symlinks by opening every ancestor directory from / down with openat(O_DIRECTORY | O_NOFOLLOW). The iOS sandbox lets a directory be opened for reading only inside the app's own containers, so opening /private/var/mobile/Containers/Data/Application on the way down fails with EPERM, and with it every torrent write. HTTP downloads open files by their full path and were unaffected; the simulator is not sandboxed this way, which is why it never showed.
  • The parent directory is now opened in one call with O_NOFOLLOW_ANY (iOS 14.5+; the app targets 15), which still refuses a symlink in any path component, and the name is acted on relative to that descriptor as before. The /var → /private/var alias rewrite stays.

Test plan

  • New SafeTorrentFileSystemTest (iosTest): nested writes, a symlinked ancestor and a symlinked name are refused without touching the target
  • TorrentPieceStoreTest, TorrentV2PieceStoreTest, TorrentContentCatalogTest on the iOS simulator
  • A physical iPhone: retry the magnet that failed (the sandbox cannot be reproduced in the simulator)

Torrents on iOS failed with "Cannot write file" however much space was
free: the safe file system opened every ancestor directory from / down
with openat to refuse symlinks, and the app sandbox lets a directory be
opened for reading only inside the app's own containers, so opening
/private/var/mobile/Containers/Data/Application on the way down failed
with EPERM. HTTP downloads open files by their full path and were fine.

Open the parent directory in one call with O_NOFOLLOW_ANY, which still
refuses a symlink in any component, and act on the name relative to it.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-29T10:19:57.372474Z cb3c097 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@linroid
linroid merged commit 4bc1ef2 into main Oct 29, 2026
12 checks passed
@linroid
linroid deleted the fix/ios-torrent-sandbox-write branch October 29, 2026 10:19
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