summaryrefslogtreecommitdiffstats
path: root/src/swarm
diff options
context:
space:
mode:
Diffstat (limited to 'src/swarm')
-rw-r--r--src/swarm/blob.rs4
-rw-r--r--src/swarm/sync.rs5
2 files changed, 9 insertions, 0 deletions
diff --git a/src/swarm/blob.rs b/src/swarm/blob.rs
index 679e1c6..c13bcd9 100644
--- a/src/swarm/blob.rs
+++ b/src/swarm/blob.rs
@@ -88,6 +88,10 @@ pub(crate) struct Blobs {
/// within Mycelium's deadline.
const DELTA_THRESHOLD_CHUNKS: usize = 16;
+/// The largest sync message accepted: the threshold of a sender with the largest chunks
+/// it may have configured. Anything larger comes from a node that doesn't keep to it.
+pub(crate) const MAX_SYNC_MESSAGE: usize = DELTA_THRESHOLD_CHUNKS * MAX_CHUNK as usize;
+
struct Prepared {
bytes: Arc<Vec<u8>>,
hashes: Vec<[u8; 32]>,
diff --git a/src/swarm/sync.rs b/src/swarm/sync.rs
index 70ce28e..4e382ec 100644
--- a/src/swarm/sync.rs
+++ b/src/swarm/sync.rs
@@ -346,6 +346,11 @@ pub(crate) async fn handle_sync(
return Ok(());
}
};
+ if payload.0.len() > crate::swarm::blob::MAX_SYNC_MESSAGE {
+ // Not decoded: a node of this version sends a delta instead.
+ warn!(peer = %peer, bytes = payload.0.len(), "Dropping a sync message larger than any sender should send");
+ return Ok(());
+ }
state.stats.sync_received(payload.0.len());
let applied = {