You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: BencodeNET.Net45/Bencode.cs
+24-40Lines changed: 24 additions & 40 deletions
Original file line number
Diff line number
Diff line change
@@ -232,69 +232,53 @@ public static BNumber DecodeNumber(BencodeStream stream)
232
232
if(stream.Length<3)
233
233
thrownewBencodeDecodingException<BNumber>("Minimum valid length of stream is 3 ('i0e').",stream.Position);
234
234
235
+
varstartPosition=stream.Position;
236
+
235
237
// Numbers must start with 'i'
236
238
if(stream.ReadChar()!='i')
237
239
thrownewBencodeDecodingException<BNumber>(string.Format("Must begin with 'i' but began with '{0}'.",stream.ReadPreviousChar()),stream.Position);
238
240
239
-
varisNegative=false;
240
241
vardigits=newStringBuilder();
241
242
while(stream.Peek()!='e'&&stream.Peek()!=-1)
242
243
{
243
-
// We do not support numbers that cannot be stored as a long (Int64)
244
-
if(digits.Length>=BNumber.MaxDigits)
245
-
{
246
-
thrownewUnsupportedBencodeException(
247
-
string.Format(
248
-
"The number '{0}' has more than 19 digits and cannot be stored as a long (Int64) and therefore is not supported.",
249
-
digits),
250
-
stream.Position);
251
-
}
252
-
253
-
varc=stream.ReadChar();
254
-
255
-
// There may be only one '-'
256
-
if(c=='-'&&!isNegative)
257
-
{
258
-
// '-' must be the first char after the beginning 'i'
259
-
if(digits.Length>0)
260
-
thrownewBencodeDecodingException<BNumber>("A '-' must be directly after 'i' and before any digits.",stream.Position);
261
-
262
-
isNegative=true;
263
-
continue;
264
-
}
244
+
digits.Append(stream.ReadChar());
245
+
}
265
246
266
-
// If it is not a digit at this point it is invalid
267
-
if(!c.IsDigit())
268
-
thrownewBencodeDecodingException<BNumber>(string.Format("Must only contain digits and a single prefixed '-'. Invalid character '{0}'",c),stream.Position);
0 commit comments