File tree Expand file tree Collapse file tree 2 files changed +24
-2
lines changed
Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -114,6 +114,22 @@ public void CreationDate_UnixTimeInMilliseconds_IsParsed()
114114 torrent . CreationDate . Should ( ) . Be ( new DateTime ( 2016 , 1 , 1 ) ) ;
115115 }
116116
117+ [ Theory ]
118+ [ AutoMockedData ]
119+ public void CreationDate_InvalidValue_ReturnsEpoch ( )
120+ {
121+ // Arrange
122+ ParsedData = ValidSingleFileTorrentData ;
123+ ParsedData [ TorrentFields . CreationDate ] = ( BNumber ) long . MaxValue ;
124+
125+ // Act
126+ var parser = new TorrentParser ( BencodeParser ) ;
127+ var torrent = parser . Parse ( ( BencodeStream ) null ) ;
128+
129+ // Assert
130+ torrent . CreationDate . Should ( ) . Be ( new DateTime ( 1970 , 1 , 1 ) ) ;
131+ }
132+
117133 [ Theory ]
118134 [ InlineAutoMockedData ( "utf8" ) ]
119135 [ InlineAutoMockedData ( "UTF8" ) ]
Original file line number Diff line number Diff line change @@ -75,8 +75,14 @@ public static implicit operator bool(BNumber bint)
7575
7676 if ( number . Value > int . MaxValue )
7777 {
78- // Assuming unix timestamp is in milliseconds instead of seconds
79- return Epoch . AddMilliseconds ( number ) ;
78+ try
79+ {
80+ return Epoch . AddMilliseconds ( number ) ;
81+ }
82+ catch ( ArgumentOutOfRangeException )
83+ {
84+ return Epoch ;
85+ }
8086 }
8187
8288 return Epoch . AddSeconds ( number ) ;
You can’t perform that action at this time.
0 commit comments