Skip to content

Commit

Permalink
limit max limit of batch request via json array
Browse files Browse the repository at this point in the history
  • Loading branch information
RCasatta committed Nov 1, 2024
1 parent b8f4524 commit 0bd3299
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/electrum/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use crate::util::{create_socket, spawn_thread, BlockId, BoolThen, Channel, FullH
const ELECTRS_VERSION: &str = env!("CARGO_PKG_VERSION");
const PROTOCOL_VERSION: ProtocolVersion = ProtocolVersion::new(1, 4);
const MAX_HEADERS: usize = 2016;
const MAX_ARRAY_BATCH: usize = 20;

#[cfg(feature = "electrum-discovery")]
use crate::electrum::{DiscoveryManager, ServerFeatures};
Expand Down Expand Up @@ -546,6 +547,13 @@ impl Connection {
Message::Request(line) => {
let cmd: Value = from_str(&line).chain_err(|| "invalid JSON format")?;
if let Value::Array(arr) = cmd {
if arr.len() > MAX_ARRAY_BATCH {
bail!(
"Too many elements in batch requests {} max:{}",
arr.len(),
MAX_ARRAY_BATCH
);
}
let mut result = Vec::with_capacity(arr.len());
for el in arr {
let reply = self.handle_value(el, &empty_params)?;
Expand Down

0 comments on commit 0bd3299

Please sign in to comment.