Skip to content

Commit

Permalink
Prevent DoS with wrong files (neo-project#81)
Browse files Browse the repository at this point in the history
* Prevent DoS with wrong files

* Constant

* Throw exception

* Clean
  • Loading branch information
shargon authored and 陈志同 committed Oct 13, 2020
1 parent d308633 commit a442774
Showing 1 changed file with 6 additions and 1 deletion.
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

0 comments on commit a442774

Please sign in to comment.