Repository navigation
fix(torrent): write torrent files on iPhones - #653
Merged
Merged
Conversation
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.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 withopenat(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/Applicationon the way down fails withEPERM, 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.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/varalias rewrite stays.Test plan
SafeTorrentFileSystemTest(iosTest): nested writes, a symlinked ancestor and a symlinked name are refused without touching the targetTorrentPieceStoreTest,TorrentV2PieceStoreTest,TorrentContentCatalogTeston the iOS simulator