Skip to content

feat(torrent): validate v2 info trees and external piece layers - #172

Closed
linroid wants to merge 3 commits into
torrent-v2-04-identityfrom
torrent-v2-04-info
Closed

linroid wants to merge 3 commits into
torrent-v2-04-identityfrom
torrent-v2-04-info

Conversation

@linroid

@linroid linroid commented Sep 12, 2026

Copy link
Copy Markdown
Owner

Add bounded parsing of the v2 fields in a raw info dictionary and authentication of its imported external piece layers. Raw paths and info bytes remain byte-exact; version, piece geometry, file-tree structure, lengths, root sizes, and caller-supplied exact topics are validated before returning metadata.

Part of #162, stacked on #171 (torrent-v2-04-identity). The piece-layer verifier streams individual hashes through a shared Merkle frontier, applies zero padding at the piece-size layer, and checks each root/topology once when several files share a layer. The dictionary adapter rejects missing/unreferenced roots, incorrect hash counts, corrupt hashes, and excess layer bytes.

The raw-info parser does not validate the enclosing metainfo document or a hybrid's v1 layout. Filesystem mapping, streaming/spilled metainfo loading, wire acquisition, and v2 download integration remain separate roadmap work. These internal primitives do not advertise completed v2 support.

Validation: focused parser, layer, and Merkle tests pass, including independent JDK full-tree comparisons across piece sizes and incomplete subtrees. All 333 local torrent tests passed with no skipped tests, both pinned-client conformance scenarios executed, and the native-runtime dependency guard passed.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 12, 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-09-12T13:50:41.723572Z 311f27a 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 311f27a506

ℹ️ 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".

Comment on lines +67 to +68
} else {
for ((component, child) in entries) visit(child, path + component)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject empty directory nodes in file trees

When a tree contains an empty dictionary below a path alongside at least one valid file, this branch iterates zero children and silently discards that subtree, so parse() returns supposedly validated metadata for a malformed BEP 52 file tree. Require non-file nodes to contain at least one child before traversing them.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 6818eff. Non-file nodes now require at least one child. Regression coverage rejects direct and nested empty directories beside a valid file while still accepting zero-length files. The focused v2 info and piece-layer tests pass.

@github-actions

Copy link
Copy Markdown
Contributor

Test Results

  523 files  +13    523 suites  +13   3m 51s ⏱️ -10s
2 395 tests +28  2 395 ✅ +28  0 💤 ±0  0 ❌ ±0 
3 061 runs  +48  3 061 ✅ +48  0 💤 ±0  0 ❌ ±0 

Results for commit 6818eff. ± Comparison against base commit c727d19.

@linroid

linroid commented Sep 20, 2026

Copy link
Copy Markdown
Owner Author

Superseded by #232 (V2 identity, metainfo and Merkle integrity) in the consolidated eight-PR stack for #162.

The replacement preserves this PR's code and subsequent fixes; its description links the original head and review discussions. The only additional consolidation fix is the CI-discovered listener cancellation regression, documented on the replacement. All eight replacements have passed their required CI checks.

Closing without merging. This branch and its discussions remain available for reference. Review index: #162 (comment)

@linroid linroid closed this Sep 20, 2026
@linroid
linroid deleted the torrent-v2-04-info branch September 20, 2026 11:12
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