Skip to content

fix(torrent): fail at once on a torrent file over the size limit - #634

Merged
linroid merged 1 commit into
mainfrom
fix/torrent-oversized-metainfo
Oct 23, 2026
Merged

linroid merged 1 commit into
mainfrom
fix/torrent-oversized-metainfo

Conversation

@linroid

@linroid linroid commented Oct 23, 2026

Copy link
Copy Markdown
Owner

Problem

A .torrent link that serves more than TorrentConfig.maxMetadataBytes (4 MiB) is either not a torrent or one Ketch won't read. It failed like this:

Download failed: Network: Network error occurred <- IllegalArgumentException: HTTP response exceeds torrent limit

TorrentHttp.fetch enforces the limit with a require inside the engine's onData callback. KtorHttpEngine reports whatever a callback throws as a retryable KetchError.Network, so the download retried three times, about 7 s, before failing with a message that didn't help. A local file over the limit failed with Metainfo exceeds limit.

Fix

  • TorrentHttp.fetch throws a ResponseTooLargeException, an IllegalArgumentException with the same message, so trackers and tracker lists see what they saw before. It also unwraps the exception when an engine reported it as a Network error.
  • Fetched and local metainfo over the limit now fail with a non-retryable KetchError.SourceError: "The torrent file is larger than 4 MiB, the most Ketch reads".
Download failed: The torrent file is larger than 4 MiB, the most Ketch reads <- ResponseTooLargeException: HTTP response exceeds torrent limit

Tests

  • TorrentDownloadSourceResolveTest.resolveUrl_metainfoLargerThanTheLimit_failsWithoutRetrying: an engine that wraps callback failures as KtorHttpEngine does. The test fails without the fix.
  • Checked by hand with the CLI:
    • An 8 MB file served as garbage.torrent now fails in 1 s instead of 7 s.
    • A 5 MB local .torrent fails with the same message.
    • A truncated torrent still says Unterminated bencode container.

A .torrent link serving more than the 4 MiB Ketch reads failed with
"Network: Network error occurred <- IllegalArgumentException: HTTP
response exceeds torrent limit": KtorHttpEngine reports what a
download callback throws as a network failure, so the download retried
it three times before failing, and said nothing useful.

TorrentHttp.fetch now throws ResponseTooLargeException past its limit,
also when an engine wrapped it in a network error, and the source turns
it, and a local file over the limit, into a SourceError saying "The
torrent file is larger than 4 MiB, the most Ketch reads".
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 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-23T18:36:45.403771Z 7591e48 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.

@claude

claude Bot commented Oct 23, 2026

Copy link
Copy Markdown

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

@github-actions

Copy link
Copy Markdown
Contributor

Test Results

 2 200 files  ±0   2 228 suites  ±0   57m 18s ⏱️ -27s
15 370 tests +3  15 102 ✅ +3  268 💤 ±0  0 ❌ ±0 
18 731 runs  +5  18 463 ✅ +5  268 💤 ±0  0 ❌ ±0 

Results for commit 7591e48. ± Comparison against base commit d3c7122.

@linroid
linroid merged commit 73c60d3 into main Oct 23, 2026
15 checks passed
@linroid
linroid deleted the fix/torrent-oversized-metainfo branch October 23, 2026 19:15
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