Improve compatibility BEP47 torrents #688
Merged
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.
If padding is unnecessarily applied to the last file in the torrent, do not strip it out.
As padding is not explicitly specified in the BitTorrent V2 file information, MonoTorrent uses the heuristic "pad the current file such that the next file begins at a piece boundary", which means the final file has no padding. As long as the v1 piece hash information has no padding, this is all good and the sanity checks which make sure V1 and V2 metadata match all succeed.
However, if padding is assumed to be zero for the final file when parsing the v2 file tree, and the v1 file tree has a padding file as the last entry in the torrent, then there'll be a mismatch and the torrent won't load.
This fixes the issue by just copying the padding value applied to the last file in the V1 metadata to the last file in the v2 metadata.
This allows things to hashcheck correctly.