Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Securize ConsensusContext Deserialization #618

Merged
merged 5 commits into from
Mar 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions neo/Consensus/ConsensusContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void Deserialize(BinaryReader reader)
TransactionHashes = reader.ReadSerializableArray<UInt256>();
if (TransactionHashes.Length == 0)
TransactionHashes = null;
Transaction[] transactions = new Transaction[reader.ReadVarInt()];
Transaction[] transactions = new Transaction[reader.ReadVarInt(Block.MaxTransactionsPerBlock)];
if (transactions.Length == 0)
{
Transactions = null;
Expand All @@ -90,16 +90,16 @@ public void Deserialize(BinaryReader reader)
transactions[i] = Transaction.DeserializeFrom(reader);
Transactions = transactions.ToDictionary(p => p.Hash);
}
PreparationPayloads = new ConsensusPayload[reader.ReadVarInt()];
PreparationPayloads = new ConsensusPayload[reader.ReadVarInt(Blockchain.MaxValidators)];
for (int i = 0; i < PreparationPayloads.Length; i++)
PreparationPayloads[i] = reader.ReadBoolean() ? reader.ReadSerializable<ConsensusPayload>() : null;
CommitPayloads = new ConsensusPayload[reader.ReadVarInt()];
CommitPayloads = new ConsensusPayload[reader.ReadVarInt(Blockchain.MaxValidators)];
for (int i = 0; i < CommitPayloads.Length; i++)
CommitPayloads[i] = reader.ReadBoolean() ? reader.ReadSerializable<ConsensusPayload>() : null;
ChangeViewPayloads = new ConsensusPayload[reader.ReadVarInt()];
ChangeViewPayloads = new ConsensusPayload[reader.ReadVarInt(Blockchain.MaxValidators)];
for (int i = 0; i < ChangeViewPayloads.Length; i++)
ChangeViewPayloads[i] = reader.ReadBoolean() ? reader.ReadSerializable<ConsensusPayload>() : null;
LastChangeViewPayloads = new ConsensusPayload[reader.ReadVarInt()];
LastChangeViewPayloads = new ConsensusPayload[reader.ReadVarInt(Blockchain.MaxValidators)];
for (int i = 0; i < LastChangeViewPayloads.Length; i++)
LastChangeViewPayloads[i] = reader.ReadBoolean() ? reader.ReadSerializable<ConsensusPayload>() : null;
}
Expand Down
4 changes: 3 additions & 1 deletion neo/Consensus/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ public static void Save(this IConsensusContext context, Store store)
public static bool Load(this IConsensusContext context, Store store)
{
byte[] data = store.Get(CN_Context, new byte[0]);
if (data is null) return false;

if (data is null || data.Length == 0) return false;

using (MemoryStream ms = new MemoryStream(data, false))
using (BinaryReader reader = new BinaryReader(ms))
{
Expand Down