Fix off-by-one max payload checks

This commit is contained in:
Justin Starry 2020-09-15 15:25:00 +08:00 committed by Michael Vines
parent c231bb7154
commit f6cda2579f
4 changed files with 4 additions and 4 deletions

View File

@ -27,7 +27,7 @@ fn producer(addr: &SocketAddr, exit: Arc<AtomicBool>) -> JoinHandle<()> {
let mut num = 0;
for p in &msgs.packets {
let a = p.meta.addr();
assert!(p.meta.size < PACKET_DATA_SIZE);
assert!(p.meta.size <= PACKET_DATA_SIZE);
send.send_to(&p.data[..p.meta.size], &a).unwrap();
num += 1;
}

View File

@ -2466,7 +2466,7 @@ fn deserialize_bs58_transaction(bs58_transaction: String) -> Result<(Vec<u8>, Tr
let wire_transaction = bs58::decode(bs58_transaction)
.into_vec()
.map_err(|e| Error::invalid_params(format!("{:?}", e)))?;
if wire_transaction.len() >= PACKET_DATA_SIZE {
if wire_transaction.len() > PACKET_DATA_SIZE {
let err = format!(
"transaction too large: {} bytes (max: {} bytes)",
wire_transaction.len(),

View File

@ -219,7 +219,7 @@ pub fn request_airdrop_transaction(
Error::new(ErrorKind::Other, "Airdrop failed")
})?;
let transaction_length = LittleEndian::read_u16(&buffer) as usize;
if transaction_length >= PACKET_DATA_SIZE || transaction_length == 0 {
if transaction_length > PACKET_DATA_SIZE || transaction_length == 0 {
return Err(Error::new(
ErrorKind::Other,
format!(

View File

@ -598,7 +598,7 @@ mod tests {
tx0.message.instructions[0].data = vec![1, 2, 3];
let message0a = tx0.message_data();
let tx_bytes = serialize(&tx0).unwrap();
assert!(tx_bytes.len() < PACKET_DATA_SIZE);
assert!(tx_bytes.len() <= PACKET_DATA_SIZE);
assert_eq!(
memfind(&tx_bytes, &tx0.signatures[0].as_ref()),
Some(SIG_OFFSET)