summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-10-26 22:16:34 +0100
committertv <tv@krebsco.de>2026-10-26 22:16:34 +0100
commit282eda719a303b4f5ae8ae05f0c11cac7b4a52ea (patch)
treed0dc38b16feb36e080b5dd224c5f11d684d76fec /src
parent5a32e746cf7aec3e4ca76616b6b66f023de53988 (diff)
reject and warn about too large delta blobs
Diffstat (limited to 'src')
-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 = {