11using System ;
22using System . Collections . Generic ;
3+ using System . Globalization ;
34using System . IO ;
45using System . Text ;
56using BencodeNET . Exceptions ;
@@ -12,6 +13,8 @@ public static class Bencode
1213 {
1314 private static Encoding _defaultEncoding = Encoding . UTF8 ;
1415
16+ private static readonly NumberFormatInfo _invariantNumberFormat = CultureInfo . InvariantCulture . NumberFormat ;
17+
1518 /// <summary>
1619 /// Gets or sets the default encoding used to convert strings to and from bytes
1720 /// when encoding/decoding bencode and no encoding is explicitly specified.
@@ -181,7 +184,7 @@ public static BString DecodeString(BencodeStream stream, Encoding encoding)
181184 }
182185
183186 long stringLength ;
184- if ( ! long . TryParse ( lengthString . ToString ( ) , out stringLength ) )
187+ if ( ! long . TryParse ( lengthString . ToString ( ) , NumberStyles . None , _invariantNumberFormat , out stringLength ) )
185188 {
186189 throw new BencodeDecodingException < BString > ( string . Format ( "Invalid length of string '{0}'" , lengthString ) , startPosition ) ;
187190 }
@@ -275,7 +278,7 @@ public static BNumber DecodeNumber(BencodeStream stream)
275278 throw new BencodeDecodingException < BNumber > ( "Missing end character 'e'." , stream . Position ) ;
276279
277280 long number ;
278- if ( ! long . TryParse ( digits . ToString ( ) , out number ) )
281+ if ( ! long . TryParse ( digits . ToString ( ) , NumberStyles . AllowLeadingSign , _invariantNumberFormat , out number ) )
279282 {
280283 throw new BencodeDecodingException < BNumber > (
281284 string . Format ( "The value '{0}' is invalid. Supported values range from {1:N0} to {2:N0}" ,
0 commit comments