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

Prevent DoS with wrong files #81

Merged
merged 10 commits into from
Jul 14, 2019
7 changes: 6 additions & 1 deletion ImportBlocks/BlockImporter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Akka.Actor;
using Neo.IO;
using Neo.Ledger;
using Neo.Network.P2P;
using Neo.Network.P2P.Payloads;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -38,7 +39,11 @@ private static IEnumerable<Block> GetBlocks(Stream stream, bool read_start = fal
if (end <= Blockchain.Singleton.Height) yield break;
for (uint height = start; height <= end; height++)
{
byte[] array = r.ReadBytes(r.ReadInt32());
var size = r.ReadInt32();
if (size > Message.PayloadMaxSize)
throw new ArgumentException($"Block {height} exceeds the maximum allowed size");

byte[] array = r.ReadBytes(size);
if (!CheckMaxOnImportHeight(height)) yield break;
if (height > Blockchain.Singleton.Height)
{
Expand Down