tooling: reject deeply nested bencode in decode_torrent #637
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/643"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by louisdibiasi on 2026-11-22T17:16:31Z.
Change
decode_torrentintools/verify_build.pyreads lists and dictionaries recursively with no depth limit. A torrent that nests a few thousand levels, closed or not, exhausts the interpreter's recursion limit and raisesRecursionError. The decoder's contract, checked bycheck_decode_torrent, is that malformed input raisesValueError. This addsMAX_TORRENT_DEPTH = 64and raisesValueError("Torrent nesting too deep")beyond it. Real multi-file torrents nest about four levels.Independent problem, no linked issue.
Verification
Commit under test:
534f673onb03f754, Windows 11, Python 3.12.10.python -B tests/layout_chunks_check.pyRecursionError: maximum recursion depth exceeded, exit 1.layout chunk summary ok, exit 0.New cases in
check_decode_torrent:b"l"*5000 + b"e"*5000andb"l"*5000andb"d1:a"*5000must raiseValueError; a 32-level list still decodes. I also checked the boundary by hand: 64 levels decode, 65 raiseValueError.Evidence and follow-up
Synthetic bytes only. The CLI (
python tools/verify_build.py <dir>) still ends with an uncaughtValueErrortraceback for any malformed torrent, including this one; that is existing behavior for every malformed torrent and I left it out to keep this PR to the decoder. I can send a separate PR for reporting torrent errors throughparser.error.Checklist
AI-assisted: I used Claude to find the bug and draft the change. I ran the reproductions and tests above myself.
Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-22T17:35:29Z.
Coordination note: this PR and #644 both edit
tests/layout_chunks_check.py. I checked534f673(#643) anda6668be(#644) on Windows 11 26100.9168 with Python 3.12.10:mainat8f57366.python -B tests/layout_chunks_check.pyprintslayout chunk summary ok.They can land in either order.
AI-assisted (Claude Code).