Fix tests for packet (caught issue with input.len())

pull/200/head
Chip Senkbeil 12 months ago
parent bd9c06178e
commit 060f50d06c
No known key found for this signature in database
GPG Key ID: 35EF1F8EC72A4131

@ -38,6 +38,7 @@ use std::io::Cursor;
/// * If fails, returns existing bytes.
fn read_header_bytes(input: &[u8]) -> Result<(&[u8], &[u8]), &[u8]> {
let mut cursor = Cursor::new(input);
let input_len = input.len();
// Determine size of header map in terms of total objects
let len = match rmp::decode::read_map_len(&mut cursor) {
@ -58,7 +59,7 @@ fn read_header_bytes(input: &[u8]) -> Result<(&[u8], &[u8]), &[u8]> {
cursor.set_position(cursor.position() + key_len);
// If we would have advanced past our input, fail
if cursor.position() as usize > input.len() {
if cursor.position() as usize > input_len {
return Err(input);
}
@ -72,7 +73,7 @@ fn read_header_bytes(input: &[u8]) -> Result<(&[u8], &[u8]), &[u8]> {
}
// If we would have advanced past our input, fail
if cursor.position() as usize > input.len() {
if cursor.position() as usize > input_len {
return Err(input);
}
}
@ -81,7 +82,7 @@ fn read_header_bytes(input: &[u8]) -> Result<(&[u8], &[u8]), &[u8]> {
// Check if we've read beyond the input (being equal to len is okay
// because we could consume all of the remaining input this way)
if pos > input.len() {
if pos > input_len {
return Err(input);
}

Loading…
Cancel
Save