Krusen / BencodeNET

.NET library for encoding/decoding bencode and reading/writing torrent files
The Unlicense
152 stars 28 forks source link

BencodeNET.Exceptions.InvalidTorrentException when parsing torrent that opens in qbittorrent #27

Closed Sleepyowl closed 7 years ago

Sleepyowl commented 7 years ago

I've got a torrent file that has both "length" and "files" fields in the info dictionary.

I do realise that it's a clear violation of BEP3 that states:

There is also a key length or a key files, but not both or neither.

But unfortunately torrents like that do exist and qBittorrent opens then without errors or warnings.

If you don't want to ignore this error in torrent's metadata, how about adding a "forgiving" parser option?

Please find the example of malformed torrent in the attachment.

B98382409D888F8F9C6F1CBACD8E62BEC46FC8EE.zip

Krusen commented 7 years ago

Version 2.2.9 is out on NuGet and allows you to specify a parse mode - TorrentParserMode.Strict or TorrentParserMode.Tolerant.

TorrentParserMode.Tolerant will skip all checks for required fields and just parse whatever it can.

You can change the mode like this:

var parser = new BencodeParser();
parser.Parsers.GetSpecific<TorrentParser>().ParseMode = TorrentParserMode.Tolerant;

Accessing a specific parser is not very pretty as it is made to be very generic. I will probably change this in the future for a possible version 3.0.