Skip to content

Verify streamed v2 and hybrid payload pieces - #175

Closed
linroid wants to merge 2 commits into
torrent-v2-06-layoutfrom
torrent-v2-06-verification
Closed

linroid wants to merge 2 commits into
torrent-v2-06-layoutfrom
torrent-v2-06-verification

Conversation

@linroid

@linroid linroid commented Sep 12, 2026

Copy link
Copy Markdown
Owner

Authenticate streamed v2 pieces against the imported file root or validated piece-layer hash before storage can commit them. Short final pieces expand with zero-hash subtrees to the required layer; hybrid pieces must also match SHA-1, including virtual padding. Hashing retains bounded state without a full-piece buffer.

Stack: based on #174, advancing #162 step 06. This is the integrity boundary; storage staging, durable commit, generation barriers and runtime v2 download integration remain pending.

Validation: 350 torrent JVM tests passed with no failures or skips, including both existing pinned-client v1 conformance scenarios. The native-runtime dependency guard passed. New tests cover short piece-layer tails, smaller file-root trees, streaming input validation, conflicting hybrid hashes and virtual padding. These tests do not establish v2 client interoperability.

@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-12T14:21:55.270928Z 206fb16 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: 206fb16fa2

ℹ️ 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 +74 to +77
var remaining = protocolLength - payloadLength
while (remaining > 0) {
val count = minOf(remaining, zeros.size.toLong()).toInt()
sha1.update(zeros, 0, count)

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 Bound hashing of virtual padding

When a hybrid document declares a very large valid power-of-two piece length and a tiny file followed by matching padding, TorrentV2Info.parse and TorrentHybridLayout.parse accept it, but this loop hashes every virtual byte in 4 KiB increments. For example, a one-byte payload with a 2^62-byte piece causes roughly 10^15 SHA-1 updates, effectively hanging verification despite receiving almost no payload. Enforce the runtime piece-length limit before constructing the verifier, or reject/cap protocolLength - payloadLength here.

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 8b365cd. TorrentPayloadVerifier now enforces the existing runtime 16 MiB piece ceiling before constructing the layout or hashing padding. Parsing can still describe larger protocol-valid dimensions. The regression constructs the one-byte/2^62-byte hybrid case and verifies immediate rejection, plus rejection above the ceiling and acceptance at the ceiling. All five focused verifier tests and the native-runtime dependency guard pass. The fix is also propagated into #176.

@github-actions

github-actions Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Test Results

  543 files  + 5    543 suites  +5   3m 49s ⏱️ -8s
2 446 tests +15  2 446 ✅ +15  0 💤 ±0  0 ❌ ±0 
3 146 runs  +25  3 146 ✅ +25  0 💤 ±0  0 ❌ ±0 

Results for commit 8b365cd. ± Comparison against base commit 6531316.

♻️ This comment has been updated with latest results.

@linroid

linroid commented Sep 20, 2026

Copy link
Copy Markdown
Owner Author

Superseded by #233 (V2 layout and verified storage) 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-06-verification 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