Repository navigation
fix(torrent): open torrents with unsafe names, padding files and long lists - #561
Merged
Merged
Conversation
… lists Ordinary torrents that Ketch refused, or never finished resolving, now open and download: - v1 names that some system cannot store (`<>:"|?*`, trailing dots or spaces, Windows device names, names over 255 bytes) are cleaned with core's sanitizeFileName instead of refusing the torrent; only traversal is refused. Names that were accepted before stay as they are, so saved tasks keep their files, and collisions are checked on the cleaned paths. v2 and hybrid names keep their %xx escaping. - BEP 47 padding in v1 torrents (attr `p`, or BitComet's unmarked padding files) is never listed, selected, written or asked of web seeds; the v1 store hashes and serves it as zeros. Selections older builds saved that name padding files still load. - Metadata that matches a magnet's hash but does not parse ends the lookup with a clear reason instead of being blamed on each peer forever. - Over 4096 lookup peers, 128 trackers or 100,000 bencode values now cap instead of failing; v2 resolution skips trackers Ketch cannot announce to, such as wss://. - v2 and hybrid magnets keep looking after a timed-out lookup: the retry log read the v1 hash and threw. - Catalog objects and the v2 creation log publish without hard links where the file system has none (FAT, exFAT, some network shares): an exclusive create claims the name, then the written file moves over it, so an existing file is still never replaced.
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ca78736514
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Skipping unsupported trackers let a private (or tracker-only) .torrent whose only trackers are wss:// resolve, then wait forever with no way to find a peer. New metainfo inputs, v1 and v2, that find peers only through trackers and have no http, https or udp tracker and no web seed are now refused with that reason. A saved task's metainfo is still read without the check.
Contributor
linroid
enabled auto-merge (squash)
October 16, 2026 12:58
…ures # Conflicts: # AGENTS.md # docs/torrent.md
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.
What
Ordinary torrents that Ketch refused, or never finished resolving, now open and download. This covers the "torrents fail to open" findings of the 2026-10-16 torrent review; throughput, client identity and the other findings are separate.
: ? " < > | *, ending in.or a space, naming a Windows device (aux.c) or longer than 255 bytes no longer refuses the whole torrent. It is stored, and listed, under the name core'ssanitizeFileNamemakes ("Who?.flac" → "Who_.flac"). Only traversal is refused: empty names,.,..,/,\and control characters. Collision checks (canonicalTorrentName, ignoring case) run on the cleaned paths.UnusableTorrentMetadataException, whichresolvereports asKetchError.SourceErrorwith the parser's reason. v2 piece layers fetched from a peer still count as that peer's failures.p, or BitComet's unmarked_____padding_file_…entries). These are never listed, selected, written or asked of web seeds. The v1 store hashes and serves them as zeros,.pad/<n>duplicates no longer count as colliding paths, and resolved sizes and admission count only content files.MagnetUri.infoHash, which throws for btmh magnets; it now useslogTopic. v2 resolution and tracker-only lookups skip trackers Ketch cannot announce to, such aswss://(TrackerConfiguration.usable), instead of failing.preparestays strict for tracker edits.torrentPublishCatalogObject(catalog objects and the v2 creation log) used to fail with a non-retriedKetchError.Diskon FAT, exFAT and some network shares. Where the file system refuses the link, it now claims the name with an exclusive create and moves the written file over it, so an existing file is still never replaced. An empty file left at the name by a crash between the two steps is read as missing and taken over by the next publication.Which names each caller checks
validateTorrentComponent): the v1 parser, on the name and every path component.validateDiskComponent/isDiskComponent):TorrentPieceStore.filePath,TorrentV2PieceStore(output and creation log names),TorrentV2Checkpoint,TorrentV2CreationLog,TorrentCheckpointFileandTorrentContentCatalog.TorrentOutputMapping's choice between keeping a v2 name and escaping it.resolveV2Metainfo's display-name fallback.Compatibility
diskComponentreturns every name the old validator accepted unchanged, so saved v1 tasks and checkpoints keep their paths. Only names that used to refuse the torrent are cleaned.%xxnames and the saved checkpoints and creation logs that name them still match. A test pins this.Testing
./gradlew :library:torrent:jvmTest: 1,319 tests, 0 failures.compileTestKotlinIosSimulatorArm64(iOS main and tests) andcompileAndroidMain.TorrentNamesTest;TorrentMetadataTest(cleaned paths, raw paths, traversal refused, collisions after cleaning);TorrentPieceStoreTest.unsafeNames_storedUnderCleanedNames;TorrentDownloadSourceResolveTest;MetainfoValidationTest; and the pinned v2 mapping inTorrentOutputMappingTest.TorrentMetadataExchangeTest.exchange_infoMatchingItsHashThatDoesNotParse_isUnusableandTorrentMetadataPeersTest.unusableMetadata_endsTheLookup.TorrentMetadataTest.fromBencode_v1Padding_keptOutOfTheContentFiles;TorrentPieceStoreTest(never written, read as zeros, older builds' selections and pad files); andTorrentWebSeedTest.multiFile_paddingNeverRequestedAndFilesAskedByTheirTorrentNames, where the mirror is asked forWho%3F.bin, which is stored asWho_.bin.TrackerConfiguration.usable, and 8,000 files ten folders deep.TorrentDownloadSourceResolveTest.resolve_v2MagnetNotFoundWhileInfoIsLogged_looksAgain, which runs a real engine with an info logger installed;MagnetTrackersTestforwss://on a v2 magnet; and a hybrid.torrentwith awss://tier.TorrentContentCatalogTest(claim then move, never replacing, takeover of an empty name, a catalog without links) andTorrentV2CreationLogTest.Not changed (follow-ups)
Who?.flacbecomes%57%68…), because changing that needs a new output-mapping version.comment, magnetdn) still refuse the input.leftstill counts padding bytes in incomplete pieces.