feat: limit length of chunks when signer reads from stackerdb

This commit is contained in:
Hank Stoever
2024-04-08 10:36:33 -07:00
parent dcc89d2679
commit d700c85eec
2 changed files with 13 additions and 1 deletions

View File

@@ -17,6 +17,7 @@
use std::net::{SocketAddr, TcpStream};
use std::str;
use blockstack_lib::net::stackerdb::SIGNERS_STACKERDB_CHUNK_SIZE;
use clarity::vm::types::QualifiedContractIdentifier;
use libstackerdb::{
stackerdb_get_chunk_path, stackerdb_get_metadata_path, stackerdb_post_chunk_path, SlotMetadata,
@@ -217,7 +218,16 @@ impl SignerSession for StackerDBSession {
for slot_id in slot_ids.iter() {
let path = stackerdb_get_chunk_path(self.stackerdb_contract_id.clone(), *slot_id, None);
let chunk = match self.rpc_request("GET", &path, None, &[]) {
Ok(body_bytes) => Some(body_bytes),
Ok(body_bytes) => {
// Verify that the chunk is not too large
if body_bytes.len() > u32::MAX as usize {
None
} else if body_bytes.len() as u32 > SIGNERS_STACKERDB_CHUNK_SIZE {
None
} else {
Some(body_bytes)
}
}
Err(RPCError::HttpError(code)) => {
if code != 404 {
return Err(RPCError::HttpError(code));

View File

@@ -148,6 +148,8 @@ pub const STACKERDB_INV_MAX: u32 = 4096;
pub const STACKERDB_PAGE_LIST_MAX: u32 = 4096;
/// maximum number of pages that can be used in a StackerDB contract
pub const STACKERDB_MAX_PAGE_COUNT: u32 = 2;
/// CHUNK_SIZE constant for signers StackerDBs
pub const SIGNERS_STACKERDB_CHUNK_SIZE: u32 = 2 * 1024 * 1024; // 2MB
pub const STACKERDB_SLOTS_FUNCTION: &str = "stackerdb-get-signer-slots";
pub const STACKERDB_CONFIG_FUNCTION: &str = "stackerdb-get-config";