Skip to content

Commit

Permalink
Merge branch 'master-2.x' into fix-sync-stuck-2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
shargon committed Jul 13, 2019
2 parents f9cef24 + 425eaa7 commit ee95314
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
18 changes: 14 additions & 4 deletions neo/Cryptography/ECC/ECPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,23 @@ public static ECPoint DeserializeFrom(BinaryReader reader, ECCurve curve)
return curve.Infinity;
case 0x02:
case 0x03:
reader.Read(buffer, 1, expectedLength);
return DecodePoint(buffer.Take(1 + expectedLength).ToArray(), curve);
{
if (reader.Read(buffer, 1, expectedLength) != expectedLength)
{
throw new FormatException();
}
return DecodePoint(buffer.Take(1 + expectedLength).ToArray(), curve);
}
case 0x04:
case 0x06:
case 0x07:
reader.Read(buffer, 1, expectedLength * 2);
return DecodePoint(buffer, curve);
{
if (reader.Read(buffer, 1, expectedLength * 2) != expectedLength * 2)
{
throw new FormatException();
}
return DecodePoint(buffer, curve);
}
default:
throw new FormatException("Invalid point encoding " + buffer[0]);
}
Expand Down
12 changes: 7 additions & 5 deletions neo/UIntBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

namespace Neo
{

/// <summary>
/// Base class for little-endian unsigned integers. Two classes inherit from this: UInt160 and UInt256.
/// Only basic comparison/serialization are proposed for these classes. For arithmetic purposes, use BigInteger class.
Expand All @@ -15,7 +14,7 @@ public abstract class UIntBase : IEquatable<UIntBase>, ISerializable
/// <summary>
/// Storing unsigned int in a little-endian byte array.
/// </summary>
private byte[] data_bytes;
private readonly byte[] data_bytes;

/// <summary>
/// Number of bytes of the unsigned int.
Expand Down Expand Up @@ -44,7 +43,10 @@ protected UIntBase(int bytes, byte[] value)
/// </summary>
void ISerializable.Deserialize(BinaryReader reader)
{
reader.Read(data_bytes, 0, data_bytes.Length);
if (reader.Read(data_bytes, 0, data_bytes.Length) != data_bytes.Length)
{
throw new FormatException();
}
}

/// <summary>
Expand All @@ -53,7 +55,7 @@ void ISerializable.Deserialize(BinaryReader reader)
/// </summary>
public bool Equals(UIntBase other)
{
if (ReferenceEquals(other, null))
if (other is null)
return false;
if (ReferenceEquals(this, other))
return true;
Expand All @@ -68,7 +70,7 @@ public bool Equals(UIntBase other)
/// </summary>
public override bool Equals(object obj)
{
if (ReferenceEquals(obj, null))
if (obj is null)
return false;
if (!(obj is UIntBase))
return false;
Expand Down

0 comments on commit ee95314

Please sign in to comment.