Krusen / BencodeNET

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

ArgumentOutOfRangeException in TorrentParser.CreateTorrent() #26

Closed Sleepyowl closed 7 years ago

Sleepyowl commented 7 years ago

Parsing a specific torrent file fails with ArgumentOutOfRangeException:

System.ArgumentOutOfRangeException: Value to add was out of range.
Parameter name: value
   at System.DateTime.Add(Double value, Int32 scale)
   at BencodeNET.Objects.BNumber.op_Implicit(BNumber number)
   at BencodeNET.Parsing.TorrentParser.CreateTorrent(BDictionary data)
   at BencodeNET.Parsing.BencodeParser.Parse[T](BencodeStream stream)
   at BencodeNET.Parsing.BencodeParser.Parse[T](Byte[] bytes)

qbittorent opens file without any errors or warnings.

Please find the torrent file in question attached.

3AC38643197FE34CD73DC311BBB75DF416E617E6.zip

Krusen commented 7 years ago

The issue was the creation date timestamp being in milliseconds instead of seconds which it should be according to the specification.

I've added support for this in v2.2.4, which should be available on NuGet shortly.

Sleepyowl commented 7 years ago

There's one more torrent file that fails on version 2.2.4 with the same exception and stack trace.

Please find it attached.

78EA509BA01BBCB00073455317FFE6CCF4B93AE8.zip

Krusen commented 7 years ago

That's even worse. That creation date appears to be in microseconds. I'll see if I can handle that as well.

Sleepyowl commented 7 years ago

@Krusen Just for reference, libtorrent (and qbittorrent as a consequence) does not implement any special logic to handle that. It just treats creation date as time_t (unix time). For the torrent I've attached qBittorrent displays creation date as "6/21/2083 17:44".

Krusen commented 7 years ago

Actually it's not even microseconds, it just seems to be invalid.

2,2.5 should be available soon and will just return epoch (1970-01-01) if the timestamp is not in either seconds or milliseconds.